1
0
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:
Robert Krimen 2013-04-20 20:03:34 -07:00
parent 3f54041eb6
commit 2642607a58
2 changed files with 24 additions and 4 deletions

15
error_test.go Normal file
View 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")
}

View File

@ -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