mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Fix HasInstance to recurse the prototype hierarchy
This commit is contained in:
parent
3f54041eb6
commit
2642607a58
15
error_test.go
Normal file
15
error_test.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package otto
|
||||
|
||||
import (
|
||||
. "./terst"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestError_instanceof(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`
|
||||
(new TypeError()) instanceof Error
|
||||
`, "true")
|
||||
}
|
|
@ -86,11 +86,16 @@ func (self *_object) HasInstance(of Value) bool {
|
|||
if !prototype.IsObject() {
|
||||
panic(newTypeError())
|
||||
}
|
||||
ofPrototype := of._object().prototype
|
||||
if ofPrototype == nil {
|
||||
return false
|
||||
prototypeObject := prototype._object()
|
||||
|
||||
value := of._object().prototype
|
||||
for value != nil {
|
||||
if value == prototypeObject {
|
||||
return true
|
||||
}
|
||||
value = value.prototype
|
||||
}
|
||||
return ofPrototype == prototype._object()
|
||||
return false
|
||||
}
|
||||
|
||||
type _functionSignature string
|
||||
|
|
Loading…
Reference in New Issue
Block a user