Rework Object's [[OwnPropertyKeys]] (#4001)
I've removed the ecma_op_object_get_property_names method, and implemented the following ones: - ecma_op_object_own_property_keys: this is now the internal [[OwnPropertyKeys]] method - ecma_op_object_enumerate: this is used for the for-in iterator - ecma_object_sort_property_names: this is used for sorting the property names of an object - ecma_object_list_lazy_property_names: this is for getting the lazy instantiated properties - ecma_object_prop_name_is_duplicated: this is for checking if a given property is duplicated in an object Also the for-in operation with Proxy object works with this patch, #3992 should be closed JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var proxy = new Proxy({length: 5}, {
|
||||
getOwnPropertyDescriptor() { throw 42.5; }
|
||||
})
|
||||
|
||||
try {
|
||||
Array.prototype.sort.call(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42.5);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ assert(getProperties(func) == "dummy");
|
||||
|
||||
var bound_func = (function() {}).bind(null);
|
||||
Object.setPrototypeOf(bound_func, prototype_obj);
|
||||
assert(getProperties(bound_func) == "dummy prototype");
|
||||
assert(getProperties(bound_func) == "dummy caller arguments prototype");
|
||||
|
||||
// 'print' is an external function
|
||||
Object.setPrototypeOf(print, prototype_obj);
|
||||
|
||||
@@ -124,7 +124,6 @@ assert (object[symbol] === "a symbol");
|
||||
assert (object.bar === 42);
|
||||
assert (object[symbol] === undefined);
|
||||
|
||||
// This code should throw TypeError
|
||||
var object = {};
|
||||
var props = {
|
||||
[symbol]: {
|
||||
@@ -142,9 +141,9 @@ var props = {
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
Object.defineProperties(object, props);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
Object.defineProperties(object, props);
|
||||
var bar_desc = Object.getOwnPropertyDescriptor(object, 'bar');
|
||||
assert(bar_desc.value === 2);
|
||||
assert(bar_desc.writable === true);
|
||||
assert(object.prop1 === undefined);
|
||||
assert(object[symbol] === undefined);
|
||||
|
||||
@@ -31,14 +31,6 @@ var handler = { ownKeys (target) {
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
// Array.prototype.sort
|
||||
Array.prototype.sort.call(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
try {
|
||||
// 19.1.2.14.4
|
||||
Object.keys(proxy);
|
||||
@@ -63,6 +55,14 @@ try {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
var handler = { ownKeys (target) {
|
||||
return ["a"];
|
||||
}};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
var sort_result = Array.prototype.sort.call(proxy);
|
||||
assert(Object.keys(sort_result).length === 0);
|
||||
|
||||
// test basic functionality
|
||||
var symA = Symbol("smA");
|
||||
var symB = Symbol("smB");
|
||||
@@ -149,16 +149,18 @@ try {
|
||||
}
|
||||
|
||||
// test with duplicated keys
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {
|
||||
var p = new Proxy({}, {
|
||||
ownKeys: function(target) {
|
||||
return ["a", "a", "a"];
|
||||
}
|
||||
};
|
||||
return ["foo", "foo"];
|
||||
}
|
||||
});
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["a","a","a"]');
|
||||
try {
|
||||
Object.keys(p);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
// test with lots of keys
|
||||
var keyslist = [];
|
||||
@@ -240,4 +242,4 @@ var handler = {
|
||||
var proxy = new Proxy(object, handler);
|
||||
|
||||
assert(Object.keys(proxy).length === 1);
|
||||
assert(Object.keys(proxy)[0] === "b");
|
||||
assert(Object.keys(proxy)[0] === "b");
|
||||
@@ -12,11 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
var a = new Proxy({}, {});
|
||||
var a = new Proxy({ a : 4, b :4}, {});
|
||||
var reached = false;
|
||||
|
||||
try {
|
||||
for (var $ in a);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
for (var $ in a)
|
||||
{
|
||||
reached = true;
|
||||
}
|
||||
|
||||
assert (reached === true);
|
||||
|
||||
@@ -174,7 +174,6 @@ assert (obj.a === "b");
|
||||
assert (obj.bar === 42);
|
||||
assert (obj.a === undefined);
|
||||
|
||||
// This code should throw TypeError
|
||||
var obj = {};
|
||||
var props = {
|
||||
prop1: {
|
||||
@@ -196,9 +195,15 @@ var props = {
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
Object.defineProperties(obj, props);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
Object.defineProperties(obj, props);
|
||||
var bar_desc = Object.getOwnPropertyDescriptor(obj, 'bar');
|
||||
assert(bar_desc.value === 2);
|
||||
assert(bar_desc.writable === true);
|
||||
assert(obj.prop2 === undefined);
|
||||
|
||||
var prop1_desc = Object.getOwnPropertyDescriptor(obj, 'prop1');
|
||||
var prop3_desc = Object.getOwnPropertyDescriptor(obj, 'prop3');
|
||||
assert(prop1_desc.value === 1);
|
||||
assert(prop1_desc.writable === true);
|
||||
assert(prop3_desc.value === 4);
|
||||
assert(prop3_desc.writable === true);
|
||||
|
||||
@@ -64,10 +64,15 @@
|
||||
<test id="built-ins/Promise/race/species-get-error.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/call-parameters.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/return-is-abrupt.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-boolean.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-number.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-string.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-symbol.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/result-not-an-object-throws-undefined.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/null-handler.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/return-trap-result.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/return-trap-result-no-value.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/trap-is-undefined.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/getOwnPropertyDescriptor/trap-is-undefined.js"><reason></reason></test>
|
||||
<test id="built-ins/Proxy/enumerate/trap-is-not-callable.js"><reason>For-in supports proxy</reason></test>
|
||||
<test id="built-ins/Reflect/enumerate/does-not-iterate-over-symbol-properties.js"><reason></reason></test>
|
||||
<test id="built-ins/Reflect/enumerate/enumerate.js"><reason></reason></test>
|
||||
<test id="built-ins/Reflect/enumerate/length.js"><reason></reason></test>
|
||||
|
||||
Reference in New Issue
Block a user