diff --git a/array_test.go b/array_test.go index b228387..4da3ba1 100644 --- a/array_test.go +++ b/array_test.go @@ -40,6 +40,16 @@ func TestArray(t *testing.T) { abc.length = 2; abc; `, "0,1") + + test(` + Object.defineProperty(Array.prototype, "0", { + value: 100, + writable: false, + configurable: true + }); + abc = [101]; + abc.hasOwnProperty("0") && abc[0] === 101; + `, "true") } func TestArray_toString(t *testing.T) { diff --git a/global.go b/global.go index a8c0c07..3aee317 100644 --- a/global.go +++ b/global.go @@ -781,7 +781,7 @@ func (runtime *_runtime) newArray(length uint32) *_object { func (runtime *_runtime) newArrayOf(valueArray []Value) *_object { self := runtime.newArray(uint32(len(valueArray))) for index, value := range valueArray { - self.put(strconv.FormatInt(int64(index), 10), value, false) + self.defineProperty(strconv.FormatInt(int64(index), 10), value, 0111, false) } return self } diff --git a/object_class.go b/object_class.go index 02d4675..bb11e0b 100644 --- a/object_class.go +++ b/object_class.go @@ -217,6 +217,7 @@ func objectPut(self *_object, name string, value Value, throw bool) { typeErrorResult(throw) return } + // TODO This is not exacting to the specification // TODO Shortcut? property := self.getOwnProperty(name) if property == nil {