1
0
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:
Robert Krimen 2013-05-02 20:23:07 +02:00
parent 78ab288e0a
commit f9879057a6
2 changed files with 19 additions and 1 deletions

View File

@ -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())
}

View File

@ -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")
}