mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
Move escargot internal tests to Samsung/js_vendor_tc repo (#395)
* Move es2015, regression-test, intl to js_vender_tc/Escargot directory * Modify each test path in run-test.py * Change a test command 'intnernal' to 'ModifiedVendorTest' * Now, if you need to add an escargot internal test, PR to js_vender_tc repo Signed-off-by: Boram Bae <boram21.bae@samsung.com>
This commit is contained in:
parent
8ac5611152
commit
393792cae7
126 changed files with 16 additions and 6413 deletions
10
.travis.yml
10
.travis.yml
|
|
@ -12,7 +12,7 @@ matrix:
|
|||
- cmake -H. -Bout/linux/x64/debug -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_OUTPUT=bin -GNinja
|
||||
- ninja -Cout/linux/x64/debug
|
||||
- cp ./out/linux/x64/debug/escargot ./escargot
|
||||
- tools/run-tests.py --arch=x86_64 sunspider-js internal regression-tests es2015 intl
|
||||
- tools/run-tests.py --arch=x86_64 sunspider-js modifiedVendorTest regression-tests es2015 intl
|
||||
- gcc -shared -fPIC -o backtrace-hooking.so tools/test/test262/backtrace-hooking.c
|
||||
- export GC_FREE_SPACE_DIVISOR=1
|
||||
- export ESCARGOT_LD_PRELOAD=${TRAVIS_BUILD_DIR}/backtrace-hooking.so
|
||||
|
|
@ -23,7 +23,7 @@ matrix:
|
|||
- cmake -H. -Bout/linux/x86/debug -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_OUTPUT=bin -GNinja
|
||||
- ninja -Cout/linux/x86/debug
|
||||
- cp ./out/linux/x86/debug/escargot ./escargot
|
||||
- tools/run-tests.py --arch=x86 sunspider-js internal regression-tests es2015 intl
|
||||
- tools/run-tests.py --arch=x86 sunspider-js modifiedVendorTest regression-tests es2015 intl
|
||||
- gcc -shared -m32 -fPIC -o backtrace-hooking.so tools/test/test262/backtrace-hooking.c
|
||||
- export GC_FREE_SPACE_DIVISOR=1
|
||||
- export ESCARGOT_LD_PRELOAD=${TRAVIS_BUILD_DIR}/backtrace-hooking.so
|
||||
|
|
@ -40,7 +40,7 @@ matrix:
|
|||
- ninja -Cout/linux/x64/release
|
||||
- cp ./out/linux/x64/release/escargot ./escargot
|
||||
- travis_wait 30 tools/run-tests.py --arch=x86_64 octane
|
||||
- tools/run-tests.py --arch=x86_64 jetstream-only-cdjs sunspider-js internal jsc-stress v8 spidermonkey regression-tests es2015 intl chakracore
|
||||
- tools/run-tests.py --arch=x86_64 jetstream-only-cdjs sunspider-js modifiedVendorTest jsc-stress v8 spidermonkey regression-tests es2015 intl chakracore
|
||||
- export GC_FREE_SPACE_DIVISOR=1
|
||||
- travis_wait 40 tools/run-tests.py --arch=x86_64 test262
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ matrix:
|
|||
- ninja -Cout/linux/x86/release
|
||||
- cp ./out/linux/x86/release/escargot ./escargot
|
||||
- travis_wait 30 tools/run-tests.py --arch=x86 octane
|
||||
- tools/run-tests.py --arch=x86 jetstream-only-cdjs sunspider-js internal jsc-stress v8 spidermonkey regression-tests es2015 intl chakracore
|
||||
- tools/run-tests.py --arch=x86 jetstream-only-cdjs sunspider-js modifiedVendorTest jsc-stress v8 spidermonkey regression-tests es2015 intl chakracore
|
||||
- export GC_FREE_SPACE_DIVISOR=1
|
||||
- travis_wait 40 tools/run-tests.py --arch=x86 test262
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ matrix:
|
|||
- cmake -H. -Bout/darwin/x64/release -DESCARGOT_HOST=darwin -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=bin -DVENDORTEST=1 -GNinja
|
||||
- ninja -Cout/darwin/x64/release
|
||||
- cp ./out/darwin/x64/release/escargot ./escargot
|
||||
- tools/run-tests.py --arch=x86_64 jetstream-only-cdjs sunspider-js internal jsc-stress regression-tests v8 es2015 intl
|
||||
- tools/run-tests.py --arch=x86_64 jetstream-only-cdjs sunspider-js modifiedVendorTest jsc-stress regression-tests v8 es2015 intl
|
||||
- tools/run-tests.py test262
|
||||
# FIXME: jetstream-only-simple and octane takes too long running time on darwin
|
||||
# jetstream-only-simple and octane are skipped now.
|
||||
|
|
|
|||
8
Jenkinsfile
vendored
8
Jenkinsfile
vendored
|
|
@ -115,15 +115,15 @@ timeout(60) {
|
|||
sh 'tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64_release/escargot" chakracore'
|
||||
},
|
||||
'32bit' : {
|
||||
sh 'tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux/escargot" internal regression-tests es2015 intl sunspider-js'
|
||||
sh 'tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux/escargot" modifiedVendorTest regression-tests es2015 intl sunspider-js'
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 ESCARGOT_LD_PRELOAD=${WORKSPACE}/backtrace-hooking-32.so tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux/escargot" test262'
|
||||
sh 'tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux_release/escargot" jetstream-only-cdjs internal jsc-stress sunspider-js'
|
||||
sh 'tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux_release/escargot" jetstream-only-cdjs modifiedVendorTest jsc-stress sunspider-js'
|
||||
sh 'tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux_release/escargot" v8 spidermonkey regression-tests es2015 intl test262'
|
||||
},
|
||||
'64bit' : {
|
||||
sh 'tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64/escargot" internal regression-tests es2015 intl sunspider-js'
|
||||
sh 'tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64/escargot" modifiedVendorTest regression-tests es2015 intl sunspider-js'
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 ESCARGOT_LD_PRELOAD=${WORKSPACE}/backtrace-hooking-64.so tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64/escargot" test262'
|
||||
sh 'tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64_release/escargot" jetstream-only-cdjs internal jsc-stress sunspider-js'
|
||||
sh 'tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64_release/escargot" jetstream-only-cdjs modifiedVendorTest jsc-stress sunspider-js'
|
||||
sh 'tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64_release/escargot" v8 spidermonkey regression-tests es2015 intl test262'
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
//-------------------------------------------------------------------------------------------------------
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
var scenarios = [
|
||||
["obj.foo", false], // obj is configurable false
|
||||
["'hello'[0]", false],
|
||||
["'hello'.length", false],
|
||||
["reg.source", true],
|
||||
["reg.global", true],
|
||||
["reg.lastIndex", false],
|
||||
];
|
||||
|
||||
(function Test1(x) {
|
||||
var str = "delete configurable false property";
|
||||
|
||||
var obj = new Object();
|
||||
Object.defineProperty(obj, "foo", { configurable: false, value: 20 });
|
||||
|
||||
var reg = /foo/;
|
||||
|
||||
for (var i = 0; i < scenarios.length; ++i) {
|
||||
var r = eval("delete " + scenarios[i][0]);
|
||||
assert(scenarios[i][1] === r);
|
||||
}
|
||||
})();
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
// Copyright (c) 2012 Ecma International. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-date-time-string-format
|
||||
description: >
|
||||
Date Time String Format - specified default values will be set for
|
||||
all optional fields(MM, DD, mm, ss and time zone) when they are
|
||||
absent
|
||||
---*/
|
||||
|
||||
var result = false;
|
||||
var expectedDateTimeStr = "1970-01-01T00:00:00.000Z";
|
||||
var dateObj = new Date("1970");
|
||||
var dateStr = dateObj.toISOString();
|
||||
result = dateStr === expectedDateTimeStr;
|
||||
|
||||
assert(result);
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Boolean.prototype.valueOf() returns this boolean value
|
||||
esid: sec-boolean.prototype.valueof
|
||||
description: calling with argument
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (typeof Boolean.prototype !== "object") {
|
||||
assertNotReached('#1: typeof Boolean.prototype === "object"');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if (Boolean.prototype != false) {
|
||||
assertNotReached('#2: Boolean.prototype == false');
|
||||
}
|
||||
|
||||
delete Boolean.prototype.toString;
|
||||
|
||||
if (Boolean.prototype.toString() !== "[object Boolean]") {
|
||||
assertNotReached('#3: The [[Class]] property of the Boolean prototype object is set to "Boolean"');
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Boolean.prototype.valueOf() returns this boolean value
|
||||
esid: sec-boolean.prototype.valueof
|
||||
description: calling with argument
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (Boolean.prototype.toString() !== "false") {
|
||||
assertNotReached('#1: Boolean.prototype.toString() === "false"');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if ((new Boolean()).toString() !== "false") {
|
||||
assertNotReached('#2: (new Boolean()).toString() === "false"');
|
||||
}
|
||||
|
||||
//CHECK#3
|
||||
if ((new Boolean(false)).toString() !== "false") {
|
||||
assertNotReached('#3: (new Boolean(false)).toString() === "false"');
|
||||
}
|
||||
|
||||
//CHECK#4
|
||||
if ((new Boolean(true)).toString() !== "true") {
|
||||
assertNotReached('#4: (new Boolean(true)).toString() === "true"');
|
||||
}
|
||||
|
||||
//CHECK#5
|
||||
if ((new Boolean(1)).toString() !== "true") {
|
||||
assertNotReached('#5: (new Boolean(1)).toString() === "true"');
|
||||
}
|
||||
|
||||
//CHECK#6
|
||||
if ((new Boolean(0)).toString() !== "false") {
|
||||
assertNotReached('#6: (new Boolean(0)).toString() === "false"');
|
||||
}
|
||||
|
||||
//CHECK#7
|
||||
if ((new Boolean(new Object())).toString() !== "true") {
|
||||
assertNotReached('#7: (new Boolean(new Object())).toString() === "true"');
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Boolean.prototype.valueOf() returns this boolean value
|
||||
esid: sec-boolean.prototype.valueof
|
||||
description: calling with argument
|
||||
---*/
|
||||
//CHECK#1
|
||||
if (Boolean.prototype.toString(true) !== "false") {
|
||||
assertNotReached('#1: Boolean.prototype.toString(true) === "false"');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if ((new Boolean()).toString(true) !== "false") {
|
||||
assertNotReached('#2: (new Boolean()).toString(true) === "false"');
|
||||
}
|
||||
|
||||
//CHECK#3
|
||||
if ((new Boolean(false)).toString(true) !== "false") {
|
||||
assertNotReached('#3: (new Boolean(false)).toString(true) === "false"');
|
||||
}
|
||||
|
||||
//CHECK#4
|
||||
if ((new Boolean(true)).toString(false) !== "true") {
|
||||
assertNotReached('#4: (new Boolean(true)).toString(false) === "true"');
|
||||
}
|
||||
|
||||
//CHECK#5
|
||||
if ((new Boolean(1)).toString(false) !== "true") {
|
||||
assertNotReached('#5: (new Boolean(1)).toString(false) === "true"');
|
||||
}
|
||||
|
||||
//CHECK#6
|
||||
if ((new Boolean(0)).toString(true) !== "false") {
|
||||
assertNotReached('#6: (new Boolean(0)).toString(true) === "false"');
|
||||
}
|
||||
|
||||
//CHECK#7
|
||||
if ((new Boolean(new Object())).toString(false) !== "true") {
|
||||
assertNotReached('#7: (new Boolean(new Object())).toString(false) === "true"');
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Boolean.prototype.valueOf() returns this boolean value
|
||||
esid: sec-boolean.prototype.valueof
|
||||
description: calling with argument
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (Boolean.prototype.valueOf() !== false) {
|
||||
assertNotReached('#1: Boolean.prototype.valueOf() === false');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if ((new Boolean()).valueOf() !== false) {
|
||||
assertNotReached('#2: (new Boolean()).valueOf() === false');
|
||||
}
|
||||
|
||||
//CHECK#3
|
||||
if ((new Boolean(0)).valueOf() !== false) {
|
||||
assertNotReached('#3: (new Boolean(0)).valueOf() === false');
|
||||
}
|
||||
|
||||
//CHECK#4
|
||||
if ((new Boolean(-1)).valueOf() !== true) {
|
||||
assertNotReached('#4: (new Boolean(-1)).valueOf() === true');
|
||||
}
|
||||
|
||||
//CHECK#5
|
||||
if ((new Boolean(1)).valueOf() !== true) {
|
||||
assertNotReached('#5: (new Boolean(1)).valueOf() === true');
|
||||
}
|
||||
|
||||
//CHECK#6
|
||||
if ((new Boolean(new Object())).valueOf() !== true) {
|
||||
assertNotReached('#6: (new Boolean(new Object())).valueOf() === true');
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: Boolean.prototype.valueOf() returns this boolean value
|
||||
esid: sec-boolean.prototype.valueof
|
||||
description: calling with argument
|
||||
---*/
|
||||
|
||||
//CHECK#1
|
||||
if (Boolean.prototype.valueOf(true) !== false) {
|
||||
assertNotReached('#1: Boolean.prototype.valueOf(true) === false');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if ((new Boolean()).valueOf(true) !== false) {
|
||||
assertNotReached('#2: (new Boolean()).valueOf(true) === false');
|
||||
}
|
||||
|
||||
//CHECK#3
|
||||
if ((new Boolean(0)).valueOf(true) !== false) {
|
||||
assertNotReached('#3: (new Boolean(0)).valueOf(true) === false');
|
||||
}
|
||||
|
||||
//CHECK#4
|
||||
if ((new Boolean(-1)).valueOf(false) !== true) {
|
||||
assertNotReached('#4: (new Boolean(-1)).valueOf(false) === true');
|
||||
}
|
||||
|
||||
//CHECK#5
|
||||
if ((new Boolean(1)).valueOf(false) !== true) {
|
||||
assertNotReached('#5: (new Boolean(1)).valueOf(false) === true');
|
||||
}
|
||||
|
||||
//CHECK#6
|
||||
if ((new Boolean(new Object())).valueOf(false) !== true) {
|
||||
assertNotReached('#6: (new Boolean(new Object())).valueOf(false) === true');
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 assert = print;
|
||||
|
||||
function assertEquals(actual, expected) {
|
||||
assert(JSON.stringify(actual) == JSON.stringify(expected))
|
||||
}
|
||||
|
||||
// Array.prototype.splice
|
||||
var arr = ["a"];
|
||||
var elem = arr.splice(0);
|
||||
assertEquals(arr, []);
|
||||
assert(elem == "a");
|
||||
|
||||
arr = ["a"];
|
||||
elem = arr.splice(0, 0);
|
||||
assertEquals(arr, ["a"]);
|
||||
assert(elem == "");
|
||||
|
||||
elem = arr.splice(0, 1);
|
||||
assertEquals(arr, []);
|
||||
assert(elem == "a");
|
||||
|
||||
arr = ["a"];
|
||||
elem = arr.splice(0, 0, "b");
|
||||
assertEquals(arr, ["b", "a"]);
|
||||
assert(elem == "");
|
||||
|
||||
arr = ["a"];
|
||||
elem = arr.splice(0, 2, "b", "c");
|
||||
assertEquals(arr, ["b", "c"]);
|
||||
assert(elem == "a");
|
||||
|
||||
elem = arr.splice(0, 2, "a");
|
||||
assertEquals(arr, ["a"]);
|
||||
assertEquals(elem, ["b", "c"]);
|
||||
|
||||
var obj = {0: "a", length: 1, splice: Array.prototype.splice};
|
||||
|
||||
elem = obj.splice(0);
|
||||
assertEquals(obj, {length: 0});
|
||||
assert(elem == "a");
|
||||
|
||||
obj = {0: "a", length: 1, splice: Array.prototype.splice};
|
||||
elem = obj.splice(0, 0);
|
||||
assertEquals(obj, {0: "a", length: 1});
|
||||
assert(elem == "");
|
||||
|
||||
elem = obj.splice(0, 1);
|
||||
assertEquals(obj, {length: 0});
|
||||
assert(elem == "a");
|
||||
|
||||
obj = {0: "a", length: 1, splice: Array.prototype.splice};
|
||||
elem = obj.splice(0, 0, "b");
|
||||
assertEquals(obj, {0: "b", length: 2, 1: "a"});
|
||||
assert(elem == "");
|
||||
|
||||
obj = {0: "a", length: 1, splice: Array.prototype.splice};
|
||||
elem = obj.splice(0, 2, "b", "c");
|
||||
assertEquals(obj, {0: "b", length: 2, 1: "c"});
|
||||
assert(elem == "a");
|
||||
|
||||
elem = obj.splice(0, 2, "a");
|
||||
assertEquals(obj, {0: "a", length: 1});
|
||||
assertEquals(elem, ["b", "c"]);
|
||||
|
||||
// Array.prototype.slice
|
||||
arr = ["a", "b", "c"]
|
||||
assertEquals(arr.slice(), ["a", "b", "c"]);
|
||||
assertEquals(arr.slice(1), ["b", "c"]);
|
||||
assertEquals(arr.slice(0, 2), ["a", "b"]);
|
||||
|
||||
obj = {0: "a", 1: "b", 2: "c", length: 3, slice: Array.prototype.slice};
|
||||
assertEquals(obj.slice(), ["a", "b", "c"]);
|
||||
assertEquals(obj.slice(1), ["b", "c"]);
|
||||
assertEquals(obj.slice(0, 2), ["a", "b"]);
|
||||
|
||||
// Array.prototype.filter
|
||||
arr = ["foo", "bar", "foobar"];
|
||||
var result = arr.filter(function(word) { return word.length > 3; });
|
||||
assertEquals(result, ["foobar"]);
|
||||
|
||||
obj = {0: "foo", 1: "bar", 2: "foobar", length: 3, filter: Array.prototype.filter};
|
||||
result = obj.filter(function(word) { return word.length > 3; });
|
||||
assertEquals(result, ["foobar"]);
|
||||
|
||||
// Array.prototype.map
|
||||
arr = [1, 2, 3, 4];
|
||||
var map = arr.map(function(n) { return n * n; });
|
||||
assertEquals(map, [1, 4, 9, 16]);
|
||||
|
||||
obj = {0: 1, 1: 2, 2: 3, 3: 4, length: 4, map: Array.prototype.map};
|
||||
map = obj.map(function(n) { return n * n; });
|
||||
assertEquals(map, [1, 4, 9, 16]);
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function ff() {
|
||||
var a = (k) => { return () => { return arguments[0] + 1;}};
|
||||
return a(1)();
|
||||
}
|
||||
assert(ff(1) == 2)
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function test(a, b, c) {
|
||||
assert(a == 10);
|
||||
assert(b() == 20);
|
||||
assert(c == 30);
|
||||
}
|
||||
|
||||
function test2(a, b, c) {
|
||||
eval("this");
|
||||
assert(a == 10);
|
||||
assert(b() == 20);
|
||||
assert(c == 30);
|
||||
}
|
||||
|
||||
test(10, () => { return 20; }, 30)
|
||||
test2(10, () => { return 20; }, 30)
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 2014 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.
|
||||
|
||||
// Arrow functions are like functions, except they throw when using the
|
||||
// "new" operator on them.
|
||||
assert("function" === typeof (() => {}));
|
||||
assert(Function.prototype === Object.getPrototypeOf(() => {}));
|
||||
assertThrows(function() { new (() => {}); }, TypeError);
|
||||
assert(!("prototype" in (() => {})));
|
||||
|
||||
// Check the different syntax variations
|
||||
assert(1 === (() => 1)());
|
||||
assert(2 === (a => a + 1)(1));
|
||||
assert(3 === (() => { return 3; })());
|
||||
assert(4 === (a => { return a + 3; })(1));
|
||||
assert(5 === ((a, b) => a + b)(1, 4));
|
||||
assert(6 === ((a, b) => { return a + b; })(1, 5));
|
||||
|
||||
// The following are tests from:
|
||||
// http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax
|
||||
|
||||
// Empty arrow function returns undefined
|
||||
var empty = () => {};
|
||||
assert(undefined === empty());
|
||||
|
||||
// Single parameter case needs no parentheses around parameter list
|
||||
var identity = x => x;
|
||||
assert(empty === identity(empty));
|
||||
|
||||
// No need for parentheses even for lower-precedence expression body
|
||||
var square = x => x * x;
|
||||
assert(9 === square(3));
|
||||
|
||||
// Parenthesize the body to return an object literal expression
|
||||
var key_maker = val => ({key: val});
|
||||
assert(empty === key_maker(empty).key);
|
||||
|
||||
// Statement body needs braces, must use 'return' explicitly if not void
|
||||
var evens = [0, 2, 4, 6, 8];
|
||||
var evenMap = evens.map(v => v + 1);
|
||||
assert(evenMap[0] === 1);
|
||||
assert(evenMap[1] === 3);
|
||||
assert(evenMap[2] === 5);
|
||||
assert(evenMap[3] === 7);
|
||||
assert(evenMap[4] === 9);
|
||||
|
||||
var fives = [];
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].forEach(v => {
|
||||
if (v % 5 === 0) fives.push(v);
|
||||
});
|
||||
assert(fives[0] === 5);
|
||||
assert(fives[1] === 10);
|
||||
|
||||
// v8:4474
|
||||
(function testConciseBodyReturnsRegexp() {
|
||||
var arrow1 = () => /foo/
|
||||
var arrow2 = () => /foo/;
|
||||
var arrow3 = () => /foo/i
|
||||
var arrow4 = () => /foo/i;
|
||||
assert(arrow1.toString() === "() => /foo/");
|
||||
assert(arrow2.toString() === "() => /foo/");
|
||||
assert(arrow3.toString() === "() => /foo/i");
|
||||
assert(arrow4.toString() === "() => /foo/i");
|
||||
});
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function assert(expression) {
|
||||
if (!expression) {
|
||||
throw new Error("Assertion failed");
|
||||
}
|
||||
}
|
||||
|
||||
function assertThrows(code, errorType) {
|
||||
try {
|
||||
if (typeof code === 'function') {
|
||||
code();
|
||||
} else {
|
||||
eval(code);
|
||||
}
|
||||
} catch (e) {
|
||||
if (errorType && !(e instanceof errorType)) {
|
||||
throw new Error("Expected exception has failed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new Error("Did not throw exception");
|
||||
}
|
||||
|
||||
function assertNotReached(message) {
|
||||
throw new Error("message");
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function must_throw_strict(str) {
|
||||
try {
|
||||
eval ("'use strict';" + str);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
//ES5 method
|
||||
assert(parseInt("111110111", 2) === 503);
|
||||
assert(parseInt("767", 8) === 503);
|
||||
|
||||
//ES6 literal method
|
||||
assert(0b111110111 === 503)
|
||||
assert(0B111110111 === 503)
|
||||
assert(0o767 === 503)
|
||||
assert(0O767 === 503)
|
||||
|
||||
//this should only work in non-strict as this is backward compatibility thing
|
||||
assert(0767 === 503)
|
||||
//test for throwing error in strict
|
||||
must_throw_strict("0767 === 503")
|
||||
|
||||
//some "should not work" tests
|
||||
//these should equal to 503 as shown above
|
||||
assertThrows("assert(0b111110111 === 502)")
|
||||
assertThrows("assert(0o767 === 502)")
|
||||
//test for not existing literal markers
|
||||
assertThrows("assert(0a767 === 502)")
|
||||
assertThrows("assert(0C767 === 502)")
|
||||
assertThrows("assert(0y767 === 502)")
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
print = assert
|
||||
|
||||
eval("var dd")
|
||||
var global
|
||||
function test() {
|
||||
global;
|
||||
Math
|
||||
print(isFunctionAllocatedOnStack(test))
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
new Function("print(isFunctionAllocatedOnStack(arguments.callee))")()
|
||||
|
||||
|
||||
print(!isFunctionAllocatedOnStack(heap))
|
||||
function heap() {
|
||||
var local;
|
||||
function foo() {
|
||||
global;
|
||||
}
|
||||
|
||||
print(isFunctionAllocatedOnStack(nonheap2))
|
||||
function nonheap2() {
|
||||
print(isFunctionAllocatedOnStack(foo3))
|
||||
function foo3() {
|
||||
local;
|
||||
}
|
||||
return foo3;
|
||||
}
|
||||
|
||||
return nonheap2
|
||||
}
|
||||
|
||||
|
||||
heap()()()
|
||||
|
||||
print(!isFunctionAllocatedOnStack(heap2))
|
||||
function heap2() {
|
||||
var local;
|
||||
print(isFunctionAllocatedOnStack(nonheap2))
|
||||
function nonheap2() {
|
||||
print(isFunctionAllocatedOnStack(foo3))
|
||||
function foo3() {
|
||||
local;
|
||||
}
|
||||
foo3()
|
||||
}
|
||||
|
||||
nonheap2()
|
||||
}
|
||||
|
||||
heap2()
|
||||
|
||||
|
||||
print(isFunctionAllocatedOnStack(test5))
|
||||
function test5() {
|
||||
var local;
|
||||
dd; Math;
|
||||
}
|
||||
|
||||
|
||||
let globallet;
|
||||
print(isFunctionAllocatedOnStack(test6))
|
||||
function test6() {
|
||||
globallet;
|
||||
}
|
||||
|
||||
print(!isFunctionAllocatedOnStack(test7))
|
||||
print(isBlockAllocatedOnStack(test7, 0))
|
||||
print(!isBlockAllocatedOnStack(test7, 2))
|
||||
function test7() {
|
||||
{ //1
|
||||
globallet;
|
||||
}
|
||||
{
|
||||
//2
|
||||
let local;
|
||||
print(isFunctionAllocatedOnStack(sub))
|
||||
function sub() {
|
||||
print(isFunctionAllocatedOnStack(subsub))
|
||||
print(isBlockAllocatedOnStack(subsub, 0))
|
||||
print(isBlockAllocatedOnStack(subsub, 1))
|
||||
function subsub() {
|
||||
local;
|
||||
{
|
||||
let l;
|
||||
}
|
||||
}
|
||||
return subsub
|
||||
}
|
||||
}
|
||||
return sub;
|
||||
}
|
||||
|
||||
test7()()()
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 key1 = {
|
||||
toString: function() {
|
||||
return 'b';
|
||||
}
|
||||
};
|
||||
var key2 = {
|
||||
toString: function() {
|
||||
return 'd';
|
||||
}
|
||||
};
|
||||
class TestClass {
|
||||
a() { return 'A'; }
|
||||
[key1]() { return 'B'; }
|
||||
c() { return 'C'; }
|
||||
[key2]() { return 'D'; }
|
||||
}
|
||||
|
||||
var expect1 = [];
|
||||
var expect2 = ['constructor', 'a', 'b', 'c', 'd'];
|
||||
|
||||
var test1 = Object.keys(TestClass.prototype);
|
||||
assert(test1.length === expect1.length);
|
||||
for (var i = 0 ; i < expect1.length; ++i) {
|
||||
assert(test1[i]);
|
||||
assert(test1[i] === expect1[i]);
|
||||
}
|
||||
|
||||
var test2 = Object.getOwnPropertyNames(TestClass.prototype);
|
||||
assert(test2.length === expect2.length);
|
||||
for (var i = 0 ; i < expect2.length; ++i) {
|
||||
assert(test2[i] === expect2[i]);
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* 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 g = Array.bind (0, 1, 2, 3)
|
||||
g.prototype = Array.prototype;
|
||||
|
||||
class C extends g {}
|
||||
|
||||
class D extends C {
|
||||
constructor () {
|
||||
super (4, 5);
|
||||
}
|
||||
}
|
||||
|
||||
var d = new D;
|
||||
assert (Object.getPrototypeOf (d) == D.prototype);
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
function isInstanceofArray (instance) {
|
||||
assert (instance instanceof C);
|
||||
assert (instance instanceof B);
|
||||
assert (instance instanceof A);
|
||||
assert (instance instanceof Array);
|
||||
}
|
||||
|
||||
class A extends Array {
|
||||
f () {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
g () {
|
||||
return eval ("eval ('super.f ()')");
|
||||
}
|
||||
}
|
||||
|
||||
class C extends B {
|
||||
h () {
|
||||
return eval ('super.g ()');
|
||||
}
|
||||
}
|
||||
|
||||
var c = new C (1, 2, 3, 4, 5, 6);
|
||||
|
||||
isInstanceofArray (c);
|
||||
c.push (7);
|
||||
assert (c.length === 7);
|
||||
assert (c.f () === 5);
|
||||
assert (c.g () === 5);
|
||||
assert (c.h () === 5);
|
||||
|
||||
/* TODO: Enable these tests after Symbol has been implemented
|
||||
// Test built-in Array prototype methods
|
||||
var mapped = c.map ((x) => x * 2);
|
||||
isInstanceofArray (mapped);
|
||||
|
||||
for (var i = 0; i < mapped.length; i++) {
|
||||
assert (mapped[i] == c[i] * 2);
|
||||
}
|
||||
|
||||
var concated = c.concat (c);
|
||||
isInstanceofArray (concated);
|
||||
|
||||
for (var i = 0; i < concated.length; i++) {
|
||||
assert (concated[i] == c[i % (concated.length / 2)]);
|
||||
}
|
||||
|
||||
var sliced = c.slice (c);
|
||||
isInstanceofArray (sliced);
|
||||
|
||||
for (var i = 0; i < sliced.length; i++) {
|
||||
assert (sliced[i] == c[i]);
|
||||
}
|
||||
|
||||
var filtered = c.filter ((x) => x > 100);
|
||||
isInstanceofArray (sliced);
|
||||
assert (filtered.length === 0);
|
||||
|
||||
var spliced = c.splice (c.length - 1);
|
||||
isInstanceofArray (spliced);
|
||||
assert (spliced.length === 1);
|
||||
assert (spliced[0] === 7);
|
||||
|
||||
c.constructor = 5;
|
||||
|
||||
try {
|
||||
mapped = c.map ((x) => x * 2);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
concated = c.concat (c);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
sliced = c.slice (c);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
filtered = c.filter ((x) => x > 100);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
spliced = c.splice (0);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
function isInstanceofTypedArray (instance) {
|
||||
assert (instance instanceof C);
|
||||
assert (instance instanceof B);
|
||||
assert (instance instanceof A);
|
||||
assert (instance instanceof Uint8Array);
|
||||
}
|
||||
|
||||
class A extends Uint8Array {
|
||||
f () {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
g () {
|
||||
return super.f ();
|
||||
}
|
||||
}
|
||||
|
||||
class C extends B {
|
||||
h () {
|
||||
return super.g ();
|
||||
}
|
||||
}
|
||||
|
||||
var c = new C ([1, 2, 3, 4, 5, 6]);
|
||||
|
||||
isInstanceofTypedArray (c);
|
||||
assert (c.length === 6);
|
||||
assert (c.f () === 5)
|
||||
assert (c.g () === 5)
|
||||
assert (c.h () === 5)
|
||||
|
||||
/* TODO: Enable these tests after Symbol has been implemented
|
||||
var mapped = c.map ((x) => x * 2);
|
||||
isInstanceofTypedArray (mapped);
|
||||
|
||||
for (var i = 0; i < mapped.length; i++) {
|
||||
assert (mapped[i] == c[i] * 2);
|
||||
}
|
||||
|
||||
var filtered = c.filter ((x) => x > 100);
|
||||
isInstanceofTypedArray (filtered);
|
||||
assert (filtered.length === 0);
|
||||
|
||||
c.constructor = 5;
|
||||
|
||||
try {
|
||||
mapped = c.map ((x) => x * 2);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
filtered = c.filter ((x) => x > 100);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError)
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class Animal {
|
||||
constructor (name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
hello () {
|
||||
return "Hello I am " + this.name;
|
||||
}
|
||||
|
||||
static speak () {
|
||||
return "Animals roar.";
|
||||
}
|
||||
|
||||
static explain () {
|
||||
return "I can walk,";
|
||||
}
|
||||
|
||||
whoAmI () {
|
||||
return "I am an Animal.";
|
||||
}
|
||||
|
||||
breath () {
|
||||
return "I am breathing.";
|
||||
}
|
||||
|
||||
get myName () {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
set rename (name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
constructor (name, barks) {
|
||||
super (name);
|
||||
this.barks = barks;
|
||||
}
|
||||
|
||||
hello () {
|
||||
return super.hello () + " and I can " + (this.barks ? "bark" : "not bark");
|
||||
}
|
||||
|
||||
whoAmI () {
|
||||
return "I am a Dog.";
|
||||
}
|
||||
|
||||
static speak () {
|
||||
return "Dogs bark.";
|
||||
}
|
||||
|
||||
static explain () {
|
||||
return super.explain () + " jump,";
|
||||
}
|
||||
|
||||
bark () {
|
||||
return this.barks ? "Woof" : "----";
|
||||
}
|
||||
}
|
||||
|
||||
class Doge extends Dog {
|
||||
constructor (name, barks, awesomeness) {
|
||||
super (name, barks);
|
||||
this.awesomeness = awesomeness;
|
||||
}
|
||||
|
||||
hello () {
|
||||
return super.hello () + " and I'm " + (this.awesomeness > 9000 ? "super awesome" : "awesome") + ".";
|
||||
}
|
||||
|
||||
whoAmI ( ) {
|
||||
return "I am a Doge.";
|
||||
}
|
||||
|
||||
static speak () {
|
||||
return "Doges wow.";
|
||||
}
|
||||
|
||||
static explain () {
|
||||
return super.explain () + " dance.";
|
||||
}
|
||||
}
|
||||
|
||||
var doge = new Doge ("doggoe", true, 10000);
|
||||
assert (doge.name === "doggoe");
|
||||
doge.rename = "doggo";
|
||||
assert (doge.myName === "doggo");
|
||||
assert (doge.barks === true);
|
||||
assert (doge.awesomeness === 10000);
|
||||
assert (doge.hello () === "Hello I am doggo and I can bark and I'm super awesome.");
|
||||
assert (doge.whoAmI () === "I am a Doge.");
|
||||
assert (doge.breath () === "I am breathing.");
|
||||
assert (doge.bark () === "Woof");
|
||||
assert (Doge.speak () === "Doges wow.");
|
||||
assert (Doge.explain () === "I can walk, jump, dance.");
|
||||
assert (doge instanceof Animal);
|
||||
assert (doge instanceof Dog);
|
||||
assert (doge instanceof Doge);
|
||||
assert (Dog.prototype.constructor === Dog)
|
||||
assert (Doge.prototype.constructor === Doge)
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor () {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A { }
|
||||
|
||||
try {
|
||||
new B;
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor () {
|
||||
assert (false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor () {
|
||||
return { o : 10 };
|
||||
}
|
||||
}
|
||||
|
||||
var b = new B;
|
||||
assert (b.o === 10);
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor (a, b, c) {
|
||||
eval ("eval ('super (a, b, c)')");
|
||||
eval ("eval ('this.f = 5;')");
|
||||
assert (this.h ()()() === 5);
|
||||
|
||||
return { o : 4 };
|
||||
}
|
||||
|
||||
g () {
|
||||
return function () {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor (a, b, c) {
|
||||
eval ("eval ('super (a, b, c)')");
|
||||
assert (this.f === undefined)
|
||||
assert (this.o === 4)
|
||||
this.k = 5;
|
||||
return { o : 7 };
|
||||
}
|
||||
|
||||
h () {
|
||||
return super["g"];
|
||||
}
|
||||
}
|
||||
|
||||
var b = new B (1, 2, 3, 4);
|
||||
assert (b.k === undefined);
|
||||
assert (b.o === 7);
|
||||
assert (b.h === undefined);
|
||||
assert (b.g === undefined);
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class C extends Array {
|
||||
constructor (a, b) {
|
||||
var a = eval ('super (arguments);');
|
||||
}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
constructor () {
|
||||
var a = eval ("eval ('super (1, 2);')");
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var d = new D;
|
||||
assert (JSON.stringify (d) === '[{"0":1,"1":2}]');
|
||||
assert (d + "" === "[object Arguments]");
|
||||
assert (d.length === 1);
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A {
|
||||
constructor () {
|
||||
this.a = 5;
|
||||
}
|
||||
|
||||
f () {
|
||||
return 10;
|
||||
}
|
||||
|
||||
super () {
|
||||
this.super = 10;
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor () {
|
||||
super ();
|
||||
assert (super.f === A.prototype.f);
|
||||
super.f = 8;
|
||||
assert (this.f === 8);
|
||||
assert (super.f === A.prototype.f);
|
||||
|
||||
assert (this.a === 5);
|
||||
super.a = 10;
|
||||
assert (this.a === 10);
|
||||
|
||||
assert (super.super () === 15);
|
||||
assert (this.super === 10);
|
||||
super.super = 20;
|
||||
assert (this.super === 20);
|
||||
assert (super.super () === 15);
|
||||
}
|
||||
}
|
||||
|
||||
var b = new B;
|
||||
assert (b.f === 8);
|
||||
assert (b.a === 10);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor () {
|
||||
super ();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
var a = new A;
|
||||
assert (a.length === 0);
|
||||
assert (a instanceof Array);
|
||||
assert (a instanceof A);
|
||||
assert (JSON.stringify (a) === "[]");
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class C {
|
||||
static a () {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
constructor () {
|
||||
super ();
|
||||
}
|
||||
}
|
||||
|
||||
assert (D.a () === 5);
|
||||
|
||||
C.a = function () {
|
||||
return 6;
|
||||
}
|
||||
|
||||
assert (D.a () === 6);
|
||||
|
||||
C = 5;
|
||||
|
||||
assert (D.a () === 6);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor (a, b, c) {
|
||||
super (a, b);
|
||||
this.f = 5;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A { }
|
||||
|
||||
var b = new B (1, 2, 3, 4);
|
||||
assert (b.f === 5);
|
||||
assert (b.length === 2);
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor (a, b, c) {
|
||||
super (a, b);
|
||||
this.f = 5;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor (a, b, c) {
|
||||
super (a, b);
|
||||
this.g = super.f;
|
||||
this.h = this.f;
|
||||
}
|
||||
}
|
||||
|
||||
var b = new B (1, 2, 3, 4);
|
||||
assert (b.g === undefined);
|
||||
assert (b.h === 5);
|
||||
assert (b.length === 2);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor (a, b, c) {
|
||||
eval ("eval ('super (a, b, c)')");
|
||||
eval ("eval ('this.f = 5;')");
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A { }
|
||||
|
||||
var b = new B (1, 2, 3, 4);
|
||||
assert (b.f === 5);
|
||||
assert (b.length === 3);
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class A extends Array {
|
||||
constructor (a, b, c, d, e) {
|
||||
eval ("eval ('super (a, b, c)')");
|
||||
this.a = 6;
|
||||
return new String ("foo");
|
||||
}
|
||||
|
||||
f () {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor (a, b, c, d) {
|
||||
eval ("eval ('super (a, b, c, d)')");
|
||||
assert (super.f () === 5);
|
||||
}
|
||||
}
|
||||
|
||||
var a = new B (1, 2, 3, 4, 5, 6);
|
||||
assert (a.a === undefined);
|
||||
assert (a[0] + a[1] + a[2] === "foo");
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class C extends Array {
|
||||
constructor () {
|
||||
var a = eval ('super (1, 2); 5');
|
||||
assert (a === 5);
|
||||
}
|
||||
}
|
||||
|
||||
class D extends C {
|
||||
constructor () {
|
||||
var a = eval ("eval ('super (1, 2); 3')");
|
||||
assert (a === 3);
|
||||
}
|
||||
}
|
||||
|
||||
var d = new D;
|
||||
|
||||
assert (JSON.stringify (d) === "[1,2]");
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/* 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 A = Array;
|
||||
var order = 0;
|
||||
|
||||
function f () {
|
||||
order++;
|
||||
|
||||
return function () {
|
||||
return A;
|
||||
}
|
||||
}
|
||||
|
||||
var B = class extends f ()() {
|
||||
constructor () {
|
||||
assert (++order === 2);
|
||||
eval ("eval ('super (1, 2, 3, 4)')");
|
||||
try {
|
||||
super (1, 2, 3, 4, 5)
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError)
|
||||
}
|
||||
|
||||
assert (this.g ()()()() === 10);
|
||||
assert (eval ("eval ('this.g ()')()")()() === 10);
|
||||
assert (eval ("eval ('this.g ()')")()()() === 10);
|
||||
assert (eval ("eval ('this.g ()()()')")() === 10);
|
||||
assert (eval ("eval ('this.g')")()()()() === 10);
|
||||
this.push (5);
|
||||
assert (this.length === 5)
|
||||
eval ('this.push (6)');
|
||||
assert (this.length === 6);
|
||||
eval ("eval ('this.push (7)')");
|
||||
this.j = 6;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var C = class extends B {
|
||||
g () {
|
||||
return function () {
|
||||
return () => {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var D = class D extends C {
|
||||
constructor () {
|
||||
super ();
|
||||
this.k = 5;
|
||||
return
|
||||
}
|
||||
|
||||
g () {
|
||||
return eval ('super["g"]');
|
||||
}
|
||||
}
|
||||
|
||||
assert (order === 1);
|
||||
|
||||
var d = new D;
|
||||
assert (d.length === 7);
|
||||
assert (d.k === 5);
|
||||
assert (d.j === 6);
|
||||
assert (d instanceof D);
|
||||
assert (d instanceof C);
|
||||
assert (d instanceof B);
|
||||
assert (d instanceof f ()());
|
||||
assert (JSON.stringify (d) === "[1,2,3,4,5,6,7]");
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/* 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 order = 0;
|
||||
|
||||
try {
|
||||
var A = class extends null {
|
||||
constructor () {
|
||||
order++;
|
||||
}
|
||||
}
|
||||
|
||||
new A;
|
||||
} catch (e) {
|
||||
assert (order === 1);
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
function must_throw (str) {
|
||||
try {
|
||||
eval ("switch (1) { default: " + str + "}");
|
||||
assert (false);
|
||||
} catch (e) { }
|
||||
|
||||
try {
|
||||
eval (str);
|
||||
assert (false);
|
||||
}
|
||||
catch (e) { }
|
||||
|
||||
try {
|
||||
eval ("'use strict'; switch (1) { default: " + str + "}");
|
||||
assert (false);
|
||||
} catch (e) { }
|
||||
|
||||
try {
|
||||
eval ("'use strict'; " + str);
|
||||
assert (false);
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
class A {
|
||||
constructor (a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
f () {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
must_throw ("class B extends 5 + 6 + 5 { constructor (a, b) { super (a) } }");
|
||||
|
||||
must_throw ("class B extends null { constructor () { super () } }; new B");
|
||||
|
||||
must_throw ("var o = { a : 5 }; \
|
||||
class B extends Object.keys (o)[0] { constructor (a, b) { super (a) } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { this.b = b} } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super.f () } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { eval ('this.b = b') } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { eval ('super.f ()') } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super (a); super (a); } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { eval ('super (a)'); eval ('super (a)'); } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super (a) } g () { super (a) } } \
|
||||
var b = new B (1, 2);");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super (a) } g () { eval ('super (a)') } } \
|
||||
var b = new B (1, 2); \
|
||||
b.g ();");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super (a) } g () { return function () { return super.f () } } } \
|
||||
var b = new B (1, 2); \
|
||||
b.g ()();");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super (a) } \
|
||||
g () { return function () { return eval ('super.f ()') } } } \
|
||||
var b = new B (1, 2); \
|
||||
b.g ()();");
|
||||
|
||||
must_throw ("class B extends A { constructor (a, b) { super (a) } \
|
||||
g () { return function () { return eval (\"eval ('super.f ();')\") } } } \
|
||||
var b = new B (1, 2); \
|
||||
b.g ()();");
|
||||
|
||||
must_throw ("class A extends Array { constructor () { return 5; } }; new A");
|
||||
|
||||
must_throw ("class A extends Array { constructor () { return undefined; } }; new A");
|
||||
|
||||
must_throw ("class B extends undefined { }; new B;");
|
||||
|
||||
must_throw ("var A = class extends Array { . }");
|
||||
|
||||
must_throw ("class Array extends Array { }");
|
||||
|
||||
must_throw ("class A extends A { }");
|
||||
|
||||
must_throw ("class A extends { constructor () { super () } }");
|
||||
|
||||
class B extends A {
|
||||
constructor (a, b) {
|
||||
super (a);
|
||||
assert (super.f () === 5);
|
||||
}
|
||||
|
||||
g () {
|
||||
return () => {
|
||||
return super.f ();
|
||||
}
|
||||
}
|
||||
|
||||
h () {
|
||||
return () => {
|
||||
return () => {
|
||||
return eval ('super.f ()');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var b = new B (1, 2);
|
||||
assert (b.g ()() === 5);
|
||||
assert (b.h ()()() === 5);
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
class myArray extends Array { };
|
||||
|
||||
var array = new myArray (1);
|
||||
array.push (2);
|
||||
assert (array.length === 2);
|
||||
assert (array instanceof myArray);
|
||||
assert (array instanceof Array);
|
||||
assert (!([] instanceof myArray));
|
||||
|
||||
class mySecretArray extends myArray { };
|
||||
|
||||
var secretArray = new mySecretArray (1, 2);
|
||||
secretArray.push (3);
|
||||
assert (secretArray.length === 3);
|
||||
assert (secretArray instanceof mySecretArray);
|
||||
assert (secretArray instanceof myArray);
|
||||
assert (secretArray instanceof Array);
|
||||
assert (!([] instanceof mySecretArray));
|
||||
|
||||
class myEpicSecretArray extends mySecretArray { };
|
||||
|
||||
var epicSecretArray = new myEpicSecretArray (1, 2, 3);
|
||||
epicSecretArray.push (4);
|
||||
assert (epicSecretArray.length === 4);
|
||||
assert (epicSecretArray instanceof myEpicSecretArray);
|
||||
assert (epicSecretArray instanceof mySecretArray);
|
||||
assert (epicSecretArray instanceof myArray);
|
||||
assert (epicSecretArray instanceof Array);
|
||||
assert (!([] instanceof myEpicSecretArray));
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* 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 calculatorMixin = Base => class extends Base {
|
||||
f () {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
var randomizerMixin = Base => class extends Base {
|
||||
g () {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
|
||||
class A {
|
||||
constructor () { }
|
||||
}
|
||||
|
||||
class B extends calculatorMixin (randomizerMixin (A)) {
|
||||
|
||||
}
|
||||
|
||||
var b = new B ();
|
||||
assert (b.f () === 1)
|
||||
assert (b.g () === 2);
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
order = 0;
|
||||
|
||||
var Mixin1 = (superclass) => class extends superclass {
|
||||
foo () {
|
||||
assert (order++ == 1)
|
||||
if (super.foo) {
|
||||
super.foo ();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var Mixin2 = (superclass) => class extends superclass {
|
||||
foo () {
|
||||
assert (order++ == 2)
|
||||
if (super.foo) {
|
||||
assert (super.foo () === 5);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class S {
|
||||
foo () {
|
||||
assert (order++ == 3)
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
class C extends Mixin1 (Mixin2 (S)) {
|
||||
foo () {
|
||||
assert (order++ == 0)
|
||||
super.foo ();
|
||||
}
|
||||
}
|
||||
|
||||
new C ().foo ()
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
function must_throw(str) {
|
||||
try {
|
||||
eval("switch (1) { default: " + str + "}");
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
try {
|
||||
eval(str);
|
||||
assert(false);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
must_throw_strict(str);
|
||||
}
|
||||
|
||||
function must_throw_strict(str) {
|
||||
try {
|
||||
eval ("'use strict'; switch (1) { default: " + str + "}");
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
try {
|
||||
eval("'use strict'; " + str);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
must_throw("class {}");
|
||||
must_throw("class class {}");
|
||||
must_throw("class A { constructor() {} this.a = 5 }");
|
||||
must_throw("class A { constructor() {} constructor() {} }");
|
||||
must_throw("class A { static prototype() {} }");
|
||||
must_throw("class A { get constructor() {} }");
|
||||
must_throw("class A { set constructor() {} }");
|
||||
must_throw("class A {}; A()");
|
||||
must_throw("class X {}; var o = {}; Object.defineProperty(o, 'p', { get: X, set: X }); o.p;");
|
||||
must_throw("var a = new A; class A {};");
|
||||
must_throw('class A { "static" e() {} }');
|
||||
|
||||
assert(eval("class A {}") === undefined);
|
||||
assert(eval("var a = class A {}") === undefined);
|
||||
assert(eval("var a = class {}") === undefined);
|
||||
assert(eval("class A { ; ; ; ;;;;;;;;;;;; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;; }") === undefined);
|
||||
assert(eval('class A {"constructor"() {} }') === undefined);
|
||||
assert(isNaN (eval('switch(1) { default: (class A{} % 1) }')));
|
||||
|
||||
class B {
|
||||
}
|
||||
|
||||
var b = new B;
|
||||
assert(typeof B === "function");
|
||||
assert(typeof b === "object");
|
||||
|
||||
class C {
|
||||
c1() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
c2() {
|
||||
return this._c;
|
||||
}
|
||||
3() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
var c = new C;
|
||||
assert (c.c1() === 5);
|
||||
assert (c.c2() === undefined);
|
||||
assert (c["3"]() === 3);
|
||||
|
||||
class D {
|
||||
constructor(d) {
|
||||
this._d = d;
|
||||
}
|
||||
|
||||
d1() {
|
||||
return this._d;
|
||||
}
|
||||
}
|
||||
var d = new D(5);
|
||||
assert(d.d1() === 5);
|
||||
|
||||
class E {
|
||||
constructor(e) {
|
||||
this._e = e;
|
||||
}
|
||||
|
||||
get e() {
|
||||
return this._e;
|
||||
}
|
||||
|
||||
set e(e) {
|
||||
this._e = e;
|
||||
}
|
||||
}
|
||||
var e = new E (5);
|
||||
assert (e.e === 5);
|
||||
e.e = 10;
|
||||
assert (e.e === 10);
|
||||
|
||||
var F = class ClassF {
|
||||
constructor(f) {
|
||||
this._f = f;
|
||||
}
|
||||
|
||||
static f1() {
|
||||
return this;
|
||||
}
|
||||
|
||||
static f2() {
|
||||
return this._f;
|
||||
}
|
||||
|
||||
static f3(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
static constructor(a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
static static(a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
static 2 (a) {
|
||||
return 2 * a;
|
||||
}
|
||||
}
|
||||
|
||||
var f = new F(5);
|
||||
|
||||
assert (f.f1 === undefined);
|
||||
assert (f.f2 === undefined);
|
||||
assert (F.f1() === F);
|
||||
assert (F.f2() === undefined);
|
||||
assert (F.f3(1, 1) === 2);
|
||||
assert (F.constructor(5) === 5);
|
||||
assert (F.static(5) === 5);
|
||||
assert (F["2"](5) === 10);
|
||||
|
||||
var G = class {
|
||||
static set a(a) {
|
||||
this._a = a;
|
||||
}
|
||||
static get a() {
|
||||
return this._a;
|
||||
}
|
||||
static set 1(a) {
|
||||
this._a = a;
|
||||
}
|
||||
static get 1() {
|
||||
return this._a;
|
||||
}
|
||||
|
||||
static set constructor(a) {
|
||||
this._a = a;
|
||||
}
|
||||
static get constructor() {
|
||||
return this._a;
|
||||
}
|
||||
|
||||
static g1() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
static g1() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
G.a = 10;
|
||||
assert (G.a === 10);
|
||||
assert (G.g1() === 10);
|
||||
G["1"] = 20;
|
||||
assert (G["1"] === 20);
|
||||
G.constructor = 30;
|
||||
assert (G.constructor === 30);
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Redeclaration
|
||||
var redeclarations = [ "const a; const a;",
|
||||
"var a; const a;",
|
||||
"const a; var a;",
|
||||
"const a; { var a; }",
|
||||
"const a; { eval ('var a;') }",
|
||||
"switch(1) { case 0: const foo; break; case 1: const foo; break; }",
|
||||
];
|
||||
|
||||
redeclarations.forEach(function(e) {
|
||||
assertThrows(e, SyntaxError);
|
||||
});
|
||||
|
||||
assertThrows("const b;", SyntaxError);
|
||||
|
||||
// Single-statement context
|
||||
var singleStatements = [ "for (;;) const a;",
|
||||
"if (true) const a;",
|
||||
"while (true) const a;",
|
||||
"do const a; while(false);"
|
||||
];
|
||||
|
||||
singleStatements.forEach(function(e) {
|
||||
assertThrows(e, SyntaxError);
|
||||
});
|
||||
|
||||
const MY_FAV = 7;
|
||||
|
||||
try {
|
||||
MY_FAV = 20;
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
assert(MY_FAV === 7);
|
||||
|
||||
if (MY_FAV === 7) {
|
||||
let MY_FAV = 20;
|
||||
assert (MY_FAV === 20);
|
||||
}
|
||||
|
||||
assert(MY_FAV === 7);
|
||||
|
||||
const MY_OBJECT = {'key': 'value'};
|
||||
|
||||
try {
|
||||
MY_OBJECT = {'OTHER_KEY': 'value'};
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
MY_OBJECT.key = 'otherValue';
|
||||
assert(MY_OBJECT.key === 'otherValue');
|
||||
|
||||
const MY_ARRAY = [];
|
||||
MY_ARRAY.push('A');
|
||||
assert(MY_ARRAY[0] === 'A');
|
||||
|
||||
try {
|
||||
MY_ARRAY = ['B'];
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
// Test for statement
|
||||
var array = [0, 1, 2];
|
||||
let n = 0;
|
||||
for (const i = n; ; n++ ) {
|
||||
assert(i === 0);
|
||||
assert(array[n] === n);
|
||||
|
||||
try {
|
||||
i = 7;
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
if (n === array.length - 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
print(i);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
// Test for of statement
|
||||
for (const a of array) {
|
||||
assert(array.includes(a));
|
||||
try {
|
||||
a = 7;
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
print(a);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof ReferenceError);
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
// 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 local = 0;
|
||||
|
||||
switch(0) { /* This switch forces a pre-scanner run. */
|
||||
default:
|
||||
|
||||
function f(a = (5, local = 6),
|
||||
b = ((5 + function(a = 6) { return a }() * 3)),
|
||||
c,
|
||||
d = true ? 1 : 2)
|
||||
{
|
||||
return "" + a + ", " + b + ", " + c + ", " + d;
|
||||
}
|
||||
|
||||
assert(f() === "6, 23, undefined, 1");
|
||||
assert(local === 6);
|
||||
|
||||
var obj = {
|
||||
f: function(a = [10,,20],
|
||||
b,
|
||||
c = Math.cos(0),
|
||||
d)
|
||||
{
|
||||
return "" + a + ", " + b + ", " + c + ", " + d;
|
||||
}
|
||||
};
|
||||
|
||||
assert(obj.f() === "10,,20, undefined, 1, undefined");
|
||||
|
||||
function g(a, b = (local = 7)) { }
|
||||
|
||||
local = 0;
|
||||
g();
|
||||
assert(local === 7);
|
||||
|
||||
local = 0;
|
||||
g(0);
|
||||
assert(local === 7);
|
||||
|
||||
local = 0;
|
||||
g(0, undefined);
|
||||
assert(local === 7);
|
||||
|
||||
local = 0;
|
||||
g(0, null);
|
||||
assert(local === 0);
|
||||
|
||||
local = 0;
|
||||
g(0, false);
|
||||
assert(local === 0);
|
||||
break;
|
||||
}
|
||||
|
||||
function CheckSyntaxError(str)
|
||||
{
|
||||
try {
|
||||
eval(str);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError);
|
||||
}
|
||||
}
|
||||
|
||||
CheckSyntaxError('function x(a += 5) {}');
|
||||
CheckSyntaxError('function x(a =, b) {}');
|
||||
CheckSyntaxError('function x(a = (b) {}');
|
||||
CheckSyntaxError('function x(a, a = 5) {}');
|
||||
CheckSyntaxError('function x(a = 5, a) {}');
|
||||
|
||||
var arrowFunc = (a = 4, b = 5, c = 6) => {
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
assert(arrowFunc() === 15);
|
||||
assert(arrowFunc(1) === 12);
|
||||
assert(arrowFunc(1, 2) === 9);
|
||||
assert(arrowFunc(1, 2, 3) === 6);
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
// Copyright 2013 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Test for-of syntax.
|
||||
|
||||
"use strict";
|
||||
|
||||
function f() { for (x of y) { } }
|
||||
function f() { for (var x of y) { } }
|
||||
function f() { for (var x of y) { } }
|
||||
|
||||
function StrictSyntaxError(s) {
|
||||
try {
|
||||
eval(s);
|
||||
} catch (e) {
|
||||
if (!(e instanceof SyntaxError)) {
|
||||
throw "is not SyntaxError";
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw "did not throw";
|
||||
}
|
||||
|
||||
StrictSyntaxError("function f() { for (x of) { } }");
|
||||
StrictSyntaxError("function f() { for (x of y z) { } }");
|
||||
StrictSyntaxError("function f() { for (x of y;) { } }");
|
||||
|
||||
StrictSyntaxError("function f() { for (var x of) { } }");
|
||||
StrictSyntaxError("function f() { for (var x of y z) { } }");
|
||||
StrictSyntaxError("function f() { for (var x of y;) { } }");
|
||||
|
||||
StrictSyntaxError("function f() { for (var x of) { } }");
|
||||
StrictSyntaxError("function f() { for (var x of y z) { } }");
|
||||
StrictSyntaxError("function f() { for (var x of y;) { } }");
|
||||
|
||||
StrictSyntaxError("function f() { for (of y) { } }");
|
||||
StrictSyntaxError("function f() { for (of of) { } }");
|
||||
StrictSyntaxError("function f() { for (var of y) { } }");
|
||||
StrictSyntaxError("function f() { for (var of of) { } }");
|
||||
StrictSyntaxError("function f() { for (var of y) { } }");
|
||||
StrictSyntaxError("function f() { for (var of of) { } }");
|
||||
|
||||
StrictSyntaxError("function f() { for (x = 3 of y) { } }");
|
||||
StrictSyntaxError("function f() { for (var x = 3 of y) { } }");
|
||||
StrictSyntaxError("function f() { for (var x = 3 of y) { } }");
|
||||
|
||||
|
||||
// Alack, this appears to be valid.
|
||||
function f() { for (of of y) { } }
|
||||
function f() { for (var of of y) { } }
|
||||
function f() { for (var of of y) { } }
|
||||
|
||||
// This too, of course.
|
||||
function f() { for (of in y) { } }
|
||||
function f() { for (var of in y) { } }
|
||||
function f() { for (var of in y) { } }
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
(function TestForArray() {
|
||||
var iterable = [1, 2, 3, 4, 5];
|
||||
var result = 0;
|
||||
|
||||
for (var value of iterable) {
|
||||
result += value;
|
||||
}
|
||||
|
||||
assert(value === 5);
|
||||
assert(result === 15);
|
||||
})();
|
||||
|
||||
|
||||
(function TestForString() {
|
||||
var iterable = "boo";
|
||||
var result = "";
|
||||
|
||||
for (var value of iterable) {
|
||||
result += value;
|
||||
}
|
||||
|
||||
assert(value === "o");
|
||||
assert(result === "boo");
|
||||
})();
|
||||
|
||||
(function TestForTypedArray() {
|
||||
var iterable = new Uint8Array([0x00, 0xff]);
|
||||
var result = 0;
|
||||
|
||||
for (var value of iterable) {
|
||||
result += value;
|
||||
}
|
||||
|
||||
assert(value === 255);
|
||||
assert(result === 255);
|
||||
})();
|
||||
|
||||
(function TestForSet() {
|
||||
var iterable = new Set([1, 1, 2, 2, 3, 3]);
|
||||
var result = 0;
|
||||
|
||||
for (value of iterable) {
|
||||
result += value;
|
||||
}
|
||||
|
||||
assert(result === 6);
|
||||
})();
|
||||
|
||||
(function TestForIterableObject() {
|
||||
var iterable = {
|
||||
[Symbol.iterator] : function() {
|
||||
return {
|
||||
i: 0,
|
||||
next: function() {
|
||||
if (this.i < 3) {
|
||||
return { value: this.i++, done: false };
|
||||
}
|
||||
return { value: undefined, done: true };
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var result = 0;
|
||||
|
||||
for (value of iterable) {
|
||||
result += value;
|
||||
}
|
||||
|
||||
assert(result === 3);
|
||||
})();
|
||||
|
||||
|
|
@ -1,146 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 assertCount = 0;
|
||||
function assertAndCount(e) {
|
||||
assert(e)
|
||||
assertCount++;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++;
|
||||
try {
|
||||
continue;
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
|
||||
|
||||
function fun() {
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++;
|
||||
try {
|
||||
continue;
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
}
|
||||
|
||||
fun();
|
||||
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++; function capture() { y }
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++; function capture() { y }
|
||||
try {
|
||||
continue;
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
|
||||
|
||||
function fun2() {
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++; function capture() { y }
|
||||
continue;
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++; function capture() { y }
|
||||
try {
|
||||
continue;
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 10)
|
||||
}
|
||||
|
||||
fun2();
|
||||
|
||||
count = 0;
|
||||
for (let x = 0; x < 5;) {
|
||||
x++;
|
||||
for (let y = 0; y < 2;) {
|
||||
y++;
|
||||
count++;
|
||||
try {
|
||||
break;
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
assertAndCount(count == 5)
|
||||
|
||||
|
||||
assert(assertCount == 9)
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
// 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.
|
||||
|
||||
function CheckSyntaxError (str)
|
||||
{
|
||||
try {
|
||||
eval (str);
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof SyntaxError);
|
||||
}
|
||||
|
||||
/* force the pre-scanner */
|
||||
try {
|
||||
eval ('switch (1) { default: ' + str + '}');
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof SyntaxError);
|
||||
}
|
||||
}
|
||||
|
||||
CheckSyntaxError ('function x (a, b, ...c, d) {}');
|
||||
CheckSyntaxError ('function x (... c = 5) {}');
|
||||
CheckSyntaxError ('function x (...) {}');
|
||||
CheckSyntaxError ('function x (a, a, ...a) {}');
|
||||
CheckSyntaxError ('"use strict" function x (...arguments) {}');
|
||||
|
||||
rest_params = ['hello', true, 7, {}, [], function () {}];
|
||||
|
||||
function f (x, y, ...a) {
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
assert (a[i] == rest_params[i]);
|
||||
}
|
||||
return (x + y) * a.length;
|
||||
}
|
||||
|
||||
assert (f (1, 2, rest_params[0], rest_params[1], rest_params[2]) === 9);
|
||||
assert (f.length === 2);
|
||||
|
||||
function g (...a) {
|
||||
return a.reduce (function (accumulator, currentValue) { return accumulator + currentValue });
|
||||
}
|
||||
|
||||
assert (g (1, 2, 3, 4) === 10);
|
||||
|
||||
function h (...arguments) {
|
||||
return arguments.length;
|
||||
}
|
||||
|
||||
assert (h (1, 2, 3, 4) === 4);
|
||||
|
||||
function f2 (a, b, c, ...d) {
|
||||
assert (JSON.stringify (d) === '[]');
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
assert (f2 (2, 3, 4) === 9);
|
||||
|
||||
// Needs complex parameter copy.
|
||||
function i(a,b,c,...i) {
|
||||
assert(a == 1);
|
||||
assert(b == 2);
|
||||
assert(c === undefined);
|
||||
assert(JSON.stringify(i) == '[]');
|
||||
}
|
||||
|
||||
i(1, 2);
|
||||
|
||||
// Needs complex parameter copy and can't use indexed variable storage.
|
||||
var dummy = 5;
|
||||
with (dummy) {
|
||||
function i2(a,b,c,...i2) {
|
||||
assert(a == 1);
|
||||
assert(b == 2);
|
||||
assert(c === undefined);
|
||||
assert(JSON.stringify(i2) == '[]');
|
||||
}
|
||||
i2(1, 2);
|
||||
}
|
||||
|
|
@ -1,277 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
function* generator1(i) {
|
||||
yield i;
|
||||
yield i + 10;
|
||||
}
|
||||
|
||||
var gen = generator1(10);
|
||||
|
||||
assert(gen.next().value === 10);
|
||||
assert(gen.next().value === 20);
|
||||
|
||||
// Simple example
|
||||
function* idMaker() {
|
||||
var index = 0;
|
||||
while (index < index+1)
|
||||
yield index++;
|
||||
}
|
||||
|
||||
var gen = idMaker();
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
assert(gen.next().value === i);
|
||||
}
|
||||
|
||||
var console = {log:print};
|
||||
|
||||
// with yield*
|
||||
function* anotherGenerator(i) {
|
||||
yield i + 1;
|
||||
yield i + 2;
|
||||
yield i + 3;
|
||||
}
|
||||
|
||||
function* generator(i) {
|
||||
yield i;
|
||||
yield* anotherGenerator(i);
|
||||
yield i + 10;
|
||||
}
|
||||
|
||||
var gen = generator(10);
|
||||
|
||||
assert(gen.next().value === 10);
|
||||
assert(gen.next().value === 11);
|
||||
assert(gen.next().value === 12);
|
||||
assert(gen.next().value === 13);
|
||||
assert(gen.next().value === 20);
|
||||
|
||||
// Passing arguments into Generators
|
||||
var counter = 0;
|
||||
function logger (a,b) {
|
||||
a;
|
||||
b;
|
||||
counter++;
|
||||
}
|
||||
|
||||
function* logGenerator() {
|
||||
counter++;
|
||||
logger(1, yield);
|
||||
assert(counter === 2);
|
||||
counter++;
|
||||
logger(2, yield);
|
||||
assert(counter === 4);
|
||||
counter++;
|
||||
logger(3, yield);
|
||||
assert(counter === 6);
|
||||
counter++;
|
||||
}
|
||||
|
||||
var gen = logGenerator();
|
||||
|
||||
gen.next();
|
||||
assert(counter === 1);
|
||||
gen.next('pretzel');
|
||||
assert(counter === 3);
|
||||
gen.next('california');
|
||||
assert(counter === 5);
|
||||
gen.next('mayonnaise');
|
||||
assert(counter === 7);
|
||||
|
||||
// Return statement in a generator
|
||||
function* yieldAndReturn() {
|
||||
yield "Y";
|
||||
return "R";
|
||||
yield "unreachable";
|
||||
}
|
||||
|
||||
var gen = yieldAndReturn()
|
||||
assert(gen.next().value === "Y");
|
||||
assert(gen.next().value === "R");
|
||||
assert(gen.next().done === true);
|
||||
|
||||
// Generator as an object property
|
||||
var someObj = {
|
||||
*generator () {
|
||||
yield 'a';
|
||||
yield 'b';
|
||||
}
|
||||
}
|
||||
|
||||
var gen = someObj.generator();
|
||||
assert(gen.next().value === 'a');
|
||||
assert(gen.next().value === 'b');
|
||||
assert(gen.next().done === true);
|
||||
|
||||
// Generator as an object methodSection
|
||||
{
|
||||
class Foo {
|
||||
*generator () {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
}
|
||||
|
||||
var f = new Foo ();
|
||||
var gen = f.generator();
|
||||
|
||||
assert(gen.next().value === 1);
|
||||
assert(gen.next().value === 2);
|
||||
assert(gen.next().value === 3);
|
||||
assert(gen.next().done === true);
|
||||
}
|
||||
|
||||
{
|
||||
// Generator as a computed property
|
||||
class Foo {
|
||||
*[Symbol.iterator] () {
|
||||
yield 1;
|
||||
yield 2;
|
||||
}
|
||||
}
|
||||
|
||||
var array = Array.from(new Foo);
|
||||
assert(array.length === 2);
|
||||
assert(array[0] === 1);
|
||||
assert(array[1] === 2);
|
||||
}
|
||||
|
||||
var SomeObj = {
|
||||
*[Symbol.iterator] () {
|
||||
yield 'a';
|
||||
yield 'b';
|
||||
}
|
||||
}
|
||||
|
||||
array = Array.from(SomeObj);
|
||||
assert(array.length === 2);
|
||||
assert(array[0] === 'a');
|
||||
assert(array[1] === 'b');
|
||||
|
||||
// Generators are not constructable
|
||||
try {
|
||||
function* f() {}
|
||||
var obj = new f;
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
// Generator defined in an expression
|
||||
var foo = function* () {
|
||||
yield 10;
|
||||
yield 20;
|
||||
};
|
||||
|
||||
var bar = foo();
|
||||
assert(bar.next().value);
|
||||
|
||||
// Delegating to another generator
|
||||
function* g1() {
|
||||
yield 2;
|
||||
yield 3;
|
||||
yield 4;
|
||||
}
|
||||
|
||||
function* g2() {
|
||||
yield 1;
|
||||
yield* g1();
|
||||
yield 5;
|
||||
}
|
||||
|
||||
var iterator = g2();
|
||||
assert(iterator.next().value === 1);
|
||||
assert(iterator.next().value === 2);
|
||||
assert(iterator.next().value === 3);
|
||||
assert(iterator.next().value === 4);
|
||||
assert(iterator.next().value === 5);
|
||||
assert(iterator.next().done === true);
|
||||
|
||||
// Other Iterable objects
|
||||
function* g3() {
|
||||
yield* [1, 2];
|
||||
yield* '34';
|
||||
yield* Array.from(arguments);
|
||||
}
|
||||
|
||||
var iterator = g3(5, 6);
|
||||
|
||||
assert(iterator.next().value === 1); // {value: 1, done: false}
|
||||
assert(iterator.next().value === 2); // {value: 2, done: false}
|
||||
assert(iterator.next().value === "3"); // {value: "3", done: false}
|
||||
assert(iterator.next().value === "4"); // {value: "4", done: false}
|
||||
assert(iterator.next().value === 5); // {value: 5, done: false}
|
||||
assert(iterator.next().value === 6); // {value: 6, done: false}
|
||||
assert(iterator.next().done === true); // {value: undefined, done: true}
|
||||
|
||||
// The value of yield* expression itself
|
||||
function* g4() {
|
||||
yield* [1, 2, 3];
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
var result;
|
||||
|
||||
function* g5() {
|
||||
result = yield* g4();
|
||||
}
|
||||
|
||||
var iterator = g5();
|
||||
|
||||
assert(iterator.next().value === 1);
|
||||
assert(iterator.next().value === 2);
|
||||
assert(iterator.next().value === 3);
|
||||
assert(iterator.next().done === true);
|
||||
assert(result === 'foo');
|
||||
|
||||
// %GeneratorPrototype%.return
|
||||
function* g6() {
|
||||
yield* [1, 2, 3];
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
var iterator = g6();
|
||||
|
||||
assert(iterator.next().value === 1);
|
||||
assert(iterator.return().done === true);
|
||||
assert(iterator.next().done === true);
|
||||
|
||||
var iterator = g6();
|
||||
assert(iterator.next().value === 1);
|
||||
assert(iterator.return(5).value === 5);
|
||||
assert(iterator.next().done === true);
|
||||
|
||||
// %GeneratorPrototype%.throw
|
||||
var iterator = g6();
|
||||
assert(iterator.next().value === 1);
|
||||
try {
|
||||
iterator.throw();
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e === undefined);
|
||||
}
|
||||
assert(iterator.next().done === true);
|
||||
|
||||
var iterator = g6();
|
||||
assert(iterator.next().value === 1);
|
||||
try {
|
||||
iterator.throw(5);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e === 5);
|
||||
}
|
||||
assert(iterator.next().done === true);
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
|
||||
function* gDecl() {}
|
||||
var gExpr = function* () {};
|
||||
|
||||
assert(gDecl instanceof GeneratorFunction)
|
||||
assert(gExpr instanceof GeneratorFunction)
|
||||
assert(new GeneratorFunction() instanceof GeneratorFunction)
|
||||
assert(GeneratorFunction() instanceof GeneratorFunction)
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 g = function* () { };
|
||||
var f = function () { };
|
||||
var a = () => { };
|
||||
var o = { a: function () { }, b: () => { }, c: function* () { } };
|
||||
var d = f;
|
||||
|
||||
assert(o.name === undefined)
|
||||
assert(o.a.name === "a")
|
||||
assert(o.b.name === "b")
|
||||
assert(o.c.name === "c")
|
||||
assert(g.name === "g")
|
||||
assert(a.name ==="a")
|
||||
assert(f.name === "f")
|
||||
assert(d.name === 'f')
|
||||
assert(d.toString() === "function () { }");
|
||||
|
||||
var test = function t() {
|
||||
var g = function* () { };
|
||||
var f = function () { };
|
||||
var a = () => { };
|
||||
var o = { a: function () { }, b: () => { }, c: function* () { } };
|
||||
var d = a;
|
||||
|
||||
assert(o.name === undefined)
|
||||
assert(o.a.name === "a")
|
||||
assert(o.b.name === "b")
|
||||
assert(o.c.name === "c")
|
||||
assert(g.name === "g")
|
||||
assert(a.name === "a")
|
||||
assert(f.name === "f")
|
||||
assert(d.name === 'a')
|
||||
assert(d.toString() === "() => { }");
|
||||
|
||||
}
|
||||
test();
|
||||
assert(test.name === "t")
|
||||
|
||||
var s0 = 'function Z';
|
||||
var s1 = '\u02b1(Z';
|
||||
var s2 = '\u02b2, b) { }';
|
||||
var sEval = s0 + s1 + s2;
|
||||
eval(sEval);
|
||||
|
||||
assert(Z\u02b1.toString() === sEval);
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
var arrayIteratorPrototype = [].entries().__proto__;
|
||||
var iteratorPrototype = arrayIteratorPrototype.__proto__;
|
||||
|
||||
assert(Object.prototype === Object.getPrototypeOf(iteratorPrototype));
|
||||
assert(Object.isExtensible(iteratorPrototype));
|
||||
assert(0 === Object.getOwnPropertyNames(iteratorPrototype).length);
|
||||
assert(1 === Object.getOwnPropertySymbols(iteratorPrototype).length);
|
||||
assert(Symbol.iterator ===
|
||||
Object.getOwnPropertySymbols(iteratorPrototype)[0]);
|
||||
|
||||
var descr = Object.getOwnPropertyDescriptor(iteratorPrototype, Symbol.iterator);
|
||||
assert(descr.configurable);
|
||||
assert(!descr.enumerable);
|
||||
assert(descr.writable);
|
||||
|
||||
var iteratorFunction = descr.value;
|
||||
assert('function' === typeof iteratorFunction);
|
||||
assert(0 === iteratorFunction.length);
|
||||
assert('[Symbol.iterator]' === iteratorFunction.name);
|
||||
|
||||
var obj = {};
|
||||
assert(obj === iteratorFunction.call(obj));
|
||||
assert(iteratorPrototype === iteratorPrototype[Symbol.iterator]());
|
||||
|
||||
var mapIteratorPrototype = new Map().entries().__proto__;
|
||||
var setIteratorPrototype = new Set().values().__proto__;
|
||||
var stringIteratorPrototype = 'abc'[Symbol.iterator]().__proto__;
|
||||
assert(iteratorPrototype === mapIteratorPrototype.__proto__);
|
||||
assert(iteratorPrototype === setIteratorPrototype.__proto__);
|
||||
assert(iteratorPrototype === stringIteratorPrototype.__proto__);
|
||||
|
||||
var typedArrays = [
|
||||
Float32Array,
|
||||
Float64Array,
|
||||
Int16Array,
|
||||
Int32Array,
|
||||
Int8Array,
|
||||
Uint16Array,
|
||||
Uint32Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray,
|
||||
];
|
||||
|
||||
for (var constructor of typedArrays) {
|
||||
var array = new constructor();
|
||||
var iterator = array[Symbol.iterator]();
|
||||
assert(iteratorPrototype === iterator.__proto__.__proto__);
|
||||
}
|
||||
|
|
@ -1,201 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Scoping rules
|
||||
function varTest() {
|
||||
var x = 1;
|
||||
if (true) {
|
||||
var x = 2;
|
||||
assert(x === 2);
|
||||
}
|
||||
assert(x === 2);
|
||||
}
|
||||
|
||||
function letTest() {
|
||||
let x = 1;
|
||||
if (true) {
|
||||
let x = 2;
|
||||
assert(x === 2);
|
||||
}
|
||||
assert(x === 1);
|
||||
}
|
||||
|
||||
varTest();
|
||||
letTest();
|
||||
|
||||
var x = 'global';
|
||||
let y = 'global';
|
||||
assert (this.x === 'global');
|
||||
assert(this.y === undefined);
|
||||
|
||||
// Emulating private members
|
||||
|
||||
var console = {log:print};
|
||||
|
||||
var Thing;
|
||||
|
||||
{
|
||||
let privateScope = new WeakMap();
|
||||
let counter = 0;
|
||||
|
||||
Thing = function() {
|
||||
this.someProperty = 'foo';
|
||||
|
||||
privateScope.set(this, {
|
||||
hidden: ++counter,
|
||||
});
|
||||
};
|
||||
|
||||
Thing.prototype.showPublic = function() {
|
||||
return this.someProperty;
|
||||
};
|
||||
|
||||
Thing.prototype.showPrivate = function() {
|
||||
return privateScope.get(this).hidden;
|
||||
};
|
||||
}
|
||||
|
||||
assert(typeof privateScope === "undefined");
|
||||
|
||||
var thing = new Thing();
|
||||
|
||||
assert(thing.someProperty === "foo");
|
||||
assert(thing.showPublic() === "foo");
|
||||
assert(thing.showPrivate() === 1);
|
||||
|
||||
// Redeclaration
|
||||
var redeclarations = [ "let a; let a;",
|
||||
"var a; let a;",
|
||||
"let a; var a;",
|
||||
"let a; { var a; }",
|
||||
"let a; { eval ('var a;') }",
|
||||
"switch(1) { case 0: let foo; break; case 1: let foo; break; }",
|
||||
];
|
||||
|
||||
redeclarations.forEach(function(e) {
|
||||
assertThrows(e, SyntaxError);
|
||||
});
|
||||
|
||||
// Single-statement context
|
||||
var singleStatements = [ "for (;;) let a;",
|
||||
"if (true) let a;",
|
||||
"while (true) let a;",
|
||||
"do let a; while(false);"
|
||||
];
|
||||
|
||||
singleStatements.forEach(function(e) {
|
||||
assertThrows(e, SyntaxError);
|
||||
});
|
||||
|
||||
|
||||
switch(1) {
|
||||
case 0: {
|
||||
let foo;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
let foo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
print(foo);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
let localBlockVariable = 5;
|
||||
}
|
||||
|
||||
try {
|
||||
print(localBlockVariable);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
// Test temporal dead zone
|
||||
var tdz = [ "assert(bar === undefined); print(foo); assert (false); var bar = 1; let foo = 2;",
|
||||
"assert((typeof undeclaredVariable) === 'undefined'); print(typeof i); assert(false); let i = 10;",
|
||||
"var foo = 33; if (true) { let foo = (foo + 55); }",
|
||||
"function go(n) { for (let n of n.a) { assert (false); } }; go({a: [1, 2, 3]});",
|
||||
];
|
||||
|
||||
tdz.forEach(function(e) {
|
||||
assertThrows(e, ReferenceError);
|
||||
});
|
||||
|
||||
// Other situations
|
||||
var a = 1;
|
||||
var b = 2;
|
||||
|
||||
if (a === 1) {
|
||||
var a = 11;
|
||||
let b = 22;
|
||||
|
||||
assert(a === 11);
|
||||
assert(b === 22);
|
||||
}
|
||||
|
||||
assert(a === 11);
|
||||
assert(b === 2);
|
||||
|
||||
// Test for statement
|
||||
var array = [0, 1, 2];
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
assert(array[i] === i);
|
||||
}
|
||||
|
||||
try {
|
||||
print(i);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
// Test for of statement
|
||||
|
||||
for (let c of array) {
|
||||
try {
|
||||
assert(array.includes(c));
|
||||
} catch (e) {
|
||||
assert(e instanceof ReferenceError);
|
||||
}
|
||||
let c = 7;
|
||||
assert(c === 7);
|
||||
}
|
||||
|
||||
try {
|
||||
print(c);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof ReferenceError);
|
||||
}
|
||||
|
||||
// Test per-iteration block
|
||||
let functionArray = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
let local = i + 2;
|
||||
functionArray[i] = function () { return [i, local] };
|
||||
}
|
||||
|
||||
for (let i = 0; i < functionArray.length; i++) {
|
||||
let result = functionArray[i]();
|
||||
assert(result[0] === i);
|
||||
assert(result[1] === i + 2);
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var map = new Map();
|
||||
|
||||
var objectKey = {};
|
||||
var stringKey = 'keykeykey';
|
||||
var numberKey = 42.24;
|
||||
var booleanKey = true;
|
||||
var undefinedKey = undefined;
|
||||
var nullKey = null;
|
||||
var nanKey = NaN;
|
||||
var zeroKey = 0;
|
||||
var minusZeroKey = -0;
|
||||
|
||||
assert(map.size === 0);
|
||||
|
||||
map.set(objectKey, 'aaa');
|
||||
map.set(stringKey, 'bbb');
|
||||
map.set(numberKey, 'ccc');
|
||||
map.set(booleanKey, 'ddd');
|
||||
map.set(undefinedKey, 'eee');
|
||||
map.set(nullKey, 'fff');
|
||||
map.set(nanKey, 'ggg');
|
||||
map.set(zeroKey, 'hhh');
|
||||
|
||||
assert(8 === map.size);
|
||||
|
||||
assert('aaa' === map.get(objectKey));
|
||||
assert('bbb' === map.get(stringKey));
|
||||
assert('ccc' === map.get(numberKey));
|
||||
assert('ddd' === map.get(booleanKey));
|
||||
assert('eee' === map.get(undefinedKey));
|
||||
assert('fff' === map.get(nullKey));
|
||||
assert('ggg' === map.get(nanKey));
|
||||
assert('hhh' === map.get(zeroKey));
|
||||
|
||||
assert(undefined === map.get({}));
|
||||
assert('bbb' === map.get('keykeykey'));
|
||||
assert('ccc' === map.get(42.24));
|
||||
assert('ddd' === map.get(true));
|
||||
assert('eee' === map.get(undefined));
|
||||
assert('fff' === map.get(null));
|
||||
assert('ggg' === map.get(NaN));
|
||||
assert('hhh' === map.get(0));
|
||||
assert('hhh' === map.get(-0));
|
||||
assert('hhh' === map.get(1 / Infinity));
|
||||
assert('hhh' === map.get(-1 / Infinity));
|
||||
|
||||
var set = new Set();
|
||||
|
||||
var objectKey = {};
|
||||
var stringKey = 'keykeykey';
|
||||
var numberKey = 42.24;
|
||||
var booleanKey = true;
|
||||
var undefinedKey = undefined;
|
||||
var nullKey = null;
|
||||
var nanKey = NaN;
|
||||
var zeroKey = 0;
|
||||
var minusZeroKey = -0;
|
||||
|
||||
assert(set.size === 0);
|
||||
|
||||
set.add(objectKey);
|
||||
set.add(stringKey);
|
||||
set.add(numberKey);
|
||||
set.add(booleanKey);
|
||||
set.add(undefinedKey);
|
||||
set.add(nullKey);
|
||||
set.add(nanKey);
|
||||
set.add(zeroKey);
|
||||
|
||||
assert(8 === set.size);
|
||||
|
||||
assert(set.has(objectKey));
|
||||
assert(set.has(stringKey));
|
||||
assert(set.has(numberKey));
|
||||
assert(set.has(booleanKey));
|
||||
assert(set.has(undefinedKey));
|
||||
assert(set.has(nullKey));
|
||||
assert(set.has(nanKey));
|
||||
assert(set.has(zeroKey));
|
||||
|
||||
assert(!set.has({}));
|
||||
assert(set.has('keykeykey'));
|
||||
assert(set.has(42.24));
|
||||
assert(set.has(true));
|
||||
assert(set.has(undefined));
|
||||
assert(set.has(null));
|
||||
assert(set.has(NaN));
|
||||
assert(set.has(0));
|
||||
assert(set.has(-0));
|
||||
assert(set.has(1 / Infinity));
|
||||
assert(set.has(-1 / Infinity));
|
||||
|
||||
(function TestSetIteratorSymbol() {
|
||||
assert(Set.prototype[Symbol.iterator] === Set.prototype.values);
|
||||
assert(Set.prototype.hasOwnProperty(Symbol.iterator));
|
||||
assert(!Set.prototype.propertyIsEnumerable(Symbol.iterator));
|
||||
|
||||
var iter = new Set().values();
|
||||
assert(iter === iter[Symbol.iterator]());
|
||||
assert(iter[Symbol.iterator].name === '[Symbol.iterator]');
|
||||
})();
|
||||
|
||||
(function TestMapIteratorSymbol() {
|
||||
assert(Map.prototype[Symbol.iterator], Map.prototype.entries);
|
||||
assert(Map.prototype.hasOwnProperty(Symbol.iterator));
|
||||
assert(!Map.prototype.propertyIsEnumerable(Symbol.iterator));
|
||||
|
||||
var iter = new Map().values();
|
||||
assert(iter === iter[Symbol.iterator]());
|
||||
assert(iter[Symbol.iterator].name === '[Symbol.iterator]');
|
||||
})();
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
assert(typeof Object.getPrototypeOf("foo") === "object");
|
||||
assert(Object.getPrototypeOf("foo") === String.prototype);
|
||||
|
||||
assert(Object.preventExtensions(1) === 1);
|
||||
assert(Object.freeze(1) === 1);
|
||||
assert(Object.seal(1) === 1);
|
||||
assert(Object.isExtensible(1) === false);
|
||||
assert(Object.isFrozen(1) === true);
|
||||
assert(Object.isSealed(1) === true);
|
||||
|
|
@ -1,251 +0,0 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
function isSyntaxError(str) {
|
||||
try {
|
||||
eval(str);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError);
|
||||
}
|
||||
}
|
||||
|
||||
// Array destructuring
|
||||
|
||||
// Nested array destructuring
|
||||
var array = [1, 2, [3, [4]], 5, 6, , 7];
|
||||
|
||||
var [a, b, [c, [d]], ...e] = array;
|
||||
assert(a === 1);
|
||||
assert(b === 2);
|
||||
assert(c === 3);
|
||||
assert(d === 4);
|
||||
assert(e[0] === 5);
|
||||
assert(e[1] === 6);
|
||||
assert(e[2] === undefined);
|
||||
assert(e[3] === 7);
|
||||
|
||||
// Basic variable assignment
|
||||
var foo = ['one', 'two', 'three'];
|
||||
|
||||
var [one, two, three] = foo;
|
||||
assert(one === 'one');
|
||||
assert(two === 'two');
|
||||
assert(three === 'three');
|
||||
|
||||
// Assignment separate from declaration
|
||||
var a, b;
|
||||
|
||||
[a, b] = [1, 2];
|
||||
assert(a === 1);
|
||||
assert(b === 2);
|
||||
|
||||
// Array destructuring with defaults
|
||||
[a = 6, b = 7, c = 8] = [1, , undefined];
|
||||
assert(a === 1);
|
||||
assert(b === 7);
|
||||
assert(c === 8);
|
||||
|
||||
// Swapping Variables
|
||||
var a = 1;
|
||||
var b = 3;
|
||||
|
||||
[a, b] = [b, a];
|
||||
|
||||
assert(a === 3);
|
||||
assert(b === 1);
|
||||
|
||||
// Function default argument
|
||||
function defaultArrayArgument ([a,b,c] = [1,2,3]) {
|
||||
return a + b + c
|
||||
}
|
||||
|
||||
assert(defaultArrayArgument() === 6);
|
||||
assert(defaultArrayArgument([4, 5, 6]) === 15);
|
||||
|
||||
// Array destructuring syntax check
|
||||
isSyntaxError("var [x, ...y , x]");
|
||||
isSyntaxError("var [x, x]");
|
||||
isSyntaxError("(function ([x, x]) {})");
|
||||
isSyntaxError("(function ([x, y], x) {})");
|
||||
|
||||
// Object destructuring
|
||||
|
||||
// Basic assignment
|
||||
var o = {p: 42, q: true};
|
||||
var {p, q} = o;
|
||||
|
||||
assert(p === 42);
|
||||
assert(q === true);
|
||||
|
||||
|
||||
// Assignment without declaration
|
||||
var a, b;
|
||||
|
||||
({a, b} = {a: 1, b: 2});
|
||||
|
||||
assert(a === 1);
|
||||
assert(b === 2);
|
||||
|
||||
// Assingment to new variable names
|
||||
var o = {p: 42, q: true};
|
||||
var {p: foo, q: bar} = o;
|
||||
|
||||
assert(foo === 42);
|
||||
assert(bar === true);
|
||||
|
||||
// Default values
|
||||
var {a = 10, b = 5} = {a: 3};
|
||||
|
||||
assert(a === 3);
|
||||
assert(b === 5);
|
||||
|
||||
// Aliasing
|
||||
var {a: aa = 10, b: bb = 5} = {a: 3};
|
||||
assert(aa === 3);
|
||||
assert(bb === 5);
|
||||
|
||||
// Function parameters default value
|
||||
function f({size = 'big', coords = {x: 0, y: 0}, radius = 25} = {}) {
|
||||
assert(size === 'big');
|
||||
assert(coords.x === 0);
|
||||
assert(coords.y === 0);
|
||||
assert(radius === 25);
|
||||
}
|
||||
|
||||
function g({size = 'big', coords = {x: 0, y: 0}, radius = 25} = {}) {
|
||||
assert(size === 'big');
|
||||
assert(coords.x === 18);
|
||||
assert(coords.y === 30);
|
||||
assert(radius === 30);
|
||||
}
|
||||
|
||||
f();
|
||||
g({
|
||||
coords: {x: 18, y: 30},
|
||||
radius: 30
|
||||
});
|
||||
|
||||
|
||||
// Nested object and array destructuring
|
||||
var metadata = {
|
||||
title: 'Scratchpad',
|
||||
translations: [
|
||||
{
|
||||
locale: 'de',
|
||||
localization_tags: [],
|
||||
last_edit: '2014-04-14T08:43:37',
|
||||
url: '/de/docs/Tools/Scratchpad',
|
||||
title: 'JavaScript-Umgebung'
|
||||
}
|
||||
],
|
||||
url: '/en-US/docs/Tools/Scratchpad'
|
||||
};
|
||||
|
||||
var {
|
||||
title: englishTitle, // rename
|
||||
translations: [
|
||||
{
|
||||
title: localeTitle, // rename
|
||||
},
|
||||
],
|
||||
} = metadata;
|
||||
|
||||
assert(englishTitle === 'Scratchpad');
|
||||
assert(localeTitle === 'JavaScript-Umgebung');
|
||||
|
||||
// For of iteration and destructuring
|
||||
var people = [
|
||||
{
|
||||
name: 'Mike Smith',
|
||||
family: {
|
||||
mother: 'Jane Smith',
|
||||
father: 'Harry Smith',
|
||||
sister: 'Samantha Smith'
|
||||
},
|
||||
age: 35
|
||||
},
|
||||
{
|
||||
name: 'Tom Jones',
|
||||
family: {
|
||||
mother: 'Norah Jones',
|
||||
father: 'Richard Jones',
|
||||
brother: 'Howard Jones'
|
||||
},
|
||||
age: 25
|
||||
}
|
||||
];
|
||||
|
||||
var idx = 0;
|
||||
for (var {name: n, family: {father: f}} of people) {
|
||||
if (idx === 0) {
|
||||
assert(n === 'Mike Smith');
|
||||
assert(f === 'Harry Smith');
|
||||
} else {
|
||||
assert(n === 'Tom Jones');
|
||||
assert(f === 'Richard Jones');
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
// Unpacking fields from objects passed as function parameterSection
|
||||
function userId({id}) {
|
||||
return id;
|
||||
}
|
||||
|
||||
function whois({displayName, fullName: {firstName: name}}) {
|
||||
assert(displayName === 'jdoe');
|
||||
assert(name === 'John');
|
||||
}
|
||||
|
||||
var user = {
|
||||
id: 42,
|
||||
displayName: 'jdoe',
|
||||
fullName: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe'
|
||||
}
|
||||
};
|
||||
|
||||
assert(userId(user) === 42);
|
||||
whois(user);
|
||||
|
||||
// Computed object property names and destructuring
|
||||
var key = 'z';
|
||||
var {[key]: foo} = {z: 'bar'};
|
||||
|
||||
assert(foo === 'bar');
|
||||
|
||||
// Invalid JavaScript identifier as a property name
|
||||
var foo = { 'fizz-buzz': true };
|
||||
var { 'fizz-buzz': fizzBuzz } = foo;
|
||||
|
||||
assert(fizzBuzz === true);
|
||||
|
||||
// Combined Array and Object Destructuring
|
||||
var props = [
|
||||
{ id: 1, name: 'Fizz'},
|
||||
{ id: 2, name: 'Buzz'},
|
||||
{ id: 3, name: 'FizzBuzz'}
|
||||
];
|
||||
|
||||
var [,, { name }] = props;
|
||||
|
||||
assert(name === 'FizzBuzz');
|
||||
|
||||
// Object destructuring syntax check
|
||||
isSyntaxError("(function ({x, x}) {})");
|
||||
isSyntaxError("(function ({x, y}, x) {})");
|
||||
isSyntaxError("(function ({x : a, y : a}, b) {})");
|
||||
35
test/es2015/prototypeInheritance2.js
vendored
35
test/es2015/prototypeInheritance2.js
vendored
|
|
@ -1,35 +0,0 @@
|
|||
//-------------------------------------------------------------------------------------------------------
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
|
||||
/* ES6 compatible test */
|
||||
|
||||
print("Test 1: Math.E");
|
||||
var obj = Object.create(Math);
|
||||
obj.E = "foo";
|
||||
assert(obj.E === 2.718281828459045);
|
||||
|
||||
print("Test 2: function length");
|
||||
function myFunc(a, b, c, d) {}
|
||||
obj = Object.create(myFunc);
|
||||
obj.length = "foo";
|
||||
assert(obj.length === 4);
|
||||
|
||||
print("Test 3: Regular expression properties");
|
||||
var regExp = new RegExp("/abc/g");
|
||||
obj = Object.create(regExp);
|
||||
obj.global = "foo";
|
||||
try {
|
||||
obj.global;
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
obj.lastIndex = "foo";
|
||||
print(obj.lastIndex === "foo");
|
||||
|
||||
print("Test 4: String length");
|
||||
obj = Object.create(new String("test"));
|
||||
obj.length = "foo";
|
||||
assert(obj.length === 4);
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function sum(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
var handler = {
|
||||
apply: function(target, thisArg, argumentsList) {
|
||||
return target(argumentsList[0], argumentsList[1]) * 10;
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(sum, handler);
|
||||
|
||||
assert(sum(1, 2) === 3);
|
||||
// expected output: 3
|
||||
assert(proxy1(1, 2) === 30);
|
||||
// expected output: 30
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function monster1(disposition) {
|
||||
this.disposition = disposition;
|
||||
}
|
||||
|
||||
var handler1 = {
|
||||
construct(target, args) {
|
||||
return new target(args[0]);
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
|
||||
assert(new proxy1('fierce').disposition === 'fierce');
|
||||
// expected output: "fierce"
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 handler1 = {
|
||||
defineProperty : function (target, key, descriptor) {
|
||||
invariant(key, 'define');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
function invariant(key, action) {
|
||||
if (key[0] === '_') {
|
||||
throw new Error("Invalid attempt to define private _secret property");
|
||||
}
|
||||
}
|
||||
|
||||
var monster1 = {};
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
|
||||
var code = "proxy1._secret = 1;";
|
||||
assertThrows(code);
|
||||
// expected output: Error: Invalid attempt to define private "_secret" property
|
||||
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 monster1 = {
|
||||
texture: 'scaly'
|
||||
};
|
||||
|
||||
var handler1 = {
|
||||
deleteProperty(target, prop) {
|
||||
if (prop in target) {
|
||||
delete target[prop];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert(monster1.texture === "scaly");
|
||||
// expected output: "scaly"
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
delete proxy1.texture;
|
||||
|
||||
assert(monster1.texture === undefined);
|
||||
// expected output: undefined
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 monster1 = {
|
||||
secret: 'easily scared',
|
||||
eyeCount: 4
|
||||
};
|
||||
|
||||
var handler1 = {
|
||||
get: function(target, prop, receiver) {
|
||||
if (prop === 'secret') {
|
||||
return 'get secret';
|
||||
} else {
|
||||
return target.eyeCount;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
|
||||
assert(proxy1.eyeCount === 4);
|
||||
// expected output: 4
|
||||
|
||||
assert(proxy1.secret === 'get secret');
|
||||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 monster1 = {
|
||||
eyeCount: 4
|
||||
};
|
||||
|
||||
var handler1 = {
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return { configurable: true, enumerable: true, value: 5 };
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
|
||||
assert(Object.getOwnPropertyDescriptor(proxy1, 'eyeCount').value === 5);
|
||||
// expected output: 5
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 monster1 = {
|
||||
eyeCount: 4
|
||||
};
|
||||
|
||||
var monsterPrototype = {
|
||||
eyeCount : 2
|
||||
};
|
||||
|
||||
var handler = {
|
||||
getPrototypeOf(target) {
|
||||
return monsterPrototype;
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler);
|
||||
|
||||
assert(Object.getPrototypeOf(proxy1) === monsterPrototype);
|
||||
// expected output: true
|
||||
|
||||
assert(Object.getPrototypeOf(proxy1).eyeCount === 2);
|
||||
// expected output: 2
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 handler1 = {
|
||||
has (target, key) {
|
||||
if (key[0] === '_') {
|
||||
return false;
|
||||
}
|
||||
return key in target;
|
||||
}
|
||||
};
|
||||
|
||||
var monster1 = {
|
||||
_secret: 'easily scared',
|
||||
eyeCount: 4
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
assert('eyeCount' in proxy1);
|
||||
// expected output: true
|
||||
|
||||
assert('_secret' in proxy1 === false);
|
||||
// expected output: false
|
||||
|
||||
assert('_secret' in monster1);
|
||||
// expected output: true
|
||||
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 monster1 = {
|
||||
canEvolve: true
|
||||
};
|
||||
|
||||
var handler1 = {
|
||||
isExtensible(target) {
|
||||
return Reflect.isExtensible(target);
|
||||
},
|
||||
preventExtensions(target) {
|
||||
target.canEvolve = false;
|
||||
return Reflect.preventExtensions(target);
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
|
||||
assert(Object.isExtensible(proxy1));
|
||||
// expected output: true
|
||||
|
||||
assert(monster1.canEvolve);
|
||||
// expected output: true
|
||||
|
||||
Object.preventExtensions(proxy1);
|
||||
|
||||
assert(Object.isExtensible(proxy1) === false);
|
||||
// expected output: false
|
||||
|
||||
assert(monster1.canEvolve === false);
|
||||
// expected output: false
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 monster1 = {
|
||||
canEvolve: true
|
||||
};
|
||||
|
||||
var handler1 = {
|
||||
preventExtensions(target) {
|
||||
target.canEvolve = false;
|
||||
Object.preventExtensions(target);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
|
||||
assert(monster1.canEvolve);
|
||||
// expected output: true
|
||||
|
||||
Object.preventExtensions(proxy1);
|
||||
|
||||
assert(monster1.canEvolve === false);
|
||||
// expected output: false
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// dummy call, to invoke proxy's get
|
||||
function dummyCall() {
|
||||
}
|
||||
|
||||
// check if string conversion is done
|
||||
var stringHandler = {
|
||||
get: function(obj, prop) {
|
||||
assert(typeof prop == "string")
|
||||
}
|
||||
};
|
||||
var proxyStringExample = new Proxy({}, stringHandler);
|
||||
var proxyArray = new Array(0);
|
||||
dummyCall(proxyArray[1])
|
||||
|
||||
|
||||
// check if symbol type is handled correctly
|
||||
var symbolHandler = {
|
||||
get: function(obj, prop) {
|
||||
assert(typeof prop == "symbol")
|
||||
}
|
||||
};
|
||||
var proxySymbolExample = new Proxy({}, symbolHandler);
|
||||
const SymbolKey = Symbol();
|
||||
|
||||
proxySymbolExample[SymbolKey] = 123;
|
||||
dummyCall(proxySymbolExample[SymbolKey])
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function Monster() {
|
||||
this.eyeCount = 4;
|
||||
}
|
||||
|
||||
var handler1 = {
|
||||
set: function (obj, prop, value) {
|
||||
if ((prop === 'eyeCount') && ((value % 2) !== 0)) {
|
||||
} else {
|
||||
obj.prop = value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var monster1 = new Monster();
|
||||
var proxy1 = new Proxy(monster1, handler1);
|
||||
proxy1.eyeCount = 1;
|
||||
|
||||
assert(proxy1.eyeCount === 4);
|
||||
// expected output: 4
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 handler = {
|
||||
setPrototypeOf: function (target, proto) {
|
||||
target.geneticallyModified = true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var monsterProto = {};
|
||||
|
||||
var monster1 = {
|
||||
geneticallyModified: false
|
||||
};
|
||||
var proxy1 = new Proxy(monster1, handler);
|
||||
|
||||
assertThrows('Object.setPrototypeOf(proxy1, monsterProto)'); // throws a TypeError
|
||||
assert(monster1.geneticallyModified); // expected output: true
|
||||
|
||||
var monster2 = {
|
||||
geneticallyModified: false
|
||||
};
|
||||
var proxy2 = new Proxy(monster2, handler);
|
||||
|
||||
Reflect.setPrototypeOf(proxy2, monsterProto) // Don't throws a TypeError
|
||||
assert(monster2.geneticallyModified); // expected output: true
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
const handler = {
|
||||
get: function (target, name) {
|
||||
return (
|
||||
name in target ? target[name] : 42
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var target1 = function () { };
|
||||
const proxy1 = new Proxy(target1, handler);
|
||||
assert(proxy1.__proto__ === Function.prototype)
|
||||
assert(proxy1.caller === null)
|
||||
try {
|
||||
proxy1.__proto__.caller
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
const target2 = {};
|
||||
const proxy2 = new Proxy(target2, handler);
|
||||
assert(proxy2.__proto__ === Object.prototype)
|
||||
assert(proxy2.caller == 42)
|
||||
assert(proxy2.__proto__.caller === undefined)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 sym = Symbol.for('comet');
|
||||
var sym2 = Symbol.for('meteor');
|
||||
var obj = {
|
||||
[sym2]: 0, 'str': 0, '773': 0, '0': 0,
|
||||
[sym]: 0, '-1': 0, '8': 0, "": 0, 'second str': 0};
|
||||
|
||||
var expects = ["0", "8", "773", "str", "-1", "", "second str", sym2, sym];
|
||||
var keys = Reflect.ownKeys(obj);
|
||||
|
||||
for(var i = 0; i < keys.length; i++){
|
||||
assert(keys[i] === expects[i])
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 target = {};
|
||||
|
||||
Object.defineProperty(target, 'attr', {
|
||||
configurable: false,
|
||||
set: undefined
|
||||
});
|
||||
|
||||
var p = new Proxy(target, {
|
||||
set: function() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assertThrows('Reflect.set(p, "attr", 1)', TypeError);
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 r = /./ug;
|
||||
r.exec('𝌆');
|
||||
assert(r.lastIndex, 2);
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
var a = [1, 2];
|
||||
var b = [5, 6];
|
||||
var c = [9, 10];
|
||||
var d = [0, ...a, 3, 4, ...b, 7, 8, ...c];
|
||||
|
||||
for (var i = 0; i < d.length; i++) {
|
||||
assert(d[i] === i);
|
||||
}
|
||||
|
||||
var str = "foobar";
|
||||
var e = [...str];
|
||||
|
||||
for (var i = 0; i < e.length; i++) {
|
||||
assert(e[i] === str[i]);
|
||||
}
|
||||
|
||||
function f(a, b, c, d, e, f, g) {
|
||||
return a + b + c + d + e + f;
|
||||
}
|
||||
|
||||
var args = [1, 2, 3, 4, 5, 6];
|
||||
assert(f(10, ...args) === 25);
|
||||
|
||||
with ({}) {
|
||||
assert(f(0, ...args) === 15)
|
||||
}
|
||||
|
||||
var str = ["5", "6"];
|
||||
assert(eval(...str) === 5);
|
||||
|
||||
var g = eval;
|
||||
assert(g(...str) === 5);
|
||||
|
||||
var array = [1, 2, 3];
|
||||
var newArray = new Array(...array);
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
assert (array[i] == newArray[i]);
|
||||
}
|
||||
|
|
@ -1,440 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function reportCompare(expectedResult, test)
|
||||
{
|
||||
assert(expectedResult == test)
|
||||
}
|
||||
|
||||
reportCompare(
|
||||
2,
|
||||
String.prototype.replace.length
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"321",
|
||||
String.prototype.replace.call(123, "123", "321")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"ok".replace()
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"undefined**",
|
||||
"***".replace("*")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xnullz",
|
||||
"xyz".replace("y", null)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x123",
|
||||
"xyz".replace("yz", 123)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"/x/g/x/g/x/g",
|
||||
"xxx".replace(/x/g, /x/g)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"undefined".replace(undefined, "ok")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"null".replace(null, "ok")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"123".replace(123, "ok")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xzyxyz",
|
||||
"xyzxyz".replace("yz", "zy")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"(xyz)".replace("(xyz)", "ok")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"*$&yzxyz",
|
||||
"xyzxyz".replace("x", "*$$&")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy*z*",
|
||||
"xyz".replace("z", "*$&*")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xyxyzxyz",
|
||||
"xyzxyzxyz".replace("zxy", "$`")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"zxyzxyzzxyz",
|
||||
"xyzxyz".replace("xy", "$'xyz")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"$",
|
||||
"xyzxyz".replace("xyzxyz", "$")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x$0$00xyz",
|
||||
"xyzxyz".replace("yz", "$0$00")
|
||||
);
|
||||
|
||||
// Result for $1/$01 .. $99 is implementation-defined if searchValue is no
|
||||
// regular expression. $+ is a non-standard Mozilla extension.
|
||||
|
||||
reportCompare(
|
||||
"$!$\"$-1$*$#$.$xyz$$",
|
||||
"xyzxyz$$".replace("xyz", "$!$\"$-1$*$#$.$")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"$$$&$$$&$&",
|
||||
"$$$&".replace("$$", "$$$$$$&$&$$&")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"yxx",
|
||||
"xxx".replace(/x/, "y")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"yyy",
|
||||
"xxx".replace(/x/g, "y")
|
||||
);
|
||||
|
||||
rex = /x/, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"yxx1",
|
||||
"xxx".replace(rex, "y") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /x/g, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"yyy0",
|
||||
"xxx".replace(rex, "y") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /y/, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"xxx1",
|
||||
"xxx".replace(rex, "y") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /y/g, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"xxx0",
|
||||
"xxx".replace(rex, "y") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /x?/, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"(x)xx1",
|
||||
"xxx".replace(rex, "($&)") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /x?/g, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"(x)(x)(x)()0",
|
||||
"xxx".replace(rex, "($&)") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /y?/, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"()xxx1",
|
||||
"xxx".replace(rex, "($&)") + rex.lastIndex
|
||||
);
|
||||
|
||||
rex = /y?/g, rex.lastIndex = 1;
|
||||
reportCompare(
|
||||
"()x()x()x()0",
|
||||
"xxx".replace(rex, "($&)") + rex.lastIndex
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy$0xy$zxy$zxyz$zxyz",
|
||||
"xyzxyzxyz".replace(/zxy/, "$0$`$$$&$$$'$")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy$0xy$zxy$zxyz$$0xyzxy$zxy$z$z",
|
||||
"xyzxyzxyz".replace(/zxy/g, "$0$`$$$&$$$'$")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xyxyxyzxyxyxyz",
|
||||
"xyzxyz".replace(/(((x)(y)()()))()()()(z)/g, "$01$2$3$04$5$6$7$8$09$10")
|
||||
);
|
||||
|
||||
rex = RegExp(
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()(y)");
|
||||
reportCompare(
|
||||
"x(y)z",
|
||||
"xyz".replace(rex, "($99)")
|
||||
);
|
||||
|
||||
rex = RegExp(
|
||||
"()()()()()()()()()(x)" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()(y)");
|
||||
reportCompare(
|
||||
"(x0)z",
|
||||
"xyz".replace(rex, "($100)")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xyz(XYZ)",
|
||||
"xyzXYZ".replace(/XYZ/g, "($&)")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"(xyz)(XYZ)",
|
||||
"xyzXYZ".replace(/xYz/gi, "($&)")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xyz\rxyz\n",
|
||||
"xyz\rxyz\n".replace(/xyz$/g, "($&)")
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"(xyz)\r(xyz)\n",
|
||||
"xyz\rxyz\n".replace(/xyz$/gm, "($&)")
|
||||
);
|
||||
|
||||
f = function () { return "failure" };
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"ok".replace("x", f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"ok".replace(/(?=k)ok/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"ok".replace(/(?!)ok/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"ok",
|
||||
"ok".replace(/ok(?!$)/, f)
|
||||
);
|
||||
|
||||
f = function (sub, offs, str) {
|
||||
return ["", sub, typeof sub, offs, typeof offs, str, typeof str, ""]
|
||||
.join("|");
|
||||
};
|
||||
|
||||
reportCompare(
|
||||
"x|y|string|1|number|xyz|string|z",
|
||||
"xyz".replace("y", f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x|(y)|string|1|number|x(y)z|string|z",
|
||||
"x(y)z".replace("(y)", f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x|y*|string|1|number|xy*z|string|z",
|
||||
"xy*z".replace("y*", f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"12|3|string|2|number|12345|string|45",
|
||||
String.prototype.replace.call(1.2345e4, 3, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"|x|string|0|number|xxx|string|xx",
|
||||
"xxx".replace(/^x/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xx|x|string|2|number|xxx|string|",
|
||||
"xxx".replace(/x$/g, f)
|
||||
);
|
||||
|
||||
f = function (sub, paren, offs, str) {
|
||||
return ["", sub, typeof sub, paren, typeof paren, offs, typeof offs,
|
||||
str, typeof str, ""].join("|");
|
||||
};
|
||||
|
||||
reportCompare(
|
||||
"xy|z|string|z|string|2|number|xyz|string|",
|
||||
"xyz".replace(/(z)/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xyz||string||string|3|number|xyz|string|",
|
||||
"xyz".replace(/($)/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"|xy|string|y|string|0|number|xyz|string|z",
|
||||
"xyz".replace(/(?:x)(y)/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"|x|string|x|string|0|number|xyz|string|yz",
|
||||
"xyz".replace(/((?=xy)x)/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"|x|string|x|string|0|number|xyz|string|yz",
|
||||
"xyz".replace(/(x(?=y))/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x|y|string|y|string|1|number|xyz|string|z",
|
||||
"xyz".replace(/((?!x)y)/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"|x|string|x|string|0|number|xyz|string|" +
|
||||
"|y|string||undefined|1|number|xyz|string|z",
|
||||
"xyz".replace(/y|(x)/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy|z|string||string|2|number|xyz|string|",
|
||||
"xyz".replace(/(z?)z/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy|z|string||undefined|2|number|xyz|string|",
|
||||
"xyz".replace(/(z)?z/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy|z|string||undefined|2|number|xyz|string|",
|
||||
"xyz".replace(/(z)?\1z/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy|z|string||undefined|2|number|xyz|string|",
|
||||
"xyz".replace(/\1(z)?z/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xy|z|string||string|2|number|xyz|string|",
|
||||
"xyz".replace(/(z?\1)z/, f)
|
||||
);
|
||||
|
||||
f = function (sub, paren1, paren2, offs, str) {
|
||||
return ["", sub, typeof sub, paren1, typeof paren1, paren2, typeof paren2,
|
||||
offs, typeof offs, str, typeof str, ""].join("|");
|
||||
};
|
||||
|
||||
reportCompare(
|
||||
"x|y|string|y|string||undefined|1|number|xyz|string|z",
|
||||
"xyz".replace(/(y)(\1)?/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x|yy|string|y|string|y|string|1|number|xyyz|string|z",
|
||||
"xyyz".replace(/(y)(\1)?/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x|y|string|y|string||undefined|1|number|xyyz|string|" +
|
||||
"|y|string|y|string||undefined|2|number|xyyz|string|z",
|
||||
"xyyz".replace(/(y)(\1)??/g, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"x|y|string|y|string|y|string|1|number|xyz|string|z",
|
||||
"xyz".replace(/(?=(y))(\1)?/, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"xyy|z|string||undefined||string|3|number|xyyz|string|",
|
||||
"xyyz".replace(/(?!(y)y)(\1)z/, f)
|
||||
);
|
||||
|
||||
rex = RegExp(
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()" +
|
||||
"()()()()()()()()()()(z)?(y)");
|
||||
a = ["sub"];
|
||||
for (i = 1; i <= 102; ++i)
|
||||
a[i] = "p" + i;
|
||||
a[103] = "offs";
|
||||
a[104] = "str";
|
||||
a[105] = "return ['', sub, typeof sub, offs, typeof offs, str, typeof str, " +
|
||||
"p100, typeof p100, p101, typeof p101, p102, typeof p102, ''].join('|');";
|
||||
f = Function.apply(null, a);
|
||||
reportCompare(
|
||||
"x|y|string|1|number|xyz|string||string||undefined|y|string|z",
|
||||
"xyz".replace(rex, f)
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"undefined",
|
||||
"".replace(/.*/g, function () {})
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"nullxnullynullznull",
|
||||
"xyz".replace(/.??/g, function () { return null; })
|
||||
);
|
||||
|
||||
reportCompare(
|
||||
"111",
|
||||
"xyz".replace(/./g, function () { return 1; })
|
||||
);
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function assertToString(actual, expected) {
|
||||
assert(actual.toString() == expected.toString());
|
||||
}
|
||||
|
||||
var arr1 = [1,2,3];
|
||||
var arr2 = ['a', 'b', 'c'];
|
||||
|
||||
var obj = {
|
||||
length: 3,
|
||||
0: 'd',
|
||||
1: 'e',
|
||||
2: 'f'
|
||||
};
|
||||
|
||||
// The Symbol.isConcatSpreadable property should be undefined by default.
|
||||
assert(arr1[Symbol.isConcatSpreadable] === undefined);
|
||||
assert(arr2[Symbol.isConcatSpreadable] === undefined);
|
||||
|
||||
// If the property is undefined, it should be handled as true in case of Array objects,
|
||||
// false in case of array-like objects.
|
||||
var arr_concat1 = arr1.concat(arr2);
|
||||
assertToString(arr_concat1, [1, 2, 3, 'a', 'b', 'c']);
|
||||
|
||||
var obj_concat1 = arr1.concat(obj);
|
||||
assertToString(obj_concat1, [1, 2, 3, obj]);
|
||||
|
||||
// If Symbol.isConcatSpreadable is set to true in an object, that object should be spread out.
|
||||
arr1[Symbol.isConcatSpreadable] = true;
|
||||
|
||||
var arr_concat2 = arr1.concat(arr2);
|
||||
assertToString(arr_concat2, [1, 2, 3, 'a', 'b', 'c']);
|
||||
|
||||
obj[Symbol.isConcatSpreadable] = true;
|
||||
var obj_concat2 = arr1.concat(obj);
|
||||
assertToString(obj_concat2, [1, 2, 3, 'd', 'e', 'f']);
|
||||
|
||||
// If Symbol.isConcatSpreadable is set to false in an object, that object should not be spread out.
|
||||
arr1[Symbol.isConcatSpreadable] = false;
|
||||
|
||||
var arr_concat3 = arr1.concat(arr2);
|
||||
assertToString(arr_concat3, [[1, 2, 3], 'a', 'b', 'c']);
|
||||
|
||||
arr1[Symbol.isConcatSpreadable] = true;
|
||||
arr2[Symbol.isConcatSpreadable] = false;
|
||||
|
||||
var arr_concat4 = arr1.concat(arr2);
|
||||
assertToString(arr_concat4, [1, 2, 3, ['a', 'b', 'c']]);
|
||||
|
||||
obj[Symbol.isConcatSpreadable] = false;
|
||||
var obj_concat3 = arr1.concat(obj);
|
||||
assertToString(obj_concat3, [1, 2, 3, {length: 3, 0: 'd', 1: 'e', 2: 'f'}]);
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function assertEquals(expectedResult, value)
|
||||
{
|
||||
assert(expectedResult == value);
|
||||
}
|
||||
|
||||
|
||||
// Test Regexp.prototype.exec
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
r.exec("zzzz");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test Regexp.prototype.test
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
r.test("zzzz");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test String.prototype.match
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
"zzzz".match(r);
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test String.prototype.replace with atomic regexp and empty string.
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
"zzzz".replace(r, "");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test String.prototype.replace with non-atomic regexp and empty string.
|
||||
r = /\d/;
|
||||
r.lastIndex = 1;
|
||||
"zzzz".replace(r, "");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test String.prototype.replace with atomic regexp and non-empty string.
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
"zzzz".replace(r, "a");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test String.prototype.replace with non-atomic regexp and non-empty string.
|
||||
r = /\d/;
|
||||
r.lastIndex = 1;
|
||||
"zzzz".replace(r, "a");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Test String.prototype.replace with replacement function
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
"zzzz".replace(r, function() { return ""; });
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
// Regexp functions that returns multiple results:
|
||||
// A global regexp always resets lastIndex regardless of whether it matches.
|
||||
r = /a/g;
|
||||
r.lastIndex = -1;
|
||||
"0123abcd".replace(r, "x");
|
||||
assertEquals(0, r.lastIndex);
|
||||
|
||||
r.lastIndex = -1;
|
||||
"01234567".replace(r, "x");
|
||||
assertEquals(0, r.lastIndex);
|
||||
|
||||
r.lastIndex = -1;
|
||||
"0123abcd".match(r);
|
||||
assertEquals(0, r.lastIndex);
|
||||
|
||||
r.lastIndex = -1;
|
||||
"01234567".match(r);
|
||||
assertEquals(0, r.lastIndex);
|
||||
|
||||
// A non-global regexp resets lastIndex iff it does not match.
|
||||
r = /a/;
|
||||
r.lastIndex = -1;
|
||||
"0123abcd".replace(r, "x");
|
||||
assertEquals(-1, r.lastIndex);
|
||||
|
||||
r.lastIndex = -1;
|
||||
"01234567".replace(r, "x");
|
||||
assertEquals(-1, r.lastIndex);
|
||||
|
||||
r.lastIndex = -1;
|
||||
"0123abcd".match(r);
|
||||
assertEquals(-1, r.lastIndex);
|
||||
|
||||
r.lastIndex = -1;
|
||||
"01234567".match(r);
|
||||
assertEquals(-1, r.lastIndex);
|
||||
|
||||
// Also test RegExp.prototype.exec and RegExp.prototype.test
|
||||
r = /a/g;
|
||||
r.lastIndex = 1;
|
||||
r.exec("01234567");
|
||||
assertEquals(0, r.lastIndex);
|
||||
|
||||
r.lastIndex = 1;
|
||||
r.exec("0123abcd");
|
||||
assertEquals(5, r.lastIndex);
|
||||
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
r.exec("01234567");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
r.lastIndex = 1;
|
||||
r.exec("0123abcd");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
r = /a/g;
|
||||
r.lastIndex = 1;
|
||||
r.test("01234567");
|
||||
assertEquals(0, r.lastIndex);
|
||||
|
||||
r.lastIndex = 1;
|
||||
r.test("0123abcd");
|
||||
assertEquals(5, r.lastIndex);
|
||||
|
||||
r = /a/;
|
||||
r.lastIndex = 1;
|
||||
r.test("01234567");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
||||
r.lastIndex = 1;
|
||||
r.test("0123abcd");
|
||||
assertEquals(1, r.lastIndex);
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
function Replace(find, newString) {
|
||||
this.find = find;
|
||||
this.newString = newString;
|
||||
}
|
||||
|
||||
Replace.prototype[Symbol.replace] = function(string) {
|
||||
return string.replace(this.find, this.newString);
|
||||
}
|
||||
function assertEquals(string, expectedResult)
|
||||
{
|
||||
assert(string == expectedResult)
|
||||
}
|
||||
|
||||
|
||||
|
||||
var string = 'foobar';
|
||||
assertEquals(string.replace(new Replace('foo', 'bar')) , 'barbar')
|
||||
assertEquals(string.replace(new Replace('foobar', 'barfoo')) , 'barfoo')
|
||||
assertEquals(string.replace(new Replace('', 'bar')) , 'barfoobar')
|
||||
|
||||
string = '';
|
||||
assertEquals(string.replace(new Replace('foo', 'bar')) , '')
|
||||
assertEquals(string.replace(new Replace('', 'bar')) , 'bar')
|
||||
|
||||
var re = /-/g
|
||||
string = '2018-01-01'
|
||||
var replace = '.'
|
||||
var newStr = re[Symbol.replace](string,replace)
|
||||
assertEquals(newStr , '2018.01.01')
|
||||
|
||||
re = /apples/gi
|
||||
string = 'Apples and apples'
|
||||
replace = 'orange'
|
||||
newStr = re[Symbol.replace](string,replace)
|
||||
assertEquals(newStr , 'orange and orange')
|
||||
|
||||
re = /(\w+)\s(\w+)/
|
||||
string = 'John Smith'
|
||||
replace = '$2, $1'
|
||||
newStr = re[Symbol.replace](string,replace)
|
||||
assertEquals(newStr , 'Smith, John')
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function Search(value) {
|
||||
this.value = value;
|
||||
}
|
||||
Search.prototype[Symbol.search]= function(string) {
|
||||
return string.indexOf(this.value);
|
||||
//return string.;
|
||||
}
|
||||
|
||||
|
||||
function assertPositionSymbol(string,find, expected) {
|
||||
assert(string.search(new Search(find)) == expected);
|
||||
}
|
||||
|
||||
function assertPosition(string,find, expected) {
|
||||
assert(string.search(find) == expected);
|
||||
}
|
||||
|
||||
var string = 'foobar';
|
||||
|
||||
assertPositionSymbol(string,'f',0);
|
||||
assertPositionSymbol(string,'o',1);
|
||||
assertPositionSymbol(string,'b',3);
|
||||
assertPositionSymbol(string,'a',4);
|
||||
assertPositionSymbol(string,'r',5);
|
||||
assertPositionSymbol(string,'z',-1);
|
||||
|
||||
assertPosition(string,'f',0);
|
||||
assertPosition(string,'o',1);
|
||||
assertPosition(string,'b',3);
|
||||
assertPosition(string,'a',4);
|
||||
assertPosition(string,'r',5);
|
||||
assertPosition(string,'z',-1);
|
||||
|
||||
var string2 = ''
|
||||
|
||||
assertPositionSymbol(string2,'',0)
|
||||
assertPositionSymbol(string2,'a',-1)
|
||||
|
||||
assertPosition(string2,'',0)
|
||||
assertPosition(string2,'a',-1)
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function checkNativeGetter(builtin) {
|
||||
assert(builtin[Symbol.species] === builtin);
|
||||
}
|
||||
|
||||
// Check the property [Symbol.species] in builtin constructors.
|
||||
checkNativeGetter(RegExp);
|
||||
checkNativeGetter(Array);
|
||||
checkNativeGetter(Map);
|
||||
checkNativeGetter(Set);
|
||||
checkNativeGetter(ArrayBuffer);
|
||||
checkNativeGetter(Promise);
|
||||
|
||||
checkNativeGetter(Int8Array);
|
||||
checkNativeGetter(Int16Array);
|
||||
checkNativeGetter(Int32Array);
|
||||
checkNativeGetter(Uint8Array);
|
||||
checkNativeGetter(Uint8ClampedArray);
|
||||
checkNativeGetter(Uint16Array);
|
||||
checkNativeGetter(Uint32Array);
|
||||
checkNativeGetter(Float32Array);
|
||||
checkNativeGetter(Float64Array);
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
assert(RegExp.prototype.hasOwnProperty(Symbol.split));
|
||||
assert(RegExp.prototype[Symbol.split] instanceof Function);
|
||||
assert(RegExp.prototype[Symbol.split].name == "[Symbol.split]");
|
||||
|
||||
function assertEquals(a, b) {
|
||||
assert(JSON.stringify(a) == JSON.stringify(b));
|
||||
}
|
||||
|
||||
// some corner cases
|
||||
assertEquals("y".split(/(x)?\1y/), ["", undefined, ""]) ;
|
||||
assertEquals("y".split(/(x)?y/), ["", undefined, ""]);
|
||||
assertEquals("abc".split(/$/), ["abc"]);
|
||||
assertEquals("a1b2c3".split(/\d/), ["a", "b", "c", ""]);
|
||||
assertEquals("1a2b3c".split(/\d/), ["", "a", "b", "c"]);
|
||||
assertEquals("test".split(/(?:)/, -1), ["t", "e", "s", "t"]);
|
||||
|
||||
function SplitTest1(value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
SplitTest1.prototype[Symbol.split] = function(string) {
|
||||
var index = string.indexOf(this.value);
|
||||
return string.substr(0, index) + this.value + "/" + string.substr(index + this.value.length);
|
||||
}
|
||||
|
||||
var str = new String("foobar");
|
||||
assert(str.split(new SplitTest1("foo")) == "foo/bar");
|
||||
assert(str.split(new SplitTest1("o")) == "fo/obar");
|
||||
assert(str.split(new SplitTest1("foobar")) == "foobar/");
|
||||
assert(str.split(new SplitTest1("")) == "/foobar");
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/* 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 a = Symbol ('foo');
|
||||
var b = Symbol ('bar');
|
||||
|
||||
assert (a !== b);
|
||||
assert (a === a);
|
||||
assert (typeof a === 'symbol');
|
||||
assert (a.toString() == 'Symbol(foo)');
|
||||
assert (Object.prototype.toString.call (a) === "[object Symbol]");
|
||||
assert (JSON.stringify (a) === undefined);
|
||||
|
||||
var obj = { c : 10, d : 20};
|
||||
obj[a] = 'EnumerableSymbolProp';
|
||||
assert (obj[a] === 'EnumerableSymbolProp');
|
||||
|
||||
// Symbol properties are not listed via for in
|
||||
Object.defineProperty(obj, b, { value : 'NonEnumerableSymbolProp' });
|
||||
|
||||
var counter = 0;
|
||||
|
||||
for (var v in obj) {
|
||||
assert (v === 'c' || v === 'd');
|
||||
counter++;
|
||||
}
|
||||
|
||||
assert (counter === 2);
|
||||
|
||||
var keys = Object.keys (obj);
|
||||
assert (keys.length === 2);
|
||||
assert (keys[0] === 'c' || keys[0] === 'd');
|
||||
assert (keys[1] === 'd' || keys[1] === 'c');
|
||||
|
||||
var c = Symbol ('bar');
|
||||
var obj2 = {};
|
||||
obj2[b] = 'foo';
|
||||
obj2[c] = 'bar';
|
||||
|
||||
assert (obj2[b] == 'foo');
|
||||
assert (obj2[c] == 'bar');
|
||||
|
||||
try {
|
||||
new Date (Symbol ('2018-11-09'));
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
a + 'append_string';
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof TypeError);
|
||||
}
|
||||
|
||||
assert (Object (a) == a);
|
||||
assert (Object (a) !== a);
|
||||
|
||||
// Test built-in symbols
|
||||
// TODO enable the commented-out well-known symbols (after implementing them)
|
||||
var a = ['hasInstance',
|
||||
'isConcatSpreadable',
|
||||
'iterator',
|
||||
// 'match',
|
||||
'replace',
|
||||
'search',
|
||||
'species',
|
||||
'split',
|
||||
'toPrimitive',
|
||||
'toStringTag',
|
||||
/* 'unscopables' */];
|
||||
|
||||
a.forEach (function (e) {
|
||||
assert (Symbol[e].toString() === ('Symbol(Symbol.' + e +')'));
|
||||
assert (typeof Symbol[e] === 'symbol');
|
||||
});
|
||||
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, a, { 'get' : function () {throw new ReferenceError ('foo'); } });
|
||||
Object.defineProperty(obj, b, { value : 5 });
|
||||
assert (obj[b] === 5);
|
||||
|
||||
try {
|
||||
obj[a];
|
||||
assert (false);
|
||||
} catch (e) {
|
||||
assert (e instanceof ReferenceError);
|
||||
assert (e.message === 'foo');
|
||||
}
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, b);
|
||||
|
||||
assert (descriptor.configurable === false);
|
||||
assert (descriptor.enumerable === false);
|
||||
assert (descriptor.writable === false);
|
||||
assert (descriptor.value === 5);
|
||||
|
||||
var foo = Symbol ('foo');
|
||||
assert (foo[Symbol.toStringTag] === 'Symbol');
|
||||
|
||||
// Test same descriptions
|
||||
var symA = Symbol ('foobar');
|
||||
var symB = Symbol ('foobar');
|
||||
assert (symA !== symB);
|
||||
assert (symA != symB);
|
||||
|
||||
var obj = { foobar : 55 };
|
||||
obj[symA] = 77;
|
||||
assert (obj["foobar"] !== obj[symA]);
|
||||
assert (obj["foobar"] != obj[symA]);
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// pass if there is no compile error
|
||||
function fo() {
|
||||
try {} catch(e) {}
|
||||
var e;
|
||||
}
|
||||
|
||||
function foo() {
|
||||
try {
|
||||
} catch(e) {
|
||||
try {
|
||||
|
||||
} catch(e2) {
|
||||
var e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function F()
|
||||
{
|
||||
e = 100;
|
||||
assert(e == 100)
|
||||
try
|
||||
{
|
||||
throw 200;
|
||||
assert(false)
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
assert(e == 200)
|
||||
var e = 300;
|
||||
assert(e == 300)
|
||||
}
|
||||
|
||||
assert(e == 100)
|
||||
}
|
||||
|
||||
F()
|
||||
|
||||
function F2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw 200;
|
||||
assert(false)
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
var e;
|
||||
}
|
||||
|
||||
assert(e === undefined)
|
||||
}
|
||||
|
||||
F2()
|
||||
|
||||
try {
|
||||
eval("try {} catch(e) { function e() {} }")
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError)
|
||||
}
|
||||
|
||||
try {
|
||||
eval("try {} catch([e]) { var e }")
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError)
|
||||
}
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function assert(expression) {
|
||||
if (!expression) {
|
||||
throw new Error("Assertion failed");
|
||||
}
|
||||
}
|
||||
|
||||
function assertThrows(code) {
|
||||
try {
|
||||
if (typeof code === 'function') {
|
||||
code();
|
||||
} else {
|
||||
eval(code);
|
||||
}
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
throw new Error("Did not throw exception");
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// TODO add TCs in this file for the rest of the Collator features
|
||||
|
||||
var desc = Object.getOwnPropertyDescriptor(Intl.Collator.prototype, Symbol.toStringTag);
|
||||
assert(desc.value === "Object");
|
||||
assert(!desc.writable && !desc.enumerable && desc.configurable);
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 actual = Intl.getCanonicalLocales(["EN-us", "eN", "FR"])
|
||||
var expected = ["en-US", "en", "fr"];
|
||||
|
||||
assert(JSON.stringify(actual) == JSON.stringify(expected));
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function assert(expression) {
|
||||
if (!expression) {
|
||||
throw new Error("Assertion failed");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 2016 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.
|
||||
|
||||
var fake =
|
||||
{
|
||||
get source() {
|
||||
return {
|
||||
toString: function() {
|
||||
return "pattern";
|
||||
}
|
||||
};
|
||||
},
|
||||
get flags() {
|
||||
return {
|
||||
toString: function() {
|
||||
return "flags";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
assert("/pattern/flags" == RegExp.prototype.toString.call(fake));
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
|
||||
// Tests that lastIndex of a global RegExp is overwritten as per
|
||||
// ECMA-262 6.0 21.2.5.8 step 10.c.
|
||||
|
||||
var global = /./g;
|
||||
global.lastIndex = { valueOf: function() { assert(false); } };
|
||||
assert("X" === "x".replace(global, function(a) { return "X"; }));
|
||||
assert(0 === global.lastIndex);
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 2016 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.
|
||||
|
||||
var hello = function() {
|
||||
var a = "world"
|
||||
return `Hello ${a}`
|
||||
}
|
||||
assert(hello() === "Hello world");
|
||||
|
||||
hello = function() {
|
||||
var a = "world"
|
||||
var b = "universe"
|
||||
return `Hello ${a} and beautiful ${b} and thanks for the fish`
|
||||
}
|
||||
|
||||
assert(hello() === "Hello world and beautiful universe and thanks for the fish");
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 bDeletesC = {$ : $, get b() { delete this.$ }, c: $};
|
||||
var $ = Object.values(bDeletesC);
|
||||
|
||||
assert(JSON.stringify($) == '[null,null,null]');
|
||||
assert(JSON.stringify(Object.keys(bDeletesC)) == '["b","c"]');
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
var r = / /;
|
||||
|
||||
var properties = ['global', 'ignoreCase', 'multiline', 'source'];
|
||||
|
||||
properties.forEach(function(prop) {
|
||||
try {
|
||||
Object.defineProperty(r, prop, {value: true});
|
||||
assert(r[prop]);
|
||||
Object.defineProperty(r, prop, {value: false});
|
||||
assert(false);
|
||||
} catch(e) {
|
||||
assert(r[prop]);
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
});
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
f = Function("func`foo`");
|
||||
assert (f.toString().localeCompare("function anonymous() {\nfunc`foo`\n}") == 0);
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 arr = [ ];
|
||||
Array.prototype[Object.defineProperty(arr, 0, {get: function() { Object.defineProperty(Array.prototype, 0, {}); return 0}})] = 0;
|
||||
|
||||
assert(JSON.stringify(arr) == "[0]");
|
||||
assert(JSON.stringify(Array.prototype) == "[null]");
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 2016 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 collect(value) {
|
||||
var primitive = y(value)
|
||||
if (primitive) return
|
||||
var index = z(value)
|
||||
if (index !== -1) { return }
|
||||
else {
|
||||
x.push({ })
|
||||
index = x.length - 1
|
||||
x[ index ].fv = value
|
||||
}
|
||||
|
||||
var ps = Object.getOwnPropertyNames(value)
|
||||
for (var i = 0; i < ps.length; i++) {
|
||||
var p = ps[i]
|
||||
if (a(value, p)) {
|
||||
collect(value[p])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function y(value) {
|
||||
if (value === null)
|
||||
return "null"
|
||||
var vt = typeof value
|
||||
if (vt !== "function" && vt !== "object")
|
||||
return vt
|
||||
}
|
||||
|
||||
function a(value, field) {
|
||||
try {
|
||||
value[field]
|
||||
return true
|
||||
} catch ( $ ) { }
|
||||
}
|
||||
|
||||
function z(value) {
|
||||
for (var i = 0; i < x.length; i++) {
|
||||
if (value === x[ i ].fv)
|
||||
return i
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
var x = [ ];
|
||||
collect(this);
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
function foo(x, y, z) {
|
||||
return [this, arguments.length, x];
|
||||
}
|
||||
|
||||
var f = foo.bind(foo);
|
||||
arr = f(1, 2, 3);
|
||||
assert(foo === arr[0]);
|
||||
assert(3 === arr[1]);
|
||||
assert(1 === arr[2]);
|
||||
assert(3 === f.length);
|
||||
assert("function () { [native code] }" === f.toString());
|
||||
|
||||
function bar(x, y, z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
f = bar.bind(bar, 1);
|
||||
obj1 = new f();
|
||||
assert(obj1 instanceof bar);
|
||||
assert(obj1 instanceof f);
|
||||
|
||||
f = bar.bind(bar, 1).bind(bar, 2).bind(bar, 3);
|
||||
obj2 = new f();
|
||||
assert(1 === obj2.x);
|
||||
assert(2 === obj2.y);
|
||||
assert(3 === obj2.z);
|
||||
assert(obj2 instanceof bar);
|
||||
assert(obj2 instanceof f);
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
var a = Object.preventExtensions([1, , 3, , 4, 5]);
|
||||
try {
|
||||
a.copyWithin(2, 1, 4);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
})();
|
||||
|
||||
(function () {
|
||||
var a = Object.preventExtensions([1, , 3, , 4, 5]);
|
||||
a[1] = 1;
|
||||
a[2] = 2;
|
||||
assert(a[1] === undefined);
|
||||
assert(a[2] === 2);
|
||||
})();
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Test for issue code
|
||||
var test_array = new Int8Array(new Int16Array(777))
|
||||
assert(test_array.length == 777)
|
||||
|
||||
// Test for Values
|
||||
test_array = new Int8Array(new Int16Array([-1,16,32,64]))
|
||||
assert(test_array.toString() == "-1,16,32,64")
|
||||
test_array = new Int16Array(new Int8Array([-1,16,32,64]))
|
||||
assert(test_array.toString() == "-1,16,32,64")
|
||||
|
||||
// Overflow
|
||||
test_array = new Int8Array(new Int16Array([-1,16,32,64,128]))
|
||||
assert(test_array.toString() == "-1,16,32,64,-128")
|
||||
test_array = new Uint8Array(new Int16Array([-1,16,32,64,256]))
|
||||
assert(test_array.toString() == "255,16,32,64,0")
|
||||
|
||||
// Signed to Unsigned
|
||||
test_array = new Uint8Array(new Int16Array([-1,16,32,64]))
|
||||
assert(test_array.toString() == "255,16,32,64")
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 a = [ ]
|
||||
a.constructor = {
|
||||
[Symbol.species]: function (...args) {
|
||||
var p = new Proxy(Array(...args), { })
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
assert(JSON.stringify(a.concat()) == "{}")
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2019-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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 2016 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.
|
||||
|
||||
Intl.NumberFormat('en-u-foo-U-foo')
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
Object.prototype[1] = 0;
|
||||
Promise.race('multiline').catch(function(error) {
|
||||
assert(error instanceof TypeError);
|
||||
assert(error.message === 'Second argument is not an array');
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue