Re-target for ES.Next (#3901)
A list of changes: - 'es2015-subset' profile is deprecated, and an 'es.next' profile is added. - The default profile is changed to 'es.next' - Renamed the JERRY_ES2015 guard to JERRY_ESNEXT - Renamed JERRY_ES2015_BUILTIN_* guards to JERRY_BUILTIN_* - Moved es2015 specific tests to a new 'es.next' subdirectory - Updated docs, targets, and test runners to reflect these changes Resolves #3737. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
// 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.
|
||||
|
||||
// Copyright 2015 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
function array_check(result_array, expected_array) {
|
||||
assert(result_array instanceof Array);
|
||||
assert(result_array.length === expected_array.length);
|
||||
for (var idx = 0; idx < expected_array.length; idx++) {
|
||||
assert(result_array[idx] === expected_array[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
var target = {};
|
||||
var handler = { ownKeys (target) {
|
||||
throw 42;
|
||||
}};
|
||||
|
||||
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);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
try {
|
||||
// 19.1.2.7.1
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
try {
|
||||
// 19.1.2.8.1
|
||||
Object.getOwnPropertySymbols(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e === 42);
|
||||
}
|
||||
|
||||
// test basic functionality
|
||||
var symA = Symbol("smA");
|
||||
var symB = Symbol("smB");
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
target[symB] = "s3";
|
||||
var handler = {
|
||||
ownKeys: function(target) {
|
||||
return ["foo", "bar", symA];
|
||||
}
|
||||
}
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
array_check(Reflect.ownKeys(proxy), ["foo", "bar", symA]);
|
||||
array_check(Object.getOwnPropertyNames(proxy), ["foo", "bar"]);
|
||||
array_check(Object.keys(proxy), ["foo", "bar"]);
|
||||
array_check(Object.getOwnPropertySymbols(proxy), [symA]);
|
||||
|
||||
handler.ownKeys = function(target) {return Object.getOwnPropertyNames(target);};
|
||||
|
||||
array_check(Reflect.ownKeys(proxy), ["prop1", "prop2"]);
|
||||
array_check(Object.getOwnPropertyNames(proxy), ["prop1", "prop2"]);
|
||||
array_check(Object.keys(proxy), ["prop1", "prop2"]);
|
||||
array_check(Object.getOwnPropertySymbols(proxy), []);
|
||||
|
||||
// test with no trap
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {};
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["prop1","prop2"]');
|
||||
|
||||
// test wtih "undefined" trap
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {ownKeys: null};
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["prop1","prop2"]');
|
||||
|
||||
// test with invalid trap
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {ownKeys: 42};
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
// test when CreateListFromArrayLike called on non-object
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {
|
||||
ownKeys: function(target) {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
// test with invalid property key
|
||||
var target = {};
|
||||
var handler = {
|
||||
ownKeys: function(target) {
|
||||
return [5];
|
||||
}
|
||||
};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
// test with duplicated keys
|
||||
var target = { prop1: "prop1", prop2: "prop2"};
|
||||
var handler = {
|
||||
ownKeys: function(target) {
|
||||
return ["a", "a", "a"];
|
||||
}
|
||||
};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["a","a","a"]');
|
||||
|
||||
// test with lots of keys
|
||||
var keyslist = [];
|
||||
|
||||
var handler = {
|
||||
ownKeys: function(target) {
|
||||
for (var idx = 0; idx < 30; idx++) {
|
||||
keyslist.push("K" + idx);
|
||||
}
|
||||
return keyslist;
|
||||
}
|
||||
};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === JSON.stringify(keyslist));
|
||||
|
||||
// test when invariants gets violated
|
||||
var target = {
|
||||
"target_one": 1
|
||||
};
|
||||
Object.defineProperty(target, "nonconf", {value: 1, configurable: false});
|
||||
|
||||
var keys = ["foo"];
|
||||
|
||||
var handler = {
|
||||
ownKeys: function(target) {
|
||||
return keys;
|
||||
}
|
||||
};
|
||||
|
||||
var proxy = new Proxy(target, handler);
|
||||
|
||||
try {
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
keys = ["nonconf"];
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["nonconf"]');
|
||||
|
||||
Object.preventExtensions(target);
|
||||
keys = ["foo", "nonconf"];
|
||||
|
||||
try {
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
keys = ["target_one", "nonconf"];
|
||||
|
||||
assert(JSON.stringify(Object.getOwnPropertyNames(proxy)) === '["target_one","nonconf"]');
|
||||
|
||||
keys = ["target_one", "nonconf", "foo"];
|
||||
|
||||
try {
|
||||
Object.getOwnPropertyNames(proxy);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
Reference in New Issue
Block a user