mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Partially implement new Object(...)
This commit is contained in:
parent
78ab288e0a
commit
f9879057a6
|
@ -16,7 +16,16 @@ func builtinObject(call FunctionCall) Value {
|
|||
return toValue(call.runtime.toObject(value))
|
||||
}
|
||||
|
||||
func builtinNewObject(self *_object, _ Value, _ []Value) Value {
|
||||
func builtinNewObject(self *_object, _ Value, argumentList []Value) Value {
|
||||
value := valueOfArrayIndex(argumentList, 0)
|
||||
switch value._valueType {
|
||||
case valueNull, valueUndefined:
|
||||
case valueNumber, valueString, valueBoolean:
|
||||
return toValue(self.runtime.toObject(value))
|
||||
case valueObject:
|
||||
return value
|
||||
default:
|
||||
}
|
||||
return toValue(self.runtime.newObject())
|
||||
}
|
||||
|
||||
|
|
|
@ -35,3 +35,12 @@ func TestObject_getPrototypeOf(t *testing.T) {
|
|||
[abc,def,ghi,ghi+""];
|
||||
`, "[object Object],[object Object],,null")
|
||||
}
|
||||
|
||||
func TestObject_new(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`
|
||||
[ new Object("abc"), new Object(2+2) ];
|
||||
`, "abc,4")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user