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)
|
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 {
|
func builtinObject_getOwnPropertyDescriptor(call FunctionCall) Value {
|
||||||
objectValue := call.Argument(0)
|
objectValue := call.Argument(0)
|
||||||
object := objectValue._object()
|
object := objectValue._object()
|
||||||
|
|
|
@ -168,6 +168,7 @@ func newContext() *_runtime {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.Global.Object.write(
|
self.Global.Object.write(
|
||||||
|
"getPrototypeOf", 1, builtinObject_getPrototypeOf,
|
||||||
"getOwnPropertyDescriptor", 2, builtinObject_getOwnPropertyDescriptor,
|
"getOwnPropertyDescriptor", 2, builtinObject_getOwnPropertyDescriptor,
|
||||||
"defineProperty", 3, builtinObject_defineProperty,
|
"defineProperty", 3, builtinObject_defineProperty,
|
||||||
"defineProperties", 2, builtinObject_defineProperties,
|
"defineProperties", 2, builtinObject_defineProperties,
|
||||||
|
|
|
@ -23,3 +23,15 @@ func TestStringObject(t *testing.T) {
|
||||||
Is(object.get("10"), "undefined")
|
Is(object.get("10"), "undefined")
|
||||||
Is(object.get("2"), "z")
|
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")
|
||||||
|
}
|
||||||
|
|
1
value.go
1
value.go
|
@ -250,6 +250,7 @@ func toValue_reflectValuePanic(value interface{}, kind reflect.Kind) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO toValue(nil)?
|
||||||
func toValue(value interface{}) Value {
|
func toValue(value interface{}) Value {
|
||||||
switch value := value.(type) {
|
switch value := value.(type) {
|
||||||
case Value:
|
case Value:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user