diff --git a/function_test.go b/function_test.go index 3ed1977..62313f9 100644 --- a/function_test.go +++ b/function_test.go @@ -93,6 +93,39 @@ func TestFunctionDeclarationInFunction(t *testing.T) { `, "function") } +func TestArguments_defineOwnProperty(t *testing.T) { + Terst(t) + + test := runTest() + + test(` + var abc; + var def = true; + var ghi = {}; + (function (a, b, c) { + Object.defineProperty(arguments, "0", { + value: 42, + writable: false, + enumerable: false, + configurable: false + }); + Object.defineProperty(arguments, "1", { + value: 3.14, + configurable: true, + enumerable: true + }); + abc = Object.getOwnPropertyDescriptor(arguments, "0"); + for (var name in arguments) { + ghi[name] = (ghi[name] || 0) + 1; + if (name === "0") { + def = false; + } + } + }(0, 1, 2)); + [ abc.value, abc.writable, abc.enumerable, abc.configurable, def, ghi["1"] ]; + `, "42,false,false,false,true,1") +} + func TestFunction_bind(t *testing.T) { Terst(t) diff --git a/object_class.go b/object_class.go index 26d1f77..060aa63 100644 --- a/object_class.go +++ b/object_class.go @@ -90,7 +90,8 @@ func init() { objectHasOwnProperty, argumentsDefineOwnProperty, argumentsDelete, - argumentsEnumerate, + //argumentsEnumerate, + objectEnumerate, //argumentsClone objectClone, } diff --git a/otto_test.go b/otto_test.go index 416b402..d3196bc 100644 --- a/otto_test.go +++ b/otto_test.go @@ -420,6 +420,18 @@ func TestObject_defineOwnProperty(t *testing.T) { [ abc, def ]; `, "true,false") + + test(` + var object = [0, 1, 2]; + Object.defineProperty(object, "0", { + value: 42, + writable: false, + enumerable: false, + configurable: false + }); + var abc = Object.getOwnPropertyDescriptor(object, "0"); + [ abc.value, abc.writable, abc.enumerable, abc.configurable ]; + `, "42,false,false,false") } func Test_assignmentEvaluationOrder(t *testing.T) { diff --git a/type_arguments.go b/type_arguments.go index ad3f320..e23912a 100644 --- a/type_arguments.go +++ b/type_arguments.go @@ -7,6 +7,11 @@ import ( func (runtime *_runtime) newArgumentsObject(indexOfParameterName []string, environment _environment, length int) *_object { self := runtime.newClassObject("Arguments") + for index, _ := range indexOfParameterName { + name := strconv.FormatInt(int64(index), 10) + objectDefineOwnProperty(self, name, _property{Value{}, 0111}, false) + } + self.objectClass = _classArguments self.value = _argumentsObject{ indexOfParameterName: indexOfParameterName, @@ -70,10 +75,11 @@ func argumentsGet(self *_object, name string) Value { } func argumentsGetOwnProperty(self *_object, name string) *_property { + property := objectGetOwnProperty(self, name) if value, exists := self.value.(_argumentsObject).get(name); exists { - return &_property{value, 0111} + property.value = value } - return objectGetOwnProperty(self, name) + return property } func argumentsDefineOwnProperty(self *_object, name string, descriptor _property, throw bool) bool { @@ -90,23 +96,11 @@ func argumentsDefineOwnProperty(self *_object, name string, descriptor _property } func argumentsDelete(self *_object, name string, throw bool) bool { + if !objectDelete(self, name, throw) { + return false + } if _, exists := self.value.(_argumentsObject).get(name); exists { self.value.(_argumentsObject).delete(name) - return true - } - return objectDelete(self, name, throw) -} - -func argumentsEnumerate(self *_object, all bool, each func(string) bool) { - { - object := self.value.(_argumentsObject) - for index, value := range object.indexOfParameterName { - if value != "" { - if !each(strconv.FormatInt(int64(index), 10)) { - return - } - } - } - objectEnumerate(self, all, each) } + return true }