mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Add Object.getPrototypeOf
This commit is contained in:
parent
299495ba0a
commit
f3da7237f2
|
@ -32,6 +32,20 @@ func builtinObject_toString(call FunctionCall) Value {
|
|||
return toValue(result)
|
||||
}
|
||||
|
||||
func builtinObject_getPrototypeOf(call FunctionCall) Value {
|
||||
objectValue := call.Argument(0)
|
||||
object := objectValue._object()
|
||||
if object == nil {
|
||||
panic(newTypeError())
|
||||
}
|
||||
|
||||
if object.prototype == nil {
|
||||
return NullValue()
|
||||
}
|
||||
|
||||
return toValue(object.prototype)
|
||||
}
|
||||
|
||||
func builtinObject_getOwnPropertyDescriptor(call FunctionCall) Value {
|
||||
objectValue := call.Argument(0)
|
||||
object := objectValue._object()
|
||||
|
|
|
@ -168,6 +168,7 @@ func newContext() *_runtime {
|
|||
},
|
||||
)
|
||||
self.Global.Object.write(
|
||||
"getPrototypeOf", 1, builtinObject_getPrototypeOf,
|
||||
"getOwnPropertyDescriptor", 2, builtinObject_getOwnPropertyDescriptor,
|
||||
"defineProperty", 3, builtinObject_defineProperty,
|
||||
"defineProperties", 2, builtinObject_defineProperties,
|
||||
|
|
|
@ -23,3 +23,15 @@ func TestStringObject(t *testing.T) {
|
|||
Is(object.get("10"), "undefined")
|
||||
Is(object.get("2"), "z")
|
||||
}
|
||||
|
||||
func TestObject_getPrototypeOf(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`
|
||||
abc = {};
|
||||
def = Object.getPrototypeOf(abc);
|
||||
ghi = Object.getPrototypeOf(def);
|
||||
[abc,def,ghi,ghi+""];
|
||||
`, "[object Object],[object Object],,null")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user