Remove ES_NEXT macro (#4915)

- remove all '#JERRY_ESNEXT' macro
- remove 5.1 build profile, update test runner accordingly (Note: all builtins are turn on by default)
- move tests from tests/jerry/esnext into tests/jerry, concatenate files with same names
- add skiplist to some snapshot tests that were supported only in 5.1
- fix doxygen issues that were hidden before (bc. of es.next macro)

Co-authored-by: Martin Negyokru negyokru@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam
2022-01-31 16:46:00 +01:00
committed by GitHub
parent 76403606d0
commit 4924f9fd31
973 changed files with 1902 additions and 8240 deletions
-111
View File
@@ -1,111 +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.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
function mustThrow(str) {
try {
eval(str);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
}
function assertArrayEqual(actual, expected) {
assert(actual.length === expected.length);
for (var i = 0; i < actual.length; i++) {
assert(actual[i] === expected[i]);
}
}
// Spread syntax
function sum(x, y, z) {
return x + y + z;
}
const numbers = [1, 2, 3];
assert(sum(...numbers) === 6);
// Replace apply()
function myFunction (v, w, x, y, z) {
return v + w + x + y + z;
}
var args = [0, 1];
assert(myFunction (-1, ...args, 2, ...[3]) == 5);
// Apply for new
var dateFields = [1970, 0, 1];
var d = new Date(...dateFields);
assert(d.toString().substring(0, 24) === "Thu Jan 01 1970 00:00:00");
function applyAndNew(constructor, args) {
function partial () {
return constructor.apply (this, args);
};
if (typeof constructor.prototype === "object") {
partial.prototype = Object.create(constructor.prototype);
}
return partial;
}
function myConstructor () {
assertArrayEqual(arguments, myArguments);
this.prop1 = "val1";
this.prop2 = "val2";
};
var myArguments = ["hi", "how", "are", "you", "mr", null];
var myConstructorWithArguments = applyAndNew(myConstructor, myArguments);
var obj = new myConstructorWithArguments;
assert(Object.keys(obj).length === 2);
assert(obj.prop1 === "val1");
assert(obj.prop2 === "val2");
// Test spread prop call
var o = { f(a,b,c) { return a + b + c },
g(a,b) { throw new TypeError ("5") }
};
assert (o.f(...["a", "b", "c"]) === "abc");
mustThrow ("o.g (...[1,2])")
// Test spread super call
class MyArray extends Array {
constructor(...args) {
super(...args);
}
}
var array = new MyArray(1, 2, 3);
assertArrayEqual(array, [1,2,3]);
assert(array instanceof MyArray);
assert(array instanceof Array);
function argumentOrderTest() {
var result = []
for (i = 0; i < arguments.length; i++) {
result.push(arguments[i]);
}
return result;
}
assertArrayEqual(argumentOrderTest(1, 2, ...[3, 4]), [1, 2, 3, 4]);
-50
View File
@@ -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.
var arrayPrototypeValues = Array.prototype.values;
function f_mapped() {
assert(typeof arguments[Symbol.iterator] === 'function');
assert(arguments[Symbol.iterator] === arrayPrototypeValues);
assert(Object.hasOwnProperty.call(arguments, Symbol.iterator));
let sum = 0;
for (a of arguments) {
sum += a;
}
return sum;
};
function f_unmapped(b = 2) {
assert(typeof arguments[Symbol.iterator] === 'function');
assert(arguments[Symbol.iterator] === arrayPrototypeValues);
assert(Object.hasOwnProperty.call(arguments, Symbol.iterator));
let sum = 0;
for (a of arguments) {
sum += a;
}
return sum;
};
assert(f_mapped(1, 2, 3, 4, 5) === 15);
assert(f_unmapped(1, 2, 3, 4, 5) === 15);
Object.defineProperty(Array.prototype, "values", { get : function () {
/* should not be executed */
assert(false);
}});
assert(f_mapped(1, 2, 3, 4, 5) === 15);
assert(f_unmapped(1, 2, 3, 4, 5) === 15);
-254
View File
@@ -1,254 +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 f1(a, b, c)
{
'use strict';
assert(!Object.hasOwnProperty(arguments,'caller'));
}
f1(1, 2, 3);
// Normal arguments access
function f2(a = arguments)
{
assert(arguments[1] === 2)
var arguments = 1
assert(arguments === 1)
assert(a[1] === 2)
}
f2(undefined, 2)
function f3(a = arguments)
{
assert(arguments() === "X")
function arguments() { return "X" }
assert(arguments() === "X")
assert(a[1] === "R")
}
f3(undefined, "R")
function f4(a = arguments)
{
const arguments = 3.25
assert(arguments === 3.25)
assert(a[1] === -1.5)
}
f4(undefined, -1.5)
// Normal arguments access with eval
function f5(a = arguments)
{
assert(arguments[1] === 2)
var arguments = 1
assert(arguments === 1)
assert(a[1] === 2)
eval()
}
f5(undefined, 2)
function f6(a = arguments)
{
assert(arguments() === "X")
function arguments() { return "X" }
assert(arguments() === "X")
assert(a[1] === "R")
eval()
}
f6(undefined, "R")
function f7(a = arguments)
{
const arguments = 3.25
assert(arguments === 3.25)
assert(a[1] === -1.5)
eval()
}
f7(undefined, -1.5)
// Argument access through a function
function f8(a = () => arguments)
{
assert(arguments[1] === 2)
var arguments = 1
assert(arguments === 1)
assert(a()[1] === 2)
}
f8(undefined, 2)
function f9(a = () => arguments)
{
assert(arguments() === "X")
function arguments() { return "X" }
assert(arguments() === "X")
assert(a()[1] === "R")
}
f9(undefined, "R")
function f10(a = () => arguments)
{
let arguments = 3.25
assert(arguments === 3.25)
assert(a()[1] === -1.5)
}
f10(undefined, -1.5)
// Argument access through an eval
function f11(a = eval("() => arguments"))
{
assert(arguments[1] === 2)
var arguments = 1
assert(arguments === 1)
assert(a()[1] === 2)
}
f11(undefined, 2)
function f12(a = eval("() => arguments"))
{
assert(arguments() === "X")
function arguments() { return "X" }
assert(arguments() === "X")
assert(a()[1] === "R")
}
f12(undefined, "R")
function f13(a = eval("() => arguments"))
{
const arguments = 3.25
assert(arguments === 3.25)
assert(a()[1] === -1.5)
}
f13(undefined, -1.5)
// Other cases
try {
function f14(a = arguments)
{
assert(a[1] === 6)
arguments;
let arguments = 1;
}
f14(undefined, 6)
assert(false)
} catch (e) {
assert(e instanceof ReferenceError)
}
try {
eval("'use strict'; function f(a = arguments) { arguments = 5; eval() }");
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
function f15()
{
assert(arguments[0] === "A")
var arguments = 1
assert(arguments === 1)
}
f15("A")
function f16()
{
assert(arguments() === "W")
function arguments() { return "W" }
assert(arguments() === "W")
}
f16("A")
function f17(a = arguments = "Val")
{
assert(arguments === "Val")
}
f17();
function f18(s = (v) => arguments = v, g = () => arguments)
{
const arguments = -3.25
s("X")
assert(g() === "X")
assert(arguments === -3.25)
}
f18()
function f19(e = (v) => eval(v))
{
var arguments = -12.5
e("arguments[0] = 4.5")
assert(e("arguments[0]") === 4.5)
assert(e("arguments[1]") === "A")
assert(arguments === -12.5)
}
f19(undefined, "A");
function f20 (arguments, a = eval('arguments')) {
assert(a === 3.1);
assert(arguments === 3.1);
}
f20(3.1);
function f21 (arguments, a = arguments) {
assert(a === 3.1);
assert(arguments === 3.1);
}
f21(3.1);
function f22 (arguments, [a = arguments]) {
assert(a === 3.1);
assert(arguments === 3.1);
}
f22(3.1, []);
try {
function f23(p = eval("var arguments"), arguments)
{
}
f23()
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
try {
function f24(p = eval("var arguments")) {
let arguments;
}
f24()
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
try {
function f25(p = eval("var arguments")) {
function arguments() { }
}
f25()
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
function f26(arguments, eval = () => eval()) {
assert(arguments === undefined);
}
f26(undefined);
-92
View File
@@ -1,92 +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 check_syntax_error (txt) {
try {
eval (txt)
assert (false)
} catch (e) {
assert (e instanceof SyntaxError)
}
}
var a = 21;
var b = 10;
var c;
check_syntax_error ("c = a++b");
check_syntax_error ("c = a--b");
check_syntax_error ("c = a +* b");
check_syntax_error ("c = a -* b");
check_syntax_error ("c = a +/ b");
check_syntax_error ("c = a -/ b");
check_syntax_error ("c = a +% b");
check_syntax_error ("c = a -% b");
check_syntax_error ("a =* b");
check_syntax_error ("a =/ b");
check_syntax_error ("a =% b");
check_syntax_error ("c = a+");
check_syntax_error ("c = a-");
check_syntax_error("a++\n()");
check_syntax_error("a--\n.b");
assert((-2 .toString()) === -2);
Number.prototype[0] = 123;
assert(-2[0] === -123);
function f() {
var a = 0;
function g() {}
try {
eval ("g(this, 'a' = 1)");
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
try {
eval ("g(this, 'a' += 1)");
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
assert (a === 0);
}
f();
function g(a, b)
{
assert(b === "undefined");
}
g(this, typeof undeclared_var)
function h()
{
var done = false;
var o = { a: function () { done = (this === o) } }
function f() {}
with (o) {
f(this, a());
}
assert(done);
}
h();
-55
View File
@@ -1,55 +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 = 21;
var b = 10;
var c;
c = a + b;
assert(c == 31);
c = a - b;
assert(c == 11);
c = a * b;
assert(c == 210);
c = a / b;
assert(c >= 2.1 - 0.000001 && c <= 2.1 + 0.000001);
c = a % b;
assert(c == 1);
c = a++;
assert(c == 21);
c = a--;
assert(c == 22);
var o = { p : 1 };
assert (++o.p === 2);
assert (o.p === 2);
assert (--o.p === 1);
assert (o.p === 1);
try {
eval ('++ ++ a');
assert (false);
}
catch (e) {
assert (e instanceof SyntaxError);
}
assert (0.1 + 0.2 != 0.3);
-37
View File
@@ -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.
var o1 = { valueOf() { return Symbol() } }
var o2 = { valueOf() { throw "Should not reach here" } }
function check_type_error(code) {
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
}
check_type_error("o1 - o2")
check_type_error("o1 * o2")
check_type_error("o1 / o2")
check_type_error("o1 % o2")
check_type_error("o1 ** o2")
check_type_error("o1 | o2")
check_type_error("o1 & o2")
check_type_error("o1 ^ o2")
check_type_error("o1 << o2")
check_type_error("o1 >> o2")
check_type_error("o1 >>> o2")
-344
View File
@@ -1,344 +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.
// 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.
// Some methods are taken from v8/test/mjsunit/mjsunit.js
function classOf(object) {
// Argument must not be null or undefined.
var string = Object.prototype.toString.call(object);
// String has format [object <ClassName>].
return string.substring(8, string.length - 1);
}
/**
* Compares two objects for key/value equality.
* Returns true if they are equal, false otherwise.
*/
function deepObjectEquals(a, b) {
var aProps = Object.keys(a);
aProps.sort();
var bProps = Object.keys(b);
bProps.sort();
if (!deepEquals(aProps, bProps)) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
return false;
}
}
return true;
}
var assertInstanceof = function assertInstanceof(obj, type) {
if (!(obj instanceof type)) {
var actualTypeName = null;
var actualConstructor = Object.getPrototypeOf(obj).constructor;
if (typeof actualConstructor == "function") {
actualTypeName = actualConstructor.name || String(actualConstructor);
} print("Object <" + obj + "> is not an instance of <" + (type.name || type) + ">" + (actualTypeName ? " but of < " + actualTypeName + ">" : ""));
}
};
function deepEquals(a, b) {
if (a === b) {
if (a === 0) return (1 / a) === (1 / b);
return true;
}
if (typeof a != typeof b) return false;
if (typeof a == "number") return isNaN(a) && isNaN(b);
if (typeof a !== "object" && typeof a !== "function") return false;
var objectClass = classOf(a);
if (objectClass !== classOf(b)) return false;
if (objectClass === "RegExp") {
return (a.toString() === b.toString());
}
if (objectClass === "Function") return false;
if (objectClass === "Array") {
var elementCount = 0;
if (a.length != b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!deepEquals(a[i], b[i]))
return false;
}
return true;
}
if (objectClass == "String" || objectClass == "Number" || objectClass == "Boolean" || objectClass == "Date") {
if (a.valueOf() !== b.valueOf()) return false;
}
return deepObjectEquals(a, b);
}
var assertEquals = function assertEquals(expected, found, name_opt) {
if (!deepEquals(found, expected)) {
assert(false);
}
};
function assertArrayLikeEquals(value, expected, type) {
assertInstanceof(value, type);
assert(expected.length === value.length);
for (var i=0; i<value.length; ++i) {
assertEquals(expected[i], value[i]);
}
}
assert(1 === Array.from.length);
// Assert that constructor is called with "length" for array-like objects
var myCollectionCalled = false;
function MyCollection(length) {
myCollectionCalled = true;
assert(1 === arguments.length);
assert(5 === length);
}
Array.from.call(MyCollection, {length: 5});
assert(myCollectionCalled === true);
// Assert that calling mapfn with / without thisArg in sloppy and strict modes
// works as expected.
var global = this;
function non_strict(){ assert(global === this); }
function strict(){ "use strict"; assert(void 0 === this); }
function strict_null(){ "use strict"; assert(null === this); }
Array.from([1], non_strict);
Array.from([1], non_strict, void 0);
Array.from([1], strict);
Array.from([1], strict, void 0);
function testArrayFrom(thisArg, constructor) {
assertArrayLikeEquals(Array.from.call(thisArg, [], undefined), [], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, NaN), [], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, Infinity), [], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, 10000000), [], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, 'test'), ['t', 'e', 's', 't'], constructor);
assertArrayLikeEquals(Array.from.call(thisArg,
{ length: 1, '0': { 'foo': 'bar' } }), [{'foo': 'bar'}], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, { length: -1, '0': { 'foo': 'bar' } }), [], constructor);
assertArrayLikeEquals(Array.from.call(thisArg,
[ 'foo', 'bar', 'baz' ]), ['foo', 'bar', 'baz'], constructor);
var kSet = new Set(['foo', 'bar', 'baz']);
assertArrayLikeEquals(Array.from.call(thisArg, kSet), ['foo', 'bar', 'baz'], constructor);
var kMap = new Map(['foo', 'bar', 'baz'].entries());
assertArrayLikeEquals(Array.from.call(thisArg, kMap), [[0, 'foo'], [1, 'bar'], [2, 'baz']], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, 'test', function(x) {
return this.filter(x);
}, {
filter: function(x) { return x.toUpperCase(); }
}), ['T', 'E', 'S', 'T'], constructor);
assertArrayLikeEquals(Array.from.call(thisArg, 'test', function(x) {
return x.toUpperCase();
}), ['T', 'E', 'S', 'T'], constructor);
try {
Array.from.call(thisArg, null);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
Array.from.call(thisArg, undefined);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
Array.from.call(thisArg, [], null);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
Array.from.call(thisArg, [], "noncallable");
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
var nullIterator = {};
nullIterator[Symbol.iterator] = null;
assertArrayLikeEquals(Array.from.call(thisArg, nullIterator), [],
constructor);
var nonObjIterator = {};
nonObjIterator[Symbol.iterator] = function() { return "nonObject"; };
try {
Array.from.call(thisArg, nonObjIterator);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
Array.from.call(thisArg, [], null);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
// Ensure iterator is only accessed once, and only invoked once
var called = false;
var arr = [1, 2, 3];
var obj = {};
// Test order --- only get iterator method once
function testIterator() {
assert(called !== "@@iterator should be called only once");
called = true;
assert(obj === this);
return arr[Symbol.iterator]();
}
var getCalled = false;
Object.defineProperty(obj, Symbol.iterator, {
get: function() {
assert(getCalled !== "@@iterator should be accessed only once");
getCalled = true;
return testIterator;
},
set: function() {
// "@@iterator should not be set"
assert(false);
}
});
assertArrayLikeEquals(Array.from.call(thisArg, obj), [1, 2, 3], constructor);
}
function Other() {}
var boundFn = (function() {}).bind(Array, 27);
testArrayFrom(Array, Array);
testArrayFrom(null, Array);
testArrayFrom({}, Array);
testArrayFrom(Object, Object);
testArrayFrom(Other, Other);
testArrayFrom(Math.cos, Array);
testArrayFrom(boundFn, boundFn);
// Assert that [[DefineOwnProperty]] is used in ArrayFrom, meaning a
// setter isn't called, and a failed [[DefineOwnProperty]] will throw.
var setterCalled = 0;
function exotic() {
Object.defineProperty(this, '0', {
get: function() { return 2; },
set: function() { setterCalled++; }
});
}
// Non-configurable properties can't be overwritten with DefineOwnProperty
// The setter wasn't called
try {
Array.from.call(exotic, [1]);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
assert( 0 === setterCalled);
// Non-callable iterators should cause a TypeError before calling the target
// constructor.
items = {};
items[Symbol.iterator] = 7;
function TestError() {}
function ArrayLike() { throw new TestError() }
try {
Array.from.call(ArrayLike, items);
assert(false);
} catch (e) {
assert (e instanceof TypeError);
}
// Check that array properties defined are writable, enumerable, configurable
function ordinary() { }
var x = Array.from.call(ordinary, [2]);
var xlength = Object.getOwnPropertyDescriptor(x, 'length');
assert(1 === xlength.value);
assert(true === xlength.writable);
assert(true === xlength.enumerable);
assert(true === xlength.configurable);
var x0 = Object.getOwnPropertyDescriptor(x, 0);
assert(2 === x0.value);
assert(true === xlength.writable);
assert(true === xlength.enumerable);
assert(true === xlength.configurable);
/* Test iterator close */
function __createIterableObject (arr, methods) {
methods = methods || {};
if (typeof Symbol !== 'function' || !Symbol.iterator) {
return {};
}
arr.length++;
var iterator = {
next: function() {
return { value: arr.shift(), done: arr.length <= 0 };
},
'return': methods['return'],
'throw': methods['throw']
};
var iterable = {};
iterable[Symbol.iterator] = function () { return iterator; };
return iterable;
};
function close1() {
var closed = false;
var iter = __createIterableObject([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
try {
Array.from(iter, x => { throw 5 });
assert(false);
} catch (e) {
assert(e === 5);
}
return closed;
}
assert(close1());
function close2() {
var closed = false;
var iter = __createIterableObject([1, 2, 3], {
'return': function() { closed = true; throw 6 }
});
try {
Array.from(iter, x => { throw 5 });
assert(false);
} catch (e) {
assert(e === 5);
}
return closed;
}
assert(close2());
-48
View File
@@ -1,48 +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.
assert(Array.isArray([]) === true);
assert(Array.isArray([1]) === true);
assert(Array.isArray(new Array()) === true);
assert(Array.isArray(new Array('a', 'b', 'c', 'd')) === true);
assert(Array.isArray(new Array(3)) === true);
assert(Array.isArray(Array.prototype) === true);
assert(Array.isArray(new Proxy([], {})) === true);
assert(Array.isArray() === false);
assert(Array.isArray({}) === false);
assert(Array.isArray(null) === false);
assert(Array.isArray(undefined) === false);
assert(Array.isArray(17) === false);
assert(Array.isArray('Array') === false);
assert(Array.isArray(true) === false);
assert(Array.isArray(false) === false);
assert(Array.isArray(new Uint8Array(32)) === false);
assert(Array.isArray({ __proto__: Array.prototype }) === false);
var revocable = Proxy.revocable ({}, {});
var proxy = revocable.proxy;
revocable.revoke();
try {
Array.isArray(proxy);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
var revocable = Proxy.revocable ([], {});
var proxy = revocable.proxy;
assert(Array.isArray(proxy) === true);
@@ -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.
function F (){}
var obj = Reflect.construct (Array, [], F);
obj[2] = 'foo';
assert (obj.length === 3 && obj instanceof F);
try {
Reflect.construct (Array, [-1], F);
} catch (e) {
assert (e instanceof RangeError);
}
var o = new Proxy (function f () {}, { get (t,p,r) { if (p == "prototype") { throw "Kitten" } Reflect.get (...arguments) }})
try {
Reflect.construct (Array, [], o)
} catch (e) {
assert (e === "Kitten");
}
-78
View File
@@ -1,78 +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.
// Test with regular inputs
var array1 = Array.of(1, 2, 3, 4, 5);
assert(array1.length === 5);
assert(array1[2] === 3);
// Test with no input
var array2 = Array.of();
assert(array2.length === 0);
assert(array2[0] === undefined);
// Test when an input is another array
var array3 = Array.of(array1, 6, 7);
assert(array3.length === 3);
assert(array3[0] instanceof Array);
assert(array3[0][3] === 4);
assert(array3[2] === 7);
// Test with undefined
var array4 = Array.of(undefined);
assert(array4.length === 1);
assert(array4[0] === undefined);
// Test when input is an object
var obj = {
0: 0,
1: 1
};
var array5 = Array.of(obj, 2, 3);
assert(array5[0] instanceof Object);
assert(array5[0][0] === 0);
assert(array5[0][1] === 1);
assert(array5[2] === 3);
// Test with array holes
var array6 = Array.of.apply(null, [,,undefined]);
assert(array6.length === 3);
assert(array6[0] === undefined);
// Test with another class
var hits = 0;
function Test() {
hits++;
}
Test.of = Array.of;
hits = 0;
var array6 = Test.of(1, 2);
assert(hits === 1);
assert(array6.length === 2);
assert(array6[1] === 2);
// Test with bounded builtin function
var boundedBuiltinFn = Array.of.bind(Array);
var array7 = Array.of.call(boundedBuiltinFn, boundedBuiltinFn);
assert(array7.length === 1);
assert(array7[0] === boundedBuiltinFn);
// Test superficial features
var desc = Object.getOwnPropertyDescriptor(Array, "of");
assert(desc.configurable === true);
assert(desc.writable === true);
assert(desc.enumerable === false);
assert(Array.of.length === 0);
-372
View File
@@ -1,372 +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 checkSyntax (str) {
try {
eval (str);
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
}
function assertArrayEqual (actual, expected) {
assert (actual.length === expected.length);
for (var i = 0; i < actual.length; i++) {
assert (actual[i] === expected[i]);
}
}
function mustThrow (str) {
try {
eval (str);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
}
function mustNotThrow (str) {
try {
eval (str);
} catch (e) {
assert (false);
}
}
checkSyntax ("var [a]");
checkSyntax ("var [a, o.a]");
checkSyntax ("var [a, ...b,]");
checkSyntax ("var [a, ...b = 4]");
checkSyntax ("var [a, ...[b] = 4]");
checkSyntax ("var [let]");
checkSyntax ("var [get = []");
checkSyntax ("var [get : 5]");
checkSyntax ("var [[a = {},]");
checkSyntax ("let [a,a] = []");
checkSyntax ("let [a, ...a] = []");
checkSyntax ("const [a,a] = []");
checkSyntax ("const [a, ...a] = []");
checkSyntax ("[new Object()] = []");
checkSyntax ("[Object()] = []");
checkSyntax ("[(a, b, d, c)] = []");
checkSyntax ("[super] = []");
checkSyntax ("[this] = []");
checkSyntax ("[()] = []");
checkSyntax ("try { let [$] = $;");
checkSyntax ("let a, [ b.c ] = [6];");
checkSyntax ("let [(a)] = [1]");
checkSyntax ("[...a = []] = [1]");
checkSyntax ("[...[a] = []] = [1]");
checkSyntax ("[...[a, [...b] = []] = []] = [1]");
mustThrow ("var [a] = 4");
mustThrow ("var [a] = 5");
mustThrow ("var [a] = {}");
mustThrow ("var [a] = { get [Symbol.iterator] () { throw new TypeError } }");
mustThrow ("var [a] = { [Symbol.iterator] () {} }");
mustThrow ("var [a] = { [Symbol.iterator] () { return {} } }");
mustThrow ("var [a] = { [Symbol.iterator] () { return { next: 5 } } }");
mustThrow ("var [a] = { [Symbol.iterator] () { return { next: 5 } } }");
mustThrow ("var [a] = { [Symbol.iterator] () { return { get next() { throw new TypeError } } } }");
mustThrow ("var [a] = { [Symbol.iterator] () { return { next () { } } } }");
mustThrow ("var [a] = { [Symbol.iterator] () { return { next () { } } } }");
mustThrow ("var [a] = { [Symbol.iterator] () { return { next () { return { get value () { throw new TypeError }}}}}}");
mustThrow ("var [a] = { [Symbol.iterator] () { return { next () { return { get done () { throw new TypeError }}}}}}");
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
// Basic variable assignment
(function () {
var foo = ["one", "two", "three"];
var [red, yellow, green] = foo;
assert (red === "one");
assert (yellow === "two");
assert (green === "three");
}) ();
// Assignment separate from declaration
(function () {
var a, b;
[a, b] = [1, 2];
assert (a === 1);
assert (b === 2);
}) ();
// Default values
(function () {
var a, b;
[a = 5, b = 7] = [1];
assert (a === 1);
assert (b === 7);
}) ();
// Swapping variables
(function () {
var a = 1;
var b = 3;
[a, b] = [b, a];
assert (a === 3);
assert (b === 1);
var arr = [1,2,3];
[arr[2], arr[1]] = [arr[1], arr[2]];
assertArrayEqual (arr, [1, 3, 2]);
}) ();
// Parsing an array returned from a function
(function () {
function f() {
return [1, 2];
}
var a, b;
[a, b] = f();
assert (a === 1);
assert (b === 2);
}) ();
// Ignoring some returned values
(function () {
function f() {
return [1, 2, 3];
}
var a, b;
[a, ,b] = f();
assert (a === 1);
assert (b === 3);
}) ();
// Ignoring some returned values
(function () {
var [a, ...b] = [1, 2, 3];
assert (a === 1);
assertArrayEqual (b, [2, 3]);
}) ();
// Unpacking values from a regular expression match
(function () {
function parseProtocol(url) {
var parsedURL = /^(\w+)\:\/\/([^\/]+)\/(.*)$/.exec(url);
if (!parsedURL) {
return false;
}
var [, protocol, fullhost, fullpath] = parsedURL;
return protocol;
}
assert (parseProtocol("https://developer.mozilla.org/en-US/Web/JavaScript") === "https");
}) ();
// Test inner patterns I.
(function () {
let [a, [b, [c = 4, d = 5]], [e] = [6]] = [1, [2, [3,undefined]]];
assert (a === 1);
assert (b === 2);
assert (c === 3);
assert (d === 5);
assert (e === 6);
}) ();
// Test inner patterns II.
(function () {
var o = {};
[a, b, c, o.a = 4, o.b, o.c = 3] = ["1", "2", "3", undefined, "8", "6"];
assert (a === "1");
assert (b === "2");
assert (c === "3");
assert (o.a === 4);
assert (o.b === "8");
assert (o.c === "6");
}) ();
// Test rest element I.
(function () {
var o = {};
[...o.a] = ["1", "2", "3"];
assertArrayEqual (o.a, ["1", "2", "3"]);
}) ();
// Test rest element II.
(function () {
[...[a,b,c]] = ["1", "2", "3"];
assert (a === "1");
assert (b === "2");
assert (c === "3");
}) ();
// Test inner object pattern I.
(function () {
[{f : a, g : b}, , , ...[c, d, e]] = [{ f : "1", g : "2"}, 3, 4, 5, 6, 7];
assert (a === "1");
assert (b === "2");
assert (c === 5);
assert (d === 6);
assert (e === 7);
}) ();
// Multiple declaration
(function () {
var [a] = [1], [b] = [2];
assert (a === 1);
assert (b === 2);
}) ();
// Force the creation of lexical environment I.
(function () {
const [a] = [1];
eval();
assert (a === 1);
}) ();
// Force the creation of lexical environment II.
(function () {
let [a] = [1];
eval();
assert (a === 1);
}) ();
// Check the parsing of AssignmentElement
(function () {
var a = 6;
[((a))] = [7];
assert (a === 7);
}) ();
// Test iterator closing
function __createIterableObject (arr, methods) {
methods = methods || {};
if (typeof Symbol !== 'function' || !Symbol.iterator) {
return {};
}
arr.length++;
var iterator = {
next: function() {
return { value: arr.shift(), done: arr.length <= 0 };
},
'return': methods['return'],
'throw': methods['throw']
};
var iterable = {};
iterable[Symbol.iterator] = function () { return iterator; };
return iterable;
};
(function () {
var closed = false;
var iter = __createIterableObject([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
var [a, b] = iter;
assert (closed === true);
assert (a === 1);
assert (b === 2);
}) ();
(function () {
var value = { y: "42" };
var x = {};
var assignmentResult, iterationResult, iter;
iter = (function*() {
assignmentResult = { y: x[yield] } = value;
}());
iterationResult = iter.next();
assert (assignmentResult === undefined);
assert (iterationResult.value === undefined);
assert (iterationResult.done === false);
assert (x.prop === undefined);
iterationResult = iter.next('prop');
assert (assignmentResult === value);
assert (iterationResult.value === undefined);
assert (iterationResult.done === true);
assert (x.prop === "42");
}) ();
(function () {
var value = { foo: "42" };
var x = {};
var assignmentResult, iterationResult, iter;
iter = (function*() {
assignmentResult = { ['f' + 'o' + 'o']: x[yield] } = value;
}());
iterationResult = iter.next();
assert (assignmentResult === undefined);
assert (iterationResult.value === undefined);
assert (iterationResult.done === false);
assert (x.prop === undefined);
iterationResult = iter.next('prop');
assert (assignmentResult === value);
assert (iterationResult.value === undefined);
assert (iterationResult.done === true);
assert (x.prop === "42");
}) ();
mustThrow (`var iter = __createIterableObject([],
{ get 'return'() { throw new TypeError() }});
var [a] = iter`);
mustNotThrow (`var iter = __createIterableObject([],
{ 'return': 5 });
var [a] = iter`);
mustNotThrow (`var iter = __createIterableObject([],
{ 'return': function() { return 5; }});
var [a] = iter`);
mustThrow (`try { throw 5 } catch (e) {
var iter = __createIterableObject([],
{ get 'return'() { throw new TypeError() }});
var [a] = iter }`);
mustNotThrow (`try { throw 5 } catch (e) {
var iter = __createIterableObject([],
{ 'return': 5 });
var [a] = iter }`);
mustNotThrow (`try { throw 5 } catch (e) {
var iter = __createIterableObject([],
{ 'return': function() { return 5; }});
var [a] = iter }`);
try {
eval ("var a = 0; 1 + [a] = [1]");
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
-50
View File
@@ -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.
*/
var obj = {};
var array = ['Apple', 'Banana', "zero", 0, obj, 'Apple'];
var index = array.at(0);
assert(index === 'Apple');
assert(array[index] === undefined);
assert(array.at(array.length) === undefined);
assert(array.at(array.length+1) === undefined);
assert(array.at(array.length-1) === 'Apple');
assert(array.at("1") === 'Banana');
assert(array.at(-1) === 'Apple');
assert(array.at("-1") === 'Apple');
assert(array.at("-20") === undefined);
/* 7 */
var obj = {}
obj.length = 1;
Object.defineProperty(obj, '0', { 'get' : function () {throw new ReferenceError ("foo"); } });
obj.at = Array.prototype.at;
try {
obj.at(0);
assert(false);
} catch(e) {
assert(e.message === "foo");
assert(e instanceof ReferenceError);
}
try {
Array.prototype.at.call(undefined)
assert (false);
} catch(e) {
assert(e instanceof TypeError);
}
@@ -1,130 +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 obj = {};
// Checking behavior with normal inputs
var array = ["foo", 1, "bar", obj, 2, "baz"];
assert(array.copyWithin(2,0,6).toString() === "foo,1,foo,1,bar,[object Object]");
assert(array.copyWithin(0,1,3).toString() === "1,foo,foo,1,bar,[object Object]");
assert(array.copyWithin(3,0,4).toString() === "1,foo,foo,1,foo,foo");
// Checking behavior with default inputs
var array = ["foo", 1, "bar", obj, 2, "baz"];
assert(array.copyWithin().toString() === "foo,1,bar,[object Object],2,baz");
assert(array.copyWithin(2).toString() === "foo,1,foo,1,bar,[object Object]");
assert(array.copyWithin(1,4).toString() === "foo,bar,[object Object],1,bar,[object Object]");
// Checking behavior when argument is negative or bigger then length
var array = ["foo", 1, "bar", obj, 2, "baz"];
assert(array.copyWithin(12,3,-3).toString() === "foo,1,bar,[object Object],2,baz");
assert(array.copyWithin(-2,-4,3).toString() === "foo,1,bar,[object Object],bar,baz");
assert(array.copyWithin(1,-5,30).toString() === "foo,1,bar,[object Object],bar,baz");
// Checking behavior with undefined, NaN, +/- Infinity
var array = ["foo", 1, "bar", obj, 2, "baz"];
assert(array.copyWithin(undefined).toString() === "foo,1,bar,[object Object],2,baz");
assert(array.copyWithin(2, NaN).toString()=== "foo,1,foo,1,bar,[object Object]");
assert(array.copyWithin(2,undefined,5).toString() === "foo,1,foo,1,foo,1");
var array = ["foo", 1, "bar", obj, 2, "baz"];
assert(array.copyWithin(Infinity,2,NaN).toString() === "foo,1,bar,[object Object],2,baz");
assert(array.copyWithin(Infinity,-Infinity,4).toString()=== "foo,1,bar,[object Object],2,baz");
assert(array.copyWithin(NaN,0,3).toString() === "foo,1,bar,[object Object],2,baz");
// Checking behavior when no length property defined
var obj = { copyWithin : Array.prototype.copyWithin };
obj.copyWithin();
assert(obj.length === undefined);
// Checking behavior when unable to get length
var obj = { copyWithin : Array.prototype.copyWithin };
Object.defineProperty(obj, 'length', { 'get' : function () {throw new ReferenceError ("foo"); } });
try {
obj.copyWithin(1);
assert(false)
} catch (e) {
assert(e.message === "foo");
assert(e instanceof ReferenceError);
}
// Checking behavior when unable to get element
var obj = { copyWithin : Array.prototype.copyWithin, length : 5 };
Object.defineProperty(obj, '2', { 'get' : function () {throw new ReferenceError ("foo"); } });
try {
obj.copyWithin(2);
assert(false);
} catch (e) {
assert(e.message === "foo");
assert(e instanceof ReferenceError);
}
// Checking behavior when a property is not defined
var obj = { '0' : 2, '2' : "foo", length : 3, copyWithin : Array.prototype.copyWithin };
obj.copyWithin(1);
assert(obj[0] === 2);
assert(obj[1] === 2);
function array_check(result_array, expected_array) {
assert(result_array instanceof Array);
assert(result_array.length === expected_array.length);
for (var idx = 0; idx < expected_array.length; idx++) {
assert(result_array[idx] === expected_array[idx]);
}
}
// Remove the buffer
var array = [1, 2, 3];
var value = array.copyWithin(0, {
valueOf: function() {
array.length = 0;
}
})
array_check(value, []);
// Extend the buffer
var array = [1, 2, 3];
var value = array.copyWithin(1, {
valueOf: function() {
array.length = 6;
}
})
array_check(value, [1, 1, 2, undefined, undefined, undefined]);
// Reduce the buffer
var array = [1, 2, 3, 4, 5, 6, 7];
var value = array.copyWithin(4, 2, {
valueOf: function() {
array.length = 3;
}
})
array_check(value, [1, 2, 3]);
// Reduce the buffer and extend the buffer
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var value = array.copyWithin(7, {
valueOf: function() {
array.length = 5;
}
})
array_check(value, [1, 2, 3, 4, 5, , , 1, 2, 3]);
// Copy with overlapping (backward copy)
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var value = array.copyWithin(0, 2, 8)
array_check(value, [3, 4, 5, 6, 7, 8, 7, 8, 9, 10]);
@@ -1,94 +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.
try {
Array.prototype.entries.call (undefined);
assert (false);
} catch (e) {
assert (e instanceof TypeError)
}
var array = ['a', "foo", 1, 1.5, true, {} ,[], function f () { }];
var iterator = array.entries ();
var current_item = iterator.next ();
for (var i = 0; i < array.length; i++) {
assert (current_item.value[0] === i);
assert (current_item.value[1] === array[i]);
assert (current_item.done === false);
current_item = iterator.next ();
}
assert (current_item.value === undefined);
assert (current_item.done === true);
function foo_error () {
throw new ReferenceError ("foo");
}
array = [1, 2, 3, 4, 5, 6, 7];
['0', '3', '5'].forEach (function (e) {
Object.defineProperty (array, e, { 'get' : foo_error });
})
iterator = array.entries ();
var expected_values = [2, 3, 5, 7];
var expected_indices = [1, 2, 4, 6];
var expected_values_idx = 0;
for (var i = 0; i < array.length; i++) {
try {
current_item = iterator.next ();
assert (current_item.value[0] === expected_indices[expected_values_idx]);
assert (current_item.value[1] === expected_values[expected_values_idx]);
assert (current_item.done === false);
expected_values_idx++;
} catch (e) {
assert (e instanceof ReferenceError);
assert (e.message === "foo");
}
}
current_item = iterator.next ();
assert (current_item.value === undefined);
assert (current_item.done === true);
/* Test empty array */
array = [];
iterator = array.entries ();
current_item = iterator.next ();
assert (current_item.value === undefined);
assert (current_item.done === true);
/* Test delete elements after the iterator has been constructed */
array = [0, 1, 2, 3, 4, 5];
iterator = array.entries ();
for (var i = 0; i < array.length; i++) {
current_item = iterator.next ();
assert (current_item.value[0] === i);
assert (current_item.value[1] === array[i]);
assert (current_item.done === false);
array.pop();
}
assert ([].entries ().toString () === "[object Array Iterator]");
-218
View File
@@ -1,218 +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.
// 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.
function assertArrayEquals (array1, array2) {
if (array1.length !== array2.length) {
return false;
}
for (var i = 0; i < array1.length; i++) {
if (array1[i] !== array2[i]) {
return false;
}
}
return true;
}
assert (1 === Array.prototype.fill.length);
assert (assertArrayEquals ([].fill (8), []));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (), [undefined, undefined, undefined, undefined, undefined]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8), [8, 8, 8, 8, 8]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, 1), [0, 8, 8, 8, 8]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, 10), [0, 0, 0, 0, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -5), [8, 8, 8, 8, 8]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, 1, 4), [0, 8, 8, 8, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, 1, -1), [0, 8, 8, 8, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, 1, 42), [0, 8, 8, 8, 8]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -3, 42), [0, 0, 8, 8, 8]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -3, 4), [0, 0, 8, 8, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -2, -1), [0, 0, 0, 8, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, -1, -3), [0, 0, 0, 0, 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (8, undefined, 4), [8, 8, 8, 8, 0]));
assert (assertArrayEquals ([ , , , , 0].fill (8, 1, 3), [, 8, 8, , 0]));
assert (assertArrayEquals ([0, 0, 0, 0, 0].fill (7.8), [7.8, 7.8, 7.8, 7.8, 7.8]));
assert (assertArrayEquals (["foo", "bar", "baz"].fill (1), [1, 1, 1]));
// If the range is empty, the array is not actually modified and
// should not throw, even when applied to a frozen object.
assert (assertArrayEquals (Object.freeze ([1, 2, 3]).fill (0, 0, 0), [1, 2, 3]));
// Test exceptions
try {
Object.freeze ([0]).fill ();
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
Array.prototype.fill.call (null)
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
Array.prototype.fill.call (undefined)
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
function TestFillObjectWithAccessors () {
var kLength = 5;
var log = [];
var object = {
length: kLength,
get 1 () {
log.push ("get 1");
return this.foo;
},
set 1 (val) {
log.push ("set 1 " + val);
this.foo = val;
}
};
Array.prototype.fill.call (object, 42);
assert (kLength === object.length);
assert (assertArrayEquals (["set 1 42"], log));
for (var i = 0; i < kLength; ++i) {
assert (42 === object[i]);
}
}
TestFillObjectWithAccessors ();
function TestFillObjectWithMaxNumberLength () {
var kMaxSafeInt = Math.pow (2, 32) - 1;
var object = {};
object.length = kMaxSafeInt;
Array.prototype.fill.call (object, 42, Math.pow (2, 32) - 4);
assert (kMaxSafeInt === object.length);
assert (42 === object[kMaxSafeInt - 3]);
assert (42 === object[kMaxSafeInt - 2]);
assert (42 === object[kMaxSafeInt - 1]);
}
TestFillObjectWithMaxNumberLength ();
function TestFillObjectWithPrototypeAccessors () {
var kLength = 5;
var log = [];
var proto = {
get 1 () {
log.push ("get 0");
return this.foo;
},
set 1 (val) {
log.push ("set 1 " + val);
this.foo = val;
}
};
var object = { 0:0, 2:2, length: kLength};
Object.setPrototypeOf (object, proto);
Array.prototype.fill.call (object, "42");
assert (kLength === object.length);
assert (assertArrayEquals (["set 1 42"], log));
assert (object.hasOwnProperty (0) == true);
assert (object.hasOwnProperty (1) == false);
assert (object.hasOwnProperty (2) == true);
assert (object.hasOwnProperty (3) == true);
assert (object.hasOwnProperty (4) == true);
for (var i = 0; i < kLength; ++i) {
assert ("42" === object[i]);
}
}
TestFillObjectWithPrototypeAccessors ();
function TestFillSealedObject () {
var object = { length: 42 };
Object.seal (object);
try {
Array.prototype.fill.call (object);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
}
TestFillSealedObject ();
function TestFillFrozenObject () {
var object = { length: 42 };
Object.freeze (object);
try {
Array.prototype.fill.call (object);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
}
TestFillFrozenObject ();
function array_check(result_array, expected_array) {
assert(result_array instanceof Array);
assert(result_array.length === expected_array.length);
for (var idx = 0; idx < expected_array.length; idx++) {
assert(result_array[idx] === expected_array[idx]);
}
}
// Remove the buffer
var array = [1, 2, 3, 4, 5];
var value = array.fill(2, 0, {
valueOf: function() {
array.length = 0;
}
})
array_check(value, []);
// Extend the buffer
var array = [1, 2, 3];
var value = array.fill(1, {
valueOf: function() {
array.length = 6;
}
})
array_check(value, [1, 1, 1, undefined, undefined, undefined]);
// Reduce the buffer
var array = [1, 2, 3, 4, 5, 6, 7];
var value = array.fill(4, {
valueOf: function() {
array.length = 3;
}
})
array_check(value, [4, 4, 4]);
@@ -1,162 +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 arrow_is_available = false;
try {
assert (eval ("(f => 5) ()") === 5);
arrow_is_available = true;
} catch (e) {
assert (e instanceof SyntaxError);
}
var array1 = [5, 12, 0, 8, 130, 44];
function bigger_than_10 (element) {
return element > 10;
}
assert (array1.findIndex (bigger_than_10) === 1);
function less_than_0 (element) {
if (element == 0) {
throw new Error ("zero");
}
return element < 0;
}
try {
array1.findIndex (less_than_0);
assert (false);
} catch (e) {
assert (e instanceof Error);
assert (e.message === "zero");
}
var inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
function isCherries (fruit) {
return fruit.name === 'cherries';
}
assert (JSON.stringify (inventory.findIndex (isCherries)) === "2");
if (arrow_is_available) {
assert (eval ("inventory.findIndex (fruit => fruit.name === 'bananas')") === 1);
}
/* Test the callback function arguments */
var src_array = [4, 6, 8, 12];
var array_index = 0;
function isPrime (element, index, array) {
assert (array_index++ === index);
assert (array === src_array)
assert (element === array[index]);
var start = 2;
while (start <= Math.sqrt (element)) {
if (element % start++ < 1) {
return false;
}
}
return element > 1;
}
assert (src_array.findIndex (isPrime) === -1);
src_array = [4, 5, 8, 12];
array_index = 0;
assert (src_array.findIndex (isPrime) === 1);
// Checking behavior when the given object is not %Array%
try {
Array.prototype.findIndex.call (5);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
// Checking behavior when unable to get length
var obj = {};
Object.defineProperty (obj, 'length', { 'get' : function () { throw new ReferenceError ("foo"); } });
obj.findIndex = Array.prototype.findIndex;
try {
obj.findIndex ();
assert (false);
} catch (e) {
assert (e.message === "foo");
assert (e instanceof ReferenceError);
}
var data = { 0: 1, 2: -3, 3: "string" }
assert (Array.prototype.findIndex.call (data, function (e) { return e < 5; }) === -1);
// Checking behavior when unable to get element
var obj = {}
obj.length = 1;
Object.defineProperty (obj, '0', { 'get' : function () { throw new ReferenceError ("foo"); } });
obj.findIndex = Array.prototype.findIndex;
try {
obj.findIndex (function () { return undefined; });
assert (false);
} catch (e) {
assert (e.message === "foo");
assert (e instanceof ReferenceError);
}
// Checking behavior when the first argument is not a callback
var array = [1, 2, 3];
try {
array.findIndex (5);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
// Checking behavior when the first argument does not exist
try {
array.findIndex ();
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
// Checking behavior when there are more than 2 arguments
assert (array.findIndex (function (e) { return e < 2 }, {}, 8, 4, 5, 6, 6) === 0);
function func (element) {
return element > 8;
}
/* ES v6.0 22.1.3.9.8.c
Checking behavior when the first element deletes the second */
function f() { delete arr[1]; };
var arr = [0, 1, 2, 3];
Object.defineProperty(arr, '0', { 'get' : f });
Array.prototype.findIndex.call(arr, func);
/* ES v6.0 22.1.3.9.8
Checking whether predicate is called also for empty elements */
var count = 0;
[,,,].findIndex(function() { count++; return false; });
assert (count == 3);
-155
View File
@@ -1,155 +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 arrow_is_available = false;
try {
assert (eval ("(f => 5) ()") === 5);
arrow_is_available = true;
} catch (e) {
assert (e instanceof SyntaxError);
}
var array1 = [5, 12, 0, 8, 130, 44];
function bigger_than_10 (element) {
return element > 10;
}
assert (array1.find (bigger_than_10) === 12);
function less_than_0 (element) {
if (element == 0) {
throw new Error ("zero");
}
return element < 0;
}
try {
array1.find (less_than_0);
assert (false);
} catch (e) {
assert (e instanceof Error);
assert (e.message === "zero");
}
var inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
function isCherries (fruit) {
return fruit.name === 'cherries';
}
assert (JSON.stringify (inventory.find (isCherries)) === '{"name":"cherries","quantity":5}');
if (arrow_is_available) {
assert (eval ("inventory.find (fruit => fruit.name === 'bananas')") === inventory[1]);
}
/* Test the callback function arguments */
var src_array = [4, 6, 8, 12];
var array_index = 0;
function isPrime (element, index, array) {
assert (array_index++ === index);
assert (array === src_array)
assert (element === array[index]);
var start = 2;
while (start <= Math.sqrt (element)) {
if (element % start++ < 1) {
return false;
}
}
return element > 1;
}
assert (src_array.find (isPrime) === undefined);
src_array = [4, 5, 8, 12];
array_index = 0;
assert (src_array.find (isPrime) === 5);
// Checking behavior when unable to get length
var obj = {};
Object.defineProperty (obj, 'length', { 'get' : function () { throw new ReferenceError ("foo"); } });
obj.find = Array.prototype.find;
try {
obj.find ();
assert (false);
} catch (e) {
assert (e.message === "foo");
assert (e instanceof ReferenceError);
}
var data = { 0: 1, 2: -3, 3: "string" }
assert (Array.prototype.find.call (data, function (e) { return e < 5; }) === undefined);
// Checking behavior when unable to get element
var obj = {}
obj.length = 1;
Object.defineProperty (obj, '0', { 'get' : function () { throw new ReferenceError ("foo"); } });
obj.find = Array.prototype.find
try {
obj.find (function () { return undefined; });
assert (false);
} catch (e) {
assert (e.message === "foo");
assert (e instanceof ReferenceError);
}
// Checking behavior when the first argument is not a callback
var array = [1, 2, 3];
try {
array.find (5);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
// Checking behavior when the first argument does not exist
try {
array.find ();
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
// Checking behavior when the there are more than 2 arguments
assert (array.find (function (e) { return e < 2 }, {}, 8, 4, 5, 6, 6) === 1);
function func (element) {
return element > 8;
}
/* ES v6.0 22.1.3.8.8.c
Checking behavior when the first element deletes the second */
function f() { delete arr[1]; };
var arr = [0, 1, 2, 3];
Object.defineProperty(arr, '0', { 'get' : f });
Array.prototype.find.call(arr, func);
/* ES v6.0 22.1.3.8.8
Checking whether predicate is called also for empty elements */
var count = 0;
[,,,].find(function() { count++; return false; });
assert (count == 3);
@@ -1,146 +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.
// helper function - simple implementation
Array.prototype.equals = function (array) {
if (this.length != array.length)
return false;
for (var i = 0; i < this.length; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) {
if (!this[i].equals(array[i]))
return false;
}
else if (this[i] != array[i]) {
return false;
}
}
return true;
}
// various checks on flat prototype
assert ([1, 4, 9].flat(2).equals([1, 4, 9]))
assert ([[4,9]].flat(0).equals([[4,9]]))
assert ([[4,9]].flat(1).equals([4,9]))
assert ([1, 4, [9,3,[2,4,[3,4]]]].flat(5).equals([1, 4, 9, 3, 2, 4, 3, 4]));
var array1 = [1,3,4]
var array2 = [array1,array1]
assert(array2.flat(1).equals([1,3,4,1,3,4]))
assert(array2.flat(0).equals([[1,3,4],[1,3,4]]))
var array3 = [array2]
assert(array3.flat(0).equals([[[1,3,4],[1,3,4]]]))
assert(array3.flat(1).equals([[1,3,4],[1,3,4]]))
assert(array3.flat(2).equals([1,3,4,1,3,4]))
var array4 = []
assert(array4.flat(10).equals([]))
var array5 = [null, array4]
assert(array5.flat(10).equals([null]))
// various checks on flatMap Prototype
assert([1, 2, 3, 4].flatMap(x => [x, x * 2]).equals([1,2,2,4,3,6,4,8]))
assert([1, 2, 3, 4].flatMap(x => [x, x * x]).equals([1,1,2,4,3,9,4,16]))
assert(array1.flatMap(x => [x, x * 2]).equals([1,2,3,6,4,8]))
assert(array4.flatMap(x => [x, x * 2]).equals([]))
function check_flat (map, depth)
{
try {
map.flat (depth)
assert (false)
} catch (e) {
assert (e instanceof TypeError);
}
}
function check_flat_map (map, mapper)
{
try {
map.flatMap (mapper)
assert (false)
} catch (e) {
assert (e instanceof TypeError);
}
}
// invalid depth
check_flat ([1,2], Symbol())
// constructor is null
var a = new Array();
a.constructor = null;
check_flat (a,1)
// callback is not object
check_flat_map ([1,2], null)
// constructor is null
check_flat_map (a,x => [x, x * x])
// "0" get is a TypeError
var array_2 = [1,2]
Object.defineProperty (array_2, '0', { 'get' : function () { throw new TypeError (); } });
check_flat (array_2, 1)
check_flat_map (array_2,x => [x, x * x])
// "0" is not Array and throw error
var revocable = Proxy.revocable ({}, {});
var proxy = revocable.proxy;
revocable.revoke();
var array_3 = [proxy,2]
check_flat (array_3, 1)
// second call of FlattenIntoArray return with a error
var array_4_1 = [1,2]
Object.defineProperty (array_4_1, '0', { 'get' : function () { throw new TypeError (); } });
var array_4 = [array_4_1,1,2]
check_flat (array_4, 1)
// unable to add new property
var array_5 = [array_2,1,2]
check_flat (array_2, 1)
var A = function(_length) {
Object.defineProperty(this, "0", {
writable: true,
configurable: false,
});
};
var arr = [1];
arr.constructor = {};
arr.constructor[Symbol.species] = A;
check_flat_map (arr, A)
// element value is not found
var array_6 = []
array_6.length = 2
array_6.flat()
// mapped function is error
var array_7 = [1,2]
var f = function () {
throw new TypeError()
}
check_flat_map (array_7, f)
var obj = new Proxy ([], { get(t, p, r) {
if (p === 'length') {
throw new TypeError();
}
}})
@@ -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.
assert(Array.prototype.includes.length === 1);
assert(Array.prototype.includes.name === "includes");
var num_arr = [1, 2, 3,,4, 5];
var str_arr = ['foo', 'bar', 'baz', NaN, 'foo'];
var obj = {};
var obj_arr = [1, obj, 2];
var empry_arr = [];
assert(num_arr.includes(3) === true);
assert(num_arr.includes(3, 4) === false);
assert(num_arr.includes(3, -5) === true);
assert(num_arr.includes(undefined) === true);
assert(num_arr.includes(3, Infinity) === false);
assert(num_arr.includes(3, -0) === true);
assert(str_arr.includes(NaN) === true);
assert(str_arr.includes('foo', 4) === true);
assert(str_arr.includes('f') === false);
assert(obj_arr.includes(obj) === true);
assert(obj_arr.includes({}) === false);
assert(empry_arr.includes() === false);
assert(empry_arr.includes(3) === false);
assert([undefined].includes() === true);
Object.defineProperty(num_arr, "1", { get: function() {throw 42}});
try {
num_arr.includes(4);
assert(false);
} catch (e) {
assert(e === 42);
}
var sym = Symbol('foo');
try {
num_arr.includes(3, sym);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
// Remove the buffer
var array = [1, 2, 3, 4, 5];
var found = array.includes(4, {
valueOf: function() {
array.length = 0;
}
})
assert(found === false);
// Extend the buffer
var array = [1, 2, 3];
var found = array.includes(2, {
valueOf: function() {
array.length = 5;
}
})
assert(found === true);
// Reduce the buffer
var array = [1, 2, 3, 4, 5, 6, 7];
var found = array.includes(6, {
valueOf: function() {
array.length = 5;
}
})
assert(found === false);
@@ -1,86 +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.
try {
Array.prototype.keys.call (undefined);
assert (false);
} catch (e) {
assert (e instanceof TypeError)
}
var array = ['a', "foo", 1, 1.5, true, {} ,[], function f () { }];
var iterator = array.keys ();
var current_item = iterator.next ();
for (var i = 0; i < array.length; i++) {
assert (current_item.value === i);
assert (current_item.done === false);
current_item = iterator.next ();
}
assert (current_item.value === undefined);
assert (current_item.done === true);
function foo_error () {
throw new ReferenceError ("foo");
}
array = [1, 2, 3, 4, 5, 6, 7];
['0', '3', '5'].forEach (function (e) {
Object.defineProperty (array, e, { 'get' : foo_error });
})
iterator = array.keys ();
for (var i = 0; i < array.length; i++) {
try {
current_item = iterator.next ();
assert (current_item.value === i);
assert (current_item.done === false);
} catch (e) {
assert (e instanceof ReferenceError);
assert (e.message === "foo");
}
}
current_item = iterator.next ();
assert (current_item.value === undefined);
assert (current_item.done === true);
/* Test empty array */
array = [];
iterator = array.keys ();
current_item = iterator.next ();
assert (current_item.value === undefined);
assert (current_item.done === true);
/* Test delete elements after the iterator has been constructed */
array = [0, 1, 2, 3, 4, 5];
iterator = array.keys ();
for (var i = 0; i < array.length; i++) {
current_item = iterator.next ();
assert (current_item.value === i);
assert (current_item.done === false);
array.pop();
}
assert ([].keys ().toString () === "[object Array Iterator]");
@@ -1,55 +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.
// Constructor creates longer array than expected.
class LongArray extends Array {
constructor(len) {
super (42);
this.fill ("foo");
}
}
var a = new LongArray (5);
a.length = 5;
var sliced = a.slice ();
assert (sliced.length == 5);
assert (JSON.stringify (sliced) == '["foo","foo","foo","foo","foo"]')
// Constructor creates shorter array than expected.
class ShortArray extends Array {
constructor(len) {
super (2);
this.fill ("bar");
}
}
var b = new ShortArray (8);
b.length = 8;
b.fill ("asd", 2);
var sliced2 = b.slice ();
assert (sliced2.length == 8);
assert (JSON.stringify (sliced2) == '["bar","bar","asd","asd","asd","asd","asd","asd"]');
// Constructor creates array of the expected size.
class ExactArray extends Array {
constructor(len) {
super (len);
this.fill ("baz");
}
}
var c = new ExactArray (5);
var sliced3 = c.slice();
assert (sliced3.length == 5);
assert (JSON.stringify (sliced3) == '["baz","baz","baz","baz","baz"]');
@@ -1,24 +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 proxy = new Proxy({length: 5}, {
getOwnPropertyDescriptor() { throw 42.5; }
})
try {
Array.prototype.sort.call(proxy);
assert(false);
} catch (e) {
assert(e === 42.5);
}
@@ -1,17 +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 arrayLike = {get 5() { throw "shouldn't throw"; }};
arrayLike.length = 10;
Array.prototype.unshift.call(arrayLike);
@@ -1,100 +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.
try {
Array.prototype.values.call (undefined);
assert (false);
} catch (e) {
assert (e instanceof TypeError)
}
var array = ['a', "foo", 1, 1.5, true, {} ,[], function f () { }];
var iterator = array.values ();
/* The initial value of the @@iterator property is the same function object
as the initial value of the Array.prototype.values property. */
var symbol_iterator = array[Symbol.iterator] ();
var current_item = iterator.next ();
var symbol_current_item = symbol_iterator.next ();
for (var i = 0; i < array.length; i++) {
assert (current_item.value === array[i]);
assert (current_item.done === false);
assert (current_item.value === symbol_current_item.value);
assert (current_item.done === symbol_current_item.done);
current_item = iterator.next ();
symbol_current_item = symbol_iterator.next ();
}
assert (current_item.value === undefined);
assert (current_item.done === true);
assert (current_item.value === symbol_current_item.value);
assert (current_item.done === symbol_current_item.done);
function foo_error () {
throw new ReferenceError ("foo");
}
array = [1, 2, 3, 4, 5, 6, 7];
['0', '3', '5'].forEach (function (e) {
Object.defineProperty (array, e, { 'get' : foo_error });
})
iterator = array.values ();
var expected_values = [2, 3, 5, 7];
var expected_values_idx = 0;
for (var i = 0; i < array.length; i++) {
try {
current_item = iterator.next ();
assert (current_item.value === expected_values[expected_values_idx++]);
assert (current_item.done === false);
} catch (e) {
assert (e instanceof ReferenceError);
assert (e.message === "foo");
}
}
current_item = iterator.next ();
assert (current_item.value === undefined);
assert (current_item.done === true);
/* Test empty array */
array = [];
iterator = array.values ();
current_item = iterator.next ();
assert (current_item.value === undefined);
assert (current_item.done === true);
/* Test delete elements after the iterator has been constructed */
array = [0, 1, 2, 3, 4, 5];
iterator = array.values ();
for (var i = 0; i < array.length; i++) {
current_item = iterator.next ();
assert (current_item.value === array[i]);
assert (current_item.done === false);
array.pop();
}
assert ([].values ().toString () === "[object Array Iterator]");
-184
View File
@@ -1,184 +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.
*/
// 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.
// Test the ES2015 @@species feature
'use strict';
// Subclasses of Array construct themselves under map, etc
class MyArray extends Array { }
function assertEquals(a, b) {
assert(a === b);
}
assertEquals(MyArray, new MyArray().map(()=>{}).constructor);
assertEquals(MyArray, new MyArray().filter(()=>{}).constructor);
assertEquals(MyArray, new MyArray().slice().constructor);
assertEquals(MyArray, new MyArray().splice().constructor);
assertEquals(MyArray, new MyArray().concat([1]).constructor);
assertEquals(1, new MyArray().concat([1])[0]);
// Subclasses can override @@species to return the another class
class MyOtherArray extends Array {
static get [Symbol.species]() { return MyArray; }
}
assertEquals(MyArray, new MyOtherArray().map(()=>{}).constructor);
assertEquals(MyArray, new MyOtherArray().filter(()=>{}).constructor);
assertEquals(MyArray, new MyOtherArray().slice().constructor);
assertEquals(MyArray, new MyOtherArray().splice().constructor);
assertEquals(MyArray, new MyOtherArray().concat().constructor);
// Array methods on non-arrays return arrays
class MyNonArray extends Array {
static get [Symbol.species]() { return MyObject; }
}
class MyObject { }
assertEquals(MyObject,
Array.prototype.map.call(new MyNonArray(), ()=>{}).constructor);
assertEquals(MyObject,
Array.prototype.filter.call(new MyNonArray(), ()=>{}).constructor);
assertEquals(MyObject,
Array.prototype.slice.call(new MyNonArray()).constructor);
assertEquals(MyObject,
Array.prototype.splice.call(new MyNonArray()).constructor);
assertEquals(MyObject,
Array.prototype.concat.call(new MyNonArray()).constructor);
assertEquals(undefined,
Array.prototype.map.call(new MyNonArray(), ()=>{}).length);
assertEquals(undefined,
Array.prototype.filter.call(new MyNonArray(), ()=>{}).length);
// slice, splice, and concat actually do explicitly define the length.
assertEquals(0, Array.prototype.slice.call(new MyNonArray()).length);
assertEquals(0, Array.prototype.splice.call(new MyNonArray()).length);
assertEquals(1, Array.prototype.concat.call(new MyNonArray(), ()=>{}).length);
// Defaults when constructor or @@species is missing or non-constructor
class MyDefaultArray extends Array {
static get [Symbol.species]() { return undefined; }
}
assertEquals(Array, new MyDefaultArray().map(()=>{}).constructor);
class MyOtherDefaultArray extends Array { }
assertEquals(MyOtherDefaultArray,
new MyOtherDefaultArray().map(()=>{}).constructor);
MyOtherDefaultArray.prototype.constructor = undefined;
assertEquals(Array, new MyOtherDefaultArray().map(()=>{}).constructor);
assertEquals(Array, new MyOtherDefaultArray().concat().constructor);
// Exceptions propagated when getting constructor @@species throws
class SpeciesError extends Error { }
class ConstructorError extends Error { }
class MyThrowingArray extends Array {
static get [Symbol.species]() { throw new SpeciesError; }
}
function assertThrows (a, b) {
try {
a();
} catch (e) {
assert(e instanceof b);
}
}
assertThrows(() => new MyThrowingArray().map(()=>{}), SpeciesError);
Object.defineProperty(MyThrowingArray.prototype, 'constructor', {
get() { throw new ConstructorError; }
});
assertThrows(() => new MyThrowingArray().map(()=>{}), ConstructorError);
// Previously unexpected errors from setting properties in arrays throw
class FrozenArray extends Array {
constructor(...args) {
super(...args);
Object.freeze(this);
}
}
assertThrows(() => new FrozenArray([1]).map(()=>0), TypeError);
assertThrows(() => new FrozenArray([1]).filter(()=>true), TypeError);
assertThrows(() => new FrozenArray([1]).slice(0, 1), TypeError);
assertThrows(() => new FrozenArray([1]).splice(0, 1), TypeError);
assertThrows(() => new FrozenArray([]).concat([1]), TypeError);
// Verify call counts and constructor parameters
var count;
var params;
class MyObservedArray extends Array {
constructor(...args) {
super(...args);
params = args;
}
static get [Symbol.species]() {
count++
return this;
}
}
function assertArrayEquals(value, expected, type) {
assert(expected.length === value.length);
for (var i=0; i<value.length; ++i) {
assertEquals(expected[i], value[i]);
}
}
count = 0;
params = undefined;
assertEquals(MyObservedArray,
new MyObservedArray().map(()=>{}).constructor);
assertEquals(1, count);
assertArrayEquals([0], params);
count = 0;
params = undefined;
assertEquals(MyObservedArray,
new MyObservedArray().filter(()=>{}).constructor);
assertEquals(1, count);
assertArrayEquals([0], params);
count = 0;
params = undefined;
assertEquals(MyObservedArray,
new MyObservedArray().concat().constructor);
assertEquals(1, count);
assertArrayEquals([0], params);
count = 0;
params = undefined;
assertEquals(MyObservedArray,
new MyObservedArray().slice().constructor);
assertEquals(1, count);
assertArrayEquals([0], params);
count = 0;
params = undefined;
assertEquals(MyObservedArray,
new MyObservedArray().splice().constructor);
assertEquals(1, count);
assertArrayEquals([0], params);
-79
View File
@@ -1,79 +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 assertArrayEqual (actual, expected) {
assert (actual.length === expected.length);
for (var i = 0; i < actual.length; i++) {
assert (actual[i] === expected[i]);
}
}
function checkSyntax (str) {
try {
eval (str);
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
}
function mustThrow (str) {
try {
eval (str);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
}
checkSyntax ("{...a}");
checkSyntax ("...a");
checkSyntax ("[...]");
checkSyntax ("[...(...)]");
checkSyntax ("[......]");
mustThrow ("[...5]");
mustThrow ("[...5, 'foo', 'bar']");
mustThrow ("[...{}]");
mustThrow ("[...{ get [Symbol.iterator] () { throw new TypeError } }]");
mustThrow ("[...{ [Symbol.iterator] () {} }, 'foo']");
mustThrow ("[...{ [Symbol.iterator] () { return {} } }]");
mustThrow ("[...{ [Symbol.iterator] () { return { next: 5 } } }]");
mustThrow ("[...{ [Symbol.iterator] () { return { next: 5 } } }], 'foo'");
mustThrow ("[...{ [Symbol.iterator] () { return { get next() { throw new TypeError } } } }]");
mustThrow ("[...{ [Symbol.iterator] () { return { next () { } } } }]");
mustThrow ("[...{ [Symbol.iterator] () { return { next () { } } } }, 'foo']");
mustThrow ("[...{ [Symbol.iterator] () { return { next () { return { get value () { throw new TypeError } } } } } } ]");
mustThrow ("[...{ [Symbol.iterator] () { return { next () { return { get done () { throw new TypeError } } } } } } ]");
var arr1 = [0, 1, 2];
var arr2 = [3, 4, 5];
var arr3 = [{}, {}, {}];
var expected = [0, 1, 2, 3 ,4, 5];
assertArrayEqual ([...arr1, ...arr2], [0, 1, 2, 3 ,4, 5]);
assertArrayEqual ([...arr2, ...arr1], [3 ,4, 5, 0, 1, 2]);
assertArrayEqual ([...arr1, 9, 9, 9, ...arr2], [0, 1, 2, 9, 9, 9, 3 ,4, 5]);
assertArrayEqual ([...arr1, ...[...arr2]], [0, 1, 2, 3 ,4, 5]);
assertArrayEqual (["0" , "1", ...arr1, ...[...arr2]], ["0", "1", 0, 1, 2, 3 ,4, 5]);
assertArrayEqual ([...arr3], arr3);
assertArrayEqual ([..."foobar"], ["f", "o", "o", "b", "a" ,"r"]);
assertArrayEqual ([...(new Set([1, "foo", arr3]))], [1, "foo", arr3]);
var holyArray = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...arr1];
assert (holyArray.length === 83);
assert (holyArray[82] === 2);
assert (holyArray[81] === 1);
assert (holyArray[80] === 0);
-37
View File
@@ -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.
*/
assert(ArrayBuffer.isView() === false);
assert(ArrayBuffer.isView([]) === false);
assert(ArrayBuffer.isView({}) === false);
assert(ArrayBuffer.isView(null) === false);
assert(ArrayBuffer.isView(undefined) === false);
assert(ArrayBuffer.isView(new ArrayBuffer(10)) === false);
assert(ArrayBuffer.isView(new Int8Array()) === true);
assert(ArrayBuffer.isView(new Uint8Array()) === true);
assert(ArrayBuffer.isView(new Uint8ClampedArray()) === true);
assert(ArrayBuffer.isView(new Int16Array()) === true);
assert(ArrayBuffer.isView(new Uint16Array()) === true);
assert(ArrayBuffer.isView(new Int32Array()) === true);
assert(ArrayBuffer.isView(new Uint32Array()) === true);
assert(ArrayBuffer.isView(new Float32Array()) === true);
assert(ArrayBuffer.isView(new Float64Array()) === true);
assert(ArrayBuffer.isView(new Int8Array(10).subarray(0, 3)) === true);
var buffer = new ArrayBuffer(2);
var dv = new DataView(buffer);
assert(ArrayBuffer.isView(dv) === true);
-46
View File
@@ -1,46 +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 y = 0
var prot = Object.getPrototypeOf(/ /)
prot.setY = function (v) { y = v }
assert(y === 0)
// Since arrow function is an assignment expression, this affects certain constructs
var f = x => {}
/ /.setY(5)
assert(y === 5)
var s
// This is not a function call
assert(eval("s = x => { return 1 }\n(3)") === 3)
assert(typeof s === "function")
// This is a function call
assert(eval("s = function () { return 1 }\n(3)") === 1)
assert(s === 1)
var f = 5 ? x => 1 : x => 2
assert(f() === 1)
var f = [x => 2][0]
assert(f() === 2)
var f = 123; f += x => y
assert(typeof f === "string")
// Comma operator
assert(eval("x => {}, 5") === 5)
-41
View File
@@ -1,41 +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.
*/
let a = 4
var f = () => {
eval("var a = 5")
assert(a === 5)
}
f()
assert(a === 4)
function g() {
eval("var b = 6")
assert(b === 6)
var h = () => delete b
h()
try {
b
assert(false)
} catch (e) {
assert(e instanceof ReferenceError)
}
}
g()
-194
View File
@@ -1,194 +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)
{
}
}
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)
{
}
}
switch (1)
{
default:
var func = x => { return x + 3 }
assert (func(5) == 8);
a => 5 /* no semicolon after */
assert (((x =>
x + 1))(4) == 5)
assert ((a => a += 3, b => b -= 3)(4) == 1);
func = true ? x=>x+2:y=>y-2
assert (func(10) == 12);
func = arguments =>
{ return arguments + 4; }
assert (func(2) == 6);
func = (
) => { return typeof
arguments
}
assert (func() === "undefined");
if (a => 0)
{
}
else
{
assert (false);
}
assert ((
(
static
,
package
) => static + package
) (2, 12) == 14);
var global_var = 7;
assert ((
(
static
,
package
) => { global_var = 5; return static + package }
)(4, 5) == 9);
assert (global_var == 5);
func = (x , y) => {}
assert (func() === undefined)
assert ((x => y => z => 6)()()() == 6)
func = x => x - 6
var func2 = y => func(y)
assert (func2 (17) == 11)
func = (m) => m++
assert (func (4) == 4)
func = () =>
((([0,0,0])))
assert (func ().length == 3);
func = (a = 5, b = 7 * 2) => a + b;
assert (func() == 19);
assert (func(1) == 15);
func = (a = Math.cos(0)) => a;
assert (func() == 1);
}
must_throw ("var x => x;");
must_throw ("(()) => 0");
must_throw ("((x)) => 0");
must_throw ("(((x))) => 0");
must_throw ("(x==6) => 0");
must_throw ("(x y) => 0");
must_throw ("x\n => 0");
must_throw ("this => 0");
must_throw ("(true) => 0");
must_throw ("()\n=>5");
must_throw ("3 + x => 3");
must_throw ("3 || x => 3");
must_throw ("a = 3 || (x,y) => 3");
must_throw ("x => {} (4)");
must_throw ("!x => 4");
must_throw ("x => {} = 1");
must_throw ("x => {} a = 1");
must_throw ("x => {} ? 1 : 0");
must_throw ("(x,x,x) => 0");
must_throw ("(x,x,x) => { }");
must_throw_strict ("(package) => 0");
must_throw_strict ("(package) => { return 5 }");
must_throw_strict ("(x,x,x) => 0");
must_throw_strict ("(x,x,x) => { }");
var f = (a) => 1;
assert(f() === 1);
var f = (a => 2);
assert(f() === 2);
var f = ((((a => ((3))))));
assert(f() === 3);
var f = (((a) => 4));
assert(f() === 4);
var f = (a,b) => 5;
assert(f() === 5);
var f = (((a,b) => 6));
assert(f() === 6);
var f = ((a,b) => x => (a) => 7);
assert(f()()() === 7);
var f = (((a=1,b=2) => ((x => (((a) => 8))))));
assert(f()()() === 8);
var f = () => {};
assert(f.hasOwnProperty('caller') === false);
assert(f.hasOwnProperty('arguments') === false);
must_throw("var f = () => {}; f.caller")
must_throw("var f = () => {}; f.arguments")
must_throw("var f = () => {}; f.caller = 1")
must_throw("var f = () => {}; f.arguments = 2")
-40
View File
@@ -1,40 +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 o = {
x: 13,
f: function()
{
return () => this.x + 1
},
g: function()
{
return function() {
return this.x + 1
}
}
}
assert(o.f().call(o) === 14);
assert(o.g().call(o) === 14);
assert(o.f()() === 14);
var o2 = { x:4, f:o.f(), g:o.g() }
assert(o2.f() === 14);
assert(o2.g() === 5);
@@ -1,210 +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.
*/
/* 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.
*/
async function f() {
let arr_idx = 0;
for await (let a of [0, 1, 2, 3]) {
assert(arr_idx++ == a);
}
let char_code = "a".charCodeAt(0);
for await (let a of "abc") {
assert(char_code++ == a.charCodeAt(0));
}
let set_idx = 0;
for await (let a of new Set([0, 1, 2, 3])) {
assert(set_idx++ == a);
}
let map_idx = 0;
for await (let [key, value] of new Map([0, 1, 2, 3].entries())) {
assert(map_idx++ == value);
}
}
async function* asyncg(obj) {
yield* obj;
}
async function f1() {
var caught = false;
var iter = asyncg({
get [Symbol.iterator]() {
throw "Symbol.iteratorError"
},
});
iter.next().catch(e => {
caught = true;
assert(e === "Symbol.iteratorError")
}).then(e => {
assert(caught)
});
}
async function f2() {
var caught = false;
var iter = asyncg({
[Symbol.iterator]() {
return {
next() {
throw "nextError";
},
};
},
});
iter.next().catch(e => {
caught = true;
assert(e === "nextError")
}).then(e => {
assert(caught)
});
}
async function f3() {
var caught = false;
var iter = asyncg({
[Symbol.iterator]() {
return {
next() {
return {
get value() {
throw "valueError"
},
done: false
};
},
};
},
});
iter.next().catch(e => {
caught = true;
assert(e === "valueError")
}).then(e => {
assert(caught)
});
}
async function f4() {
var caught = false;
var iter = asyncg({
[Symbol.iterator]() {
return {
next() {
return {
value: "value",
get done() {
throw "doneError"
},
};
},
};
},
});
iter.next().catch(e => {
caught = true;
assert(e === "doneError")
}).then(e => {
assert(caught)
});
}
async function f5() {
var caught = false;
var iter = asyncg({
[Symbol.iterator]() {
return {
next() {
return {
value: 1,
done: false
};
},
get return () {
throw "returnError"
}
};
}
});
iter.next().then(function (res) {
assert(res.value === 1);
assert(!res.done);
iter.return().catch(e => {
caught = true;
assert(e == "returnError");
}).then(e => {
assert(caught);
});
});
}
async function f6() {
var caught = false;
var iter = asyncg({
[Symbol.iterator]() {
return {
next() {
return {
value: 1,
done: false
};
},
get throw () {
throw "throwError"
}
};
}
});
iter.next().then(function (res) {
assert(res.value === 1);
assert(!res.done);
iter.throw().catch(e => {
caught = true;
assert(e == "throwError");
}).then(e => {
assert(caught);
});
});
}
const tests = [f, f1, f2, f3, f4, f5, f6];
for (let t of tests) {
t();
}
-65
View File
@@ -1,65 +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.
const buffer = new SharedArrayBuffer (16);
const uint8 = new Uint8Array (buffer);
uint8[0] = 7;
Atomics.add (uint8, 0, 2);
Atomics.and (uint8, 0, 2);
Atomics.compareExchange (uint8, 0, 5, 2);
Atomics.exchange (uint8, 0, 2);
Atomics.or (uint8, 0, 2);
Atomics.sub (uint8, 0, 2);
Atomics.xor (uint8, 0, 2)
Atomics.isLockFree (3);
Atomics.load (uint8, 0);
Atomics.store (uint8, 0, 2);
const sab = new SharedArrayBuffer (1024);
const int32 = new Int32Array (sab);
Atomics.wait (int32, 0, 0);
Atomics.notify (int32, 0, 1);
try {
let a;
Atomics.add (a, 0, 0);
} catch (ex) {
assert (ex instanceof TypeError);
}
try {
Atomics.add (new Float32Array(10), 0, 2);
} catch (ex) {
assert (ex instanceof TypeError);
}
try{
const uint16 = new Uint16Array (new ArrayBuffer (16));
Atomics.add(uint16, 0, 0);
} catch (ex) {
assert (ex instanceof TypeError);
}
try {
Atomics.add (uint8, 100, 0);
} catch (ex) {
assert (ex instanceof RangeError);
}
try {
Atomics.add (uint8, -1, 0);
} catch (ex) {
assert (ex instanceof RangeError);
}
@@ -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.
function arrayEquals(result, expected) {
assert(result.length === expected.length);
for (var idx = 0; idx < result.length; idx++) {
assert(result[idx] === expected[idx]);
}
}
var bigint64_array = new BigInt64Array([1n, 2n, 3n, -4n, 5n]);
function positive(element, index, array) {
return element > 0n;
}
var bigint64_filter = bigint64_array.filter(positive);
arrayEquals(bigint64_filter, [1n, 2n, 3n, 5n]);
var biguint64_array = new BigUint64Array([1n, 2n, 3n, -4n, 5n]);
var biguint64_filter = biguint64_array.filter(positive);
assert(biguint64_filter.length === 5);
@@ -1,26 +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 bigint64_array = new BigInt64Array([1n, 2n, 3n, -4n, 5n]);
function sum(prev, current) {
return prev + current;
}
var bigint64_reduce_result = bigint64_array.reduce(sum, 7n);
assert(bigint64_reduce_result === 14n);
var biguint64_array = new BigUint64Array([1n, 2n, 3n, -4n, 5n]);
var biguint64_reduce_result = biguint64_array.reduce(sum, 7n);
assert(biguint64_reduce_result === 18446744073709551630n);
-247
View File
@@ -1,247 +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 check_result(bigint, expected)
{
assert(bigint.toString() === expected)
}
function check_result16(bigint, expected)
{
assert(bigint.toString(16) === expected)
}
function check_syntax_error(code)
{
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
}
assert(typeof BigInt("0") == "bigint")
// Test BigInt string parsing and toString
check_syntax_error("BigInt('-0x5')");
check_syntax_error("BigInt('-')");
check_syntax_error("BigInt('00x5')");
check_syntax_error("BigInt('11a')");
check_syntax_error("BigInt('0b2')");
check_syntax_error("BigInt('1n')");
check_result(BigInt("0"), "0")
check_result(BigInt("-0"), "0")
check_result(BigInt("100000000000000000000000000000000000000"), "100000000000000000000000000000000000000")
check_result(BigInt("-1234567890123456789012345678901234567890"), "-1234567890123456789012345678901234567890")
check_result(BigInt("+1"), "1")
check_result(BigInt("+000000000000000000001"), "1")
check_result(BigInt("-000000000000000000000"), "0")
check_result(BigInt("0x00abcdefABCDEF0123456789000000000000000"), "239460437713606077082343926293727858623774720")
check_result(BigInt("0b00100000000000010000000000010000000000010"), "274911469570")
assert(BigInt("100000000000000000000000000000000000000").toString(22) === "2ci67fiek1bkhec5fig7aiii9hf8c")
check_result16(BigInt("239460437713606077082343926293727858623774720"), "abcdefabcdef0123456789000000000000000")
// Test negate
check_result(-BigInt("0"), "0")
check_result(-BigInt("100"), "-100")
check_result(-BigInt("-100"), "100")
check_result(-BigInt("100000000000000000000000000000000000000000000"), "-100000000000000000000000000000000000000000000")
check_result(-BigInt("-100000000000000000000000000000000000000000000"), "100000000000000000000000000000000000000000000")
// Test addition
check_result(BigInt("0") + BigInt("0"), "0")
check_result(BigInt("1") + BigInt("1"), "2")
check_result(BigInt("0") + BigInt("100"), "100")
check_result(BigInt("0") + BigInt("-100"), "-100")
check_result(BigInt("100") + BigInt("0"), "100")
check_result(BigInt("-100") + BigInt("0"), "-100")
check_result(BigInt("100000000000000000000000000000000000000") + BigInt("100000000000000000000000000000000000000"),
"200000000000000000000000000000000000000");
check_result(BigInt("-100000000000000000000000000000000000000") + BigInt("-100000000000000000000000000000000000000"),
"-200000000000000000000000000000000000000");
check_result(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3") + BigInt("0xd"),
"115792089237316195423570985008687907853269984665640564039457584007913129639936");
check_result(BigInt("0xd") + BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3"),
"115792089237316195423570985008687907853269984665640564039457584007913129639936");
check_result(BigInt("100000000000000000000000000000000000000") + BigInt("-100000000000000000000000000000000000000"), "0")
check_result(BigInt("100000000000000000000000000000000000001") + BigInt("-100000000000000000000000000000000000000"), "1")
check_result(BigInt("100000000000000000000000000000000000000") + BigInt("-100000000000000000000000000000000000001"), "-1")
check_result(BigInt("-100000000000000000000000000000000000000") + BigInt("100000000000000000000000000000000000000"), "0")
check_result(BigInt("-100000000000000000000000000000000000001") + BigInt("100000000000000000000000000000000000000"), "-1")
check_result(BigInt("-100000000000000000000000000000000000000") + BigInt("100000000000000000000000000000000000001"), "1")
// Test substraction
check_result(BigInt("0") - BigInt("0"), "0")
check_result(BigInt("2") - BigInt("1"), "1")
check_result(BigInt("0") - BigInt("100"), "-100")
check_result(BigInt("0") - BigInt("-100"), "100")
check_result(BigInt("100") - BigInt("0"), "100")
check_result(BigInt("-100") - BigInt("0"), "-100")
check_result(BigInt("100000000000000000000000000000000000000") - BigInt("-100000000000000000000000000000000000000"),
"200000000000000000000000000000000000000");
check_result(BigInt("-100000000000000000000000000000000000000") - BigInt("100000000000000000000000000000000000000"),
"-200000000000000000000000000000000000000");
check_result(BigInt("100000000000000000000000000000000000000") - BigInt("-1"),
"100000000000000000000000000000000000001");
check_result(BigInt("-100000000000000000000000000000000000000") - BigInt("1"),
"-100000000000000000000000000000000000001");
check_result(BigInt("1") - BigInt("-100000000000000000000000000000000000000"),
"100000000000000000000000000000000000001");
check_result(BigInt("-1") - BigInt("100000000000000000000000000000000000000"),
"-100000000000000000000000000000000000001");
check_result(BigInt("100000000000000000000000000000000000000") - BigInt("100000000000000000000000000000000000000"), "0")
check_result(BigInt("100000000000000000000000000000000000001") - BigInt("100000000000000000000000000000000000000"), "1")
check_result(BigInt("100000000000000000000000000000000000000") - BigInt("100000000000000000000000000000000000001"), "-1")
check_result(BigInt("-100000000000000000000000000000000000000") - BigInt("-100000000000000000000000000000000000000"), "0")
check_result(BigInt("-100000000000000000000000000000000000001") - BigInt("-100000000000000000000000000000000000000"), "-1")
check_result(BigInt("-100000000000000000000000000000000000000") - BigInt("-100000000000000000000000000000000000001"), "1")
// Test multiplication
check_result(BigInt("0") * BigInt("0"), "0")
check_result(BigInt("1000") * BigInt("0"), "0")
check_result(BigInt("0") * BigInt("1000"), "0")
check_result(BigInt("1") * BigInt("100000000000000000000000000000000000000"), "100000000000000000000000000000000000000")
check_result(BigInt("1") * BigInt("-100000000000000000000000000000000000000"), "-100000000000000000000000000000000000000")
check_result(BigInt("-1") * BigInt("100000000000000000000000000000000000000"), "-100000000000000000000000000000000000000")
check_result(BigInt("-1") * BigInt("-100000000000000000000000000000000000000"), "100000000000000000000000000000000000000")
check_result(BigInt("100000000000000000000000000000000000000") * BigInt("1"), "100000000000000000000000000000000000000")
check_result(BigInt("-100000000000000000000000000000000000000") * BigInt("1"), "-100000000000000000000000000000000000000")
check_result(BigInt("100000000000000000000000000000000000000") * BigInt("-1"), "-100000000000000000000000000000000000000")
check_result(BigInt("-100000000000000000000000000000000000000") * BigInt("-1"), "100000000000000000000000000000000000000")
check_result(BigInt("100000000000000000000000000000000000000") * BigInt("100000000000000000000000000000000000000"),
"10000000000000000000000000000000000000000000000000000000000000000000000000000")
check_result(BigInt("100000000000000000000000000000000000000") * BigInt("-100000000000000000000000000000000000000"),
"-10000000000000000000000000000000000000000000000000000000000000000000000000000")
check_result(BigInt("-100000000000000000000000000000000000000") * BigInt("100000000000000000000000000000000000000"),
"-10000000000000000000000000000000000000000000000000000000000000000000000000000")
check_result(BigInt("-100000000000000000000000000000000000000") * BigInt("-100000000000000000000000000000000000000"),
"10000000000000000000000000000000000000000000000000000000000000000000000000000")
// Test divide
try {
BigInt("32") / BigInt("0")
assert(false)
} catch (e) {
assert(e instanceof RangeError)
}
try {
BigInt("32") % BigInt("0")
assert(false)
} catch (e) {
assert(e instanceof RangeError)
}
check_result(BigInt("0") / BigInt("1234"), "0")
check_result(BigInt("0") % BigInt("1234"), "0")
check_result(BigInt("100") / BigInt("70"), "1")
check_result(BigInt("100") % BigInt("70"), "30")
check_result(BigInt("-100") / BigInt("70"), "-1")
check_result(BigInt("-100") % BigInt("70"), "-30")
check_result(BigInt("100") / BigInt("-70"), "-1")
check_result(BigInt("100") % BigInt("-70"), "30")
check_result(BigInt("-100") / BigInt("-70"), "1")
check_result(BigInt("-100") % BigInt("-70"), "-30")
check_result(BigInt("100") / BigInt("100"), "1")
check_result(BigInt("100") % BigInt("100"), "0")
check_result(BigInt("-100") / BigInt("100"), "-1")
check_result(BigInt("-100") % BigInt("100"), "0")
check_result(BigInt("100") / BigInt("-100"), "-1")
check_result(BigInt("100") % BigInt("-100"), "0")
check_result(BigInt("-100") / BigInt("-100"), "1")
check_result(BigInt("-100") % BigInt("-100"), "0")
/* Division by small value. */
check_result(BigInt("100000000000000000000") / BigInt("1000000"), "100000000000000")
check_result(BigInt("100000000000000000000") % BigInt("1000000"), "0")
check_result(BigInt("12345678901234567890") / BigInt("1000000"), "12345678901234")
check_result(BigInt("12345678901234567890") % BigInt("1000000"), "567890")
/* Division by large value. */
check_result(BigInt("100000000000000000000") / BigInt("100000000000000000"), "1000")
check_result(BigInt("100000000000000000000") % BigInt("100000000000000000"), "0")
check_result(BigInt("12345678901234567890123456789012345678901234567890123456789012345678901234567890") / BigInt("10000000000000000000000000000000000000"),
"1234567890123456789012345678901234567890123")
check_result(BigInt("12345678901234567890123456789012345678901234567890123456789012345678901234567890") % BigInt("10000000000000000000000000000000000000"),
"4567890123456789012345678901234567890")
check_result16(BigInt("0xffffffffffffffffffffffff") / BigInt("0x100000000"), "ffffffffffffffff")
check_result16(BigInt("0xffffffffffffffffffffffff") % BigInt("0x100000000"), "ffffffff")
/* Triggers a corner case. */
check_result(BigInt("170141183420855150493001878992821682176") / BigInt("39614081266355540842216685573"), "4294967293")
check_result(BigInt("170141183420855150493001878992821682176") % BigInt("39614081266355540842216685573"), "39614081266355540837921718287")
// Test shift
check_result(BigInt("0") << BigInt("10000000"), "0")
check_result(BigInt("0") >> BigInt("10000000"), "0")
check_result(BigInt("10000000") << BigInt("0"), "10000000")
check_result(BigInt("10000000") >> BigInt("0"), "10000000")
check_result(BigInt("4096") << BigInt("2"), "16384")
check_result(BigInt("4096") << BigInt("-2"), "1024")
check_result(BigInt("4096") >> BigInt("2"), "1024")
check_result(BigInt("4096") >> BigInt("-2"), "16384")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("1"), "11fdebf9fffdebf9fffdebf9fffdebf9fe")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("19"), "47f7afe7fff7afe7fff7afe7fff7afe7f80000")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("31"), "47f7afe7fff7afe7fff7afe7fff7afe7f80000000")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("32"), "8fef5fcfffef5fcfffef5fcfffef5fcff00000000")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("51"), "47f7afe7fff7afe7fff7afe7fff7afe7f8000000000000")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("63"), "47f7afe7fff7afe7fff7afe7fff7afe7f8000000000000000")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("64"), "8fef5fcfffef5fcfffef5fcfffef5fcff0000000000000000")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("1"), "47f7afe7fff7afe7fff7afe7fff7afe7f")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("19"), "11fdebf9fffdebf9fffdebf9fffde")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("31"), "11fdebf9fffdebf9fffdebf9ff")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("32"), "8fef5fcfffef5fcfffef5fcff")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("51"), "11fdebf9fffdebf9fffde")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("63"), "11fdebf9fffdebf9ff")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("64"), "8fef5fcfffef5fcff")
check_result16(-BigInt("0xff") >> BigInt("8"), "-1")
check_result16(-BigInt("0xff") >> BigInt("1000"), "-1")
check_result16(-BigInt("0xff") >> BigInt("7"), "-2")
check_result16(-BigInt("0xff00000000") >> BigInt("32"), "-ff")
check_result16(-BigInt("0xff80000000") >> BigInt("32"), "-100")
check_result16(-BigInt("0xff00000000000000000000000000000000") >> BigInt("128"), "-ff")
check_result16(-BigInt("0xff80000000000000000000000000000000") >> BigInt("128"), "-100")
check_result16(-BigInt("0xfe00000000000000000000000000000000") >> BigInt("129"), "-7f")
check_result16(-BigInt("0xff00000000000000000000000000000000") >> BigInt("129"), "-80")
check_result16(BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") >> BigInt("10000000000000000000000000"), "0")
try {
BigInt("0x8fef5fcfffef5fcfffef5fcfffef5fcff") << BigInt("10000000000000000000000000");
assert(false)
} catch (e) {
assert(e instanceof RangeError)
}
-61
View File
@@ -1,61 +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.
*/
try {
new BigInt("1")
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
function check_type_error (code)
{
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
}
check_type_error("+BigInt('0')")
check_type_error("BigInt('1') + 1")
check_type_error("BigInt('2') - 2")
check_type_error("BigInt('3') * 3")
check_type_error("BigInt('4') / 4")
check_type_error("BigInt('5') % 5")
check_type_error("BigInt('6') ** 6")
check_type_error("1 + BigInt('1')")
check_type_error("2 - BigInt('2')")
check_type_error("3 * BigInt('3')")
check_type_error("4 / BigInt('4')")
check_type_error("5 % BigInt('5')")
check_type_error("6 ** BigInt('6')")
check_type_error("BigInt('1') & 1")
check_type_error("BigInt('2') | 2")
check_type_error("BigInt('3') ^ 3")
check_type_error("BigInt('4') << 4")
check_type_error("BigInt('5') >> 5")
check_type_error("BigInt('6') >>> 6")
check_type_error("1 & BigInt('1')")
check_type_error("2 | BigInt('2')")
check_type_error("3 ^ BigInt('3')")
check_type_error("4 << BigInt('4')")
check_type_error("5 >> BigInt('5')")
check_type_error("6 >>> BigInt('6')")
-56
View File
@@ -1,56 +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 check_result(bigint, expected)
{
assert(bigint.toString() === expected)
}
function check_error (code, error_type)
{
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof error_type)
}
}
check_error("BigInt(undefined)", TypeError)
check_error("BigInt(null)", TypeError)
check_error("BigInt(Symbol())", TypeError)
check_error("BigInt(0.25)", RangeError)
check_error("BigInt(-0.25)", RangeError)
check_error("BigInt(-10000000.25)", RangeError)
check_error("BigInt(4503599627370495.5)", RangeError)
check_error("BigInt(NaN)", RangeError)
check_error("BigInt(Infinity)", RangeError)
check_result(BigInt(true), "1")
check_result(BigInt(false), "0")
check_result(BigInt({ valueOf() { return "0x100" } }), "256")
check_result(BigInt(0), "0")
check_result(BigInt(-0), "0")
check_result(BigInt(8192), "8192")
check_result(BigInt(-0xffffffffff), "-1099511627775")
check_result(BigInt(0x1fffffffffffff), "9007199254740991")
check_result(BigInt(-4503599627370496), "-4503599627370496")
check_result(BigInt(4503599627370496.5), "4503599627370496")
check_result(BigInt(9007199254740991.5), "9007199254740992")
check_result(BigInt(0x1fffffffffffff * (2 ** 70)), "10633823966279325802638835764831453184")
check_result(BigInt(-0x1fffffffffffff * (2 ** 128)), "-3064991081731777376434327133362154903862870812598992896")
-183
View File
@@ -1,183 +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.
*/
/* Boolean. */
assert(!BigInt("0") === true)
assert(!BigInt("1") === false)
assert(!BigInt("-1") === false)
/* Strict equal. */
assert(BigInt("0") === BigInt("0"))
assert(BigInt("-77") === BigInt("-77"))
assert(!(BigInt("-77") !== BigInt("-77")))
assert(!(Object(BigInt("-77")) === BigInt("-77")))
assert(BigInt("-77") !== Object(BigInt("-77")))
assert(BigInt("0xffffffffffffffffffffffffffffffff") === BigInt("0xffffffffffffffffffffffffffffffff"))
assert(!(BigInt("0xfffffffffffffffffffffffffffffffe") === BigInt("0xffffffffffffffffffffffffffffffff")))
assert(BigInt("0x100000000000000000000000000000000") !== BigInt("0xffffffffffffffffffffffffffffffff"))
assert(!(BigInt("1234") === 1234))
assert(-4567 !== BigInt("-4567"))
/* Equal. */
assert(BigInt("0x100") == BigInt("256"))
assert(BigInt("-77") == "-77")
assert("168" == BigInt("168"))
assert(!("0xffffffffffffffffffffffffffffffff" != BigInt("0xffffffffffffffffffffffffffffffff")))
assert(BigInt("0x1000") == 0x1000)
assert(468123 == BigInt("468123"))
assert(!(BigInt("100000000") == 100000000.5))
assert(-0.125 != BigInt("0"))
assert(!("InvalidBigIntString" == BigInt("100000000")))
assert(BigInt("100000000") != "10000 0000")
assert(BigInt("0") == 0)
assert(!(-0 != BigInt("0")))
assert(!(BigInt("0") == 0.0000152587890625))
assert(0.0000152587890625 != BigInt("0"))
assert(!(BigInt("100000000") == NaN))
assert(NaN != BigInt("-100000000"))
assert(!(BigInt("100000000000000000000000000") == Infinity))
assert(Infinity != BigInt("100000000000000000000000000"))
/* Relational. */
assert(!(BigInt("1234") < BigInt("1234")))
assert(BigInt("1234") >= BigInt("1234"))
assert(BigInt("1234") <= BigInt("1234"))
assert(!(BigInt("1234") > BigInt("1234")))
assert(BigInt("1234") < BigInt("1235"))
assert(!(BigInt("1234") >= BigInt("1235")))
assert(BigInt("1234") <= BigInt("1235"))
assert(!(BigInt("1234") > BigInt("1235")))
assert(!(BigInt("123456789012345678901234567890") < "123456789012345678901234567890"))
assert(BigInt("123456789012345678901234567890") >= "123456789012345678901234567890")
assert(BigInt("123456789012345678901234567890") <= "123456789012345678901234567890")
assert(!(BigInt("123456789012345678901234567890") > "123456789012345678901234567890"))
assert(!("0x1234567890abcdef1234567890abcdef" < BigInt("0x1234567890abcdef1234567890abcdef")))
assert("0x1234567890abcdef1234567890abcdef" >= BigInt("0x1234567890abcdef1234567890abcdef"))
assert("0x1234567890abcdef1234567890abcdef" <= BigInt("0x1234567890abcdef1234567890abcdef"))
assert(!("0x1234567890abcdef1234567890abcdef" > BigInt("0x1234567890abcdef1234567890abcdef")))
assert(!("Invalid" < BigInt("100")))
assert(!("Invalid" >= BigInt("100")))
assert(!("Invalid" <= BigInt("100")))
assert(!("Invalid" > BigInt("100")))
assert(!(BigInt("0") < "NotABigInt"))
assert(!(BigInt("0") >= "NotABigInt"))
assert(!(BigInt("0") <= "NotABigInt"))
assert(!(BigInt("0") > "NotABigInt"))
assert(!(BigInt("0") < 0))
assert(BigInt("0") >= 0)
assert(BigInt("0") <= 0)
assert(!(BigInt("0") > 0))
assert(!(-0 < BigInt("0")))
assert(-0 >= BigInt("0"))
assert(-0 <= BigInt("0"))
assert(!(-0 > BigInt("0")))
assert(BigInt("0") < 67)
assert(!(BigInt("0") > 67))
assert(!(BigInt("0") < -0.125))
assert(BigInt("0") > -0.125)
assert(!(BigInt("7") < NaN))
assert(!(BigInt("7") >= NaN))
assert(!(BigInt("7") <= NaN))
assert(!(BigInt("7") > NaN))
assert(!(Infinity < BigInt("1000000000000000000000000000000")))
assert(!(Infinity <= BigInt("1000000000000000000000000000000")))
assert(Infinity >= BigInt("1000000000000000000000000000000"))
assert(Infinity > BigInt("1000000000000000000000000000000"))
assert(-Infinity < BigInt("1000000000000000000000000000000"))
assert(-Infinity <= BigInt("1000000000000000000000000000000"))
assert(!(-Infinity >= BigInt("1000000000000000000000000000000")))
assert(!(-Infinity > BigInt("1000000000000000000000000000000")))
assert(BigInt("-10000") < 1)
assert(BigInt("-10000") <= 1)
assert(!(BigInt("-10000") >= 1))
assert(!(BigInt("-10000") > 1))
assert(!(1 < BigInt("-12345678")))
assert(!(1 <= BigInt("-12345678")))
assert(1 >= BigInt("-12345678"))
assert(1 > BigInt("-12345678"))
assert(!(BigInt("1") < 0.5))
assert(!(BigInt("1") <= 0.5))
assert(BigInt("1") >= 0.5)
assert(BigInt("1") > 0.5)
assert(!(-0.5 < BigInt("-1")))
assert(!(-0.5 <= BigInt("-1")))
assert(-0.5 >= BigInt("-1"))
assert(-0.5 > BigInt("-1"))
assert(!(BigInt("0x1000000000000000000000000000000") < 0x100000))
assert(!(BigInt("0x1000000000000000000000000000000") <= 0x100000))
assert(BigInt("0x1000000000000000000000000000000") >= 0x100000)
assert(BigInt("0x1000000000000000000000000000000") > 0x100000)
assert(-0x1000000000000000000000000000000 < BigInt("-1234"))
assert(-0x1000000000000000000000000000000 <= BigInt("-1234"))
assert(!(-0x1000000000000000000000000000000 >= BigInt("-1234")))
assert(!(-0x1000000000000000000000000000000 > BigInt("-1234")))
assert(0x1234567880000000000000000000000 < BigInt("0x1234567890000000000000000000000"))
assert(0x1234567880000000000000000000000 <= BigInt("0x1234567890000000000000000000000"))
assert(!(0x1234567880000000000000000000000 > BigInt("0x1234567890000000000000000000000")))
assert(!(0x1234567880000000000000000000000 >= BigInt("0x1234567890000000000000000000000")))
assert(-BigInt("0x1234567890000000000000000000000") < -0x1234567880000000000000000000000)
assert(-BigInt("0x1234567890000000000000000000000") <= -0x1234567880000000000000000000000)
assert(!(-BigInt("0x1234567890000000000000000000000") >= -0x1234567880000000000000000000000))
assert(!(-BigInt("0x1234567890000000000000000000000") > -0x1234567880000000000000000000000))
// True because of rounding
assert(0x1234567890000000000000000000001 < BigInt("0x1234567890000000000000000000001"))
assert(0x1234567890000000000000000000001 <= BigInt("0x1234567890000000000000000000001"))
assert(!(0x1234567890000000000000000000001 >= BigInt("0x1234567890000000000000000000001")))
assert(!(0x1234567890000000000000000000001 > BigInt("0x1234567890000000000000000000001")))
assert(-BigInt("0x1234567890000000000000000000001") < -0x1234567890000000000000000000001)
assert(-BigInt("0x1234567890000000000000000000001") <= -0x1234567890000000000000000000001)
assert(!(-BigInt("0x1234567890000000000000000000001") >= -0x1234567890000000000000000000001))
assert(!(-BigInt("0x1234567890000000000000000000001") > -0x1234567890000000000000000000001))
assert(!(1.0000152587890625 < BigInt("1")))
assert(!(1.0000152587890625 <= BigInt("1")))
assert(1.0000152587890625 >= BigInt("1"))
assert(1.0000152587890625 > BigInt("1"))
assert(!(BigInt("-1") < -1.0000152587890625))
assert(!(BigInt("-1") <= -1.0000152587890625))
assert(BigInt("-1") >= -1.0000152587890625)
assert(BigInt("-1") > -1.0000152587890625)
-57
View File
@@ -1,57 +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 check_syntax_error(code)
{
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
}
check_syntax_error("1N")
check_syntax_error("3.5n")
check_syntax_error("3e10n")
check_syntax_error("3e+10n")
check_syntax_error("0xn")
check_syntax_error("0on")
check_syntax_error("0bn")
check_syntax_error("0777n")
check_syntax_error("00777n")
check_syntax_error("0x1 n")
assert(0n == 0n)
assert(0n == -0n)
assert(12n == 12n)
assert(123456789012345678901234567890123456789012345678901234567890n == 123456789012345678901234567890123456789012345678901234567890n)
assert(12n != -12n)
assert(123456789012345678901234567890123456789012345678901234567890n != -123456789012345678901234567890123456789012345678901234567890n)
assert(0xffn == 255n)
assert(0o77777n == 0x7fffn)
assert(255n.toString(16) == "ff")
var o = { 12n : "data" }
assert(o[12] === "data")
var c = class C { static 19n () { return "BigInt" } }
assert(c[19]() === "BigInt")
function f(p, q) {
assert(p + q === 5000n)
}
f(-1000n, 6000n)
-54
View File
@@ -1,54 +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.
*/
// Test bitwise 'and' operation
assert((0n & 0n) === 0n)
assert((0x12345678n & 0n) === 0n)
assert((0n & 0x12345678n) === 0n)
assert((0xff00ff00ff00ff00ff00n & 0xff00ff00ff00ff00ffn) === 0n)
assert((0x12345678ffffffff12345678ffffffffn & 0xffff87654321n) === 0x567887654321n)
assert((0xf56cd2479efcdn & 0x56cdf23bc02134e3bdc56f43297be4c27n) === 0x6540004384c05n)
assert((0x45c308bd83cf279n & -0x100000000n) === 0x45c308b00000000n)
assert((-0x10000000000000000n & 0xffffffffffffffffn) === 0n)
assert((-0x11234567890abcdefn & 0xffffffffffffffffffffn) === 0xfffeedcba9876f543211n)
assert((-0x10000000000000n & -0x10000000000000n) === -0x10000000000000n)
assert((-0x100000000000000001n & -0x1n) === -0x100000000000000001n)
// Test bitwise 'or' operation
assert((0n | 0n) === 0n)
assert((0x123456789abcdefn | 0n) === 0x123456789abcdefn)
assert((0n | 0x123456789abcdefn) === 0x123456789abcdefn)
assert((0xaa00bb00cc00dd00ee00n | 0xff00ee00dd00cc00bbn) === 0xaaffbbeeccddddcceebbn);
assert((0xfedcba09876543210fedcba09876543210n | 0x7n) === 0xfedcba09876543210fedcba09876543217n)
assert((0x8n | 0xfedcba09876543210fedcba09876543210n) === 0xfedcba09876543210fedcba09876543218n)
assert((-0xc34bd5f946c7a92b69b3a96cd7c2a12n | 0xfcbacfbn) === -0xc34bd5f946c7a92b69b3a96c0340201n)
assert((-0xb314c297ba3n | 0xfeacb00000000n) === -0x1304c297ba3n)
assert((-0x74b186cd308b377cb23n | -0x5cba7935b213cd657d937c42975de63802a7b92cd49an) === -0x74900280200b124c001n)
assert((-0x10000000000000000n | -0x100000000000000000000000000000000n) === -0x10000000000000000n)
// Test bitwise 'xor' operation
assert((0n ^ 0n) === 0n)
assert((0x123456789abcdefn ^ 0n) === 0x123456789abcdefn)
assert((0n ^ 0x123456789abcdefn) === 0x123456789abcdefn)
assert((0x74b186cd308b355cb23cd28cd75n ^ 0x74b186cd308b355cb23cd28cd75n) === 0n)
assert((0xff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ffn ^ 0xf0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0fn) === 0xff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff0n)
assert((0x31988644a57e18n ^ 0xb2303b6f2efcb4de7761c01622440f9d985d07dbfe03c9f1n) === 0xb2303b6f2efcb4de7761c01622440f9d986c9f5dbaa6b7e9n)
assert((-0xd858541b8eb3e6ae247b1f84dbd8cc2db66n ^ 0x0811a0e70710fcf965n) === -0xd858541b8eb3e6ae24fa058aaba9c3e2201n)
assert((0x38d00faa3f33n ^ -0x89c40cdc4a064dcd8b3663feb322026dn) === -0x89c40cdc4a064dcd8b365b2ebc883d60n)
assert((-0x66cb3001b88361a25b8715922n ^ -0x66cb3001b88361a25b8715922n) === 0n)
assert((-0x893bff556397300afe6411d8727c0aaffn ^ -0xef69f24dfcd1447397d62217c6ad2n) === 0x893b103c91daccdbba17860e506bcc02fn)
-115
View File
@@ -1,115 +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.
*/
// Bitwise not
assert(~BigInt("0") === -1n)
assert(~BigInt("-1") === 0n)
assert(~BigInt("0xffffffff") === -0x100000000n)
assert(~BigInt("0x100000000") === -0x100000001n)
assert(~BigInt("0x10000ffff") === -0x100010000n)
assert(~(-BigInt("0xffffffff")) === 0xfffffffen)
assert(~(-BigInt("0x100000000")) === 0xffffffffn)
assert(~(-BigInt("0x10000ffff")) === 0x10000fffen)
assert(~BigInt("0xffffffffffffffff") === -0x10000000000000000n)
assert(~BigInt("0xffffffffffffffffffffffffffffffff") === -0x100000000000000000000000000000000n)
assert(~BigInt("0x100000000000000000000000000000000") === -0x100000000000000000000000000000001n)
assert(~BigInt("0x100000000000000ffffffffffffffffff") === -0x100000000000001000000000000000000n)
assert(~(-BigInt("0xffffffffffffffff")) === 0xfffffffffffffffen)
assert(~(-BigInt("0xffffffffffffffffffffffffffffffff")) === 0xfffffffffffffffffffffffffffffffen)
assert(~(-BigInt("0x100000000000000000000000000000000")) === 0xffffffffffffffffffffffffffffffffn)
assert(~(-BigInt("0xffffffffffffff000000000000000000")) === 0xfffffffffffffeffffffffffffffffffn)
// Increase
var a = 0n
assert(++a === 1n)
assert(a === 1n)
a = -1n
assert(++a === 0n)
assert(a === 0n)
a = 1n
assert(++a === 2n)
assert(a === 2n)
a = 0xffffffffn
assert(++a === 0x100000000n)
assert(a === 0x100000000n)
a = { b:0xffffffffffffffffn }
assert(++a.b === 0x10000000000000000n)
assert(a.b === 0x10000000000000000n)
a = 0xffffffffffffffffffffffffffffffffn
assert(a++ === 0xffffffffffffffffffffffffffffffffn)
assert(a === 0x100000000000000000000000000000000n)
a = { b:0x100000000000000ffffffffffffffffffn }
assert(a.b++ === 0x100000000000000ffffffffffffffffffn)
assert(a.b === 0x100000000000001000000000000000000n)
a = -0x10000000000000001n;
for (var i = 0; i < 1; i++, a++) ;
assert(a === -0x10000000000000000n)
a = { b:-0x100000000000001000000000000000000n }
for (var i = 0; i < 1; i++, ++a.b) ;
assert(a.b === -0x100000000000000ffffffffffffffffffn)
// Decrease
a = 0n
assert(--a === -1n)
assert(a === -1n)
a = 1n
assert(--a === 0n)
assert(a === 0n)
a = -1n
assert(--a === -2n)
assert(a === -2n)
a = 0x100000000n
assert(--a === 0xffffffffn)
assert(a === 0xffffffffn)
a = -0xffffffffffffffffn
assert(a-- === -0xffffffffffffffffn)
assert(a === -0x10000000000000000n)
a = { b:0x10000000000000000n }
assert(--a.b === 0xffffffffffffffffn)
assert(a.b === 0xffffffffffffffffn)
a = 0x100000000000000000000000000000000n
assert(a-- === 0x100000000000000000000000000000000n)
assert(a === 0xffffffffffffffffffffffffffffffffn)
a = { b:0x100000000000001000000000000000000n }
assert(a.b-- === 0x100000000000001000000000000000000n)
assert(a.b === 0x100000000000000ffffffffffffffffffn)
a = 0x10000000000000001n;
for (var i = 0; i < 1; i++, a--) ;
assert(a === 0x10000000000000000n)
a = { b:-0x100000000000000ffffffffffffffffffn }
for (var i = 0; i < 1; i++, --a.b) ;
assert(a.b === -0x100000000000001000000000000000000n)
-55
View File
@@ -1,55 +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.
*/
// Exponentiation
try {
12n ** -7n
assert(false)
} catch (e) {
assert(e instanceof RangeError)
}
assert((0n ** 0n) === 1n)
assert((1n ** 0n) === 1n)
assert(((-2n) ** 0n) === 1n)
assert((1000000000000000000000000000000000n ** 0n) === 1n)
assert(((-1000000000000000000000000000000000n) ** 0n) === 1n)
assert((1n ** 1n) === 1n)
assert((1n ** 10000000000000000000000000000000n) === 1n)
assert(((-1n) ** 1n) === -1n)
assert(((-1n) ** 10000000000000000000000000000000n) === 1n)
assert(((-1n) ** 10000000000000000000000000000001n) === -1n)
assert((2n ** 10n) === 1024n)
assert((2n ** 11n) === 2048n)
assert(((-2n) ** 10n) === 1024n)
assert(((-2n) ** 11n) === -2048n)
assert((2n ** 64n) === 0x10000000000000000n)
assert((2n ** 65n) === 0x20000000000000000n)
assert(((-2n) ** 64n) === 0x10000000000000000n)
assert(((-2n) ** 65n) === -0x20000000000000000n)
assert((2n ** 190n) === 0x400000000000000000000000000000000000000000000000n)
assert((2n ** 191n) === 0x800000000000000000000000000000000000000000000000n)
assert(((-2n) ** 190n) === 0x400000000000000000000000000000000000000000000000n)
assert(((-2n) ** 191n) === -0x800000000000000000000000000000000000000000000000n)
assert((103n ** 32n) === 25750827556851106532658069028441289322166445432839581773436522241n)
assert((103n ** 31n) === 250008034532535014880175427460595041962781023619801764790645847n)
assert(((-79n) ** 32n) === 5297450670659957549009604563595170759963655420038456036451841n)
assert(((-79n) ** 31n) === -67056337603290601886197526121457857721058929367575392866479n)
-42
View File
@@ -1,42 +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.
*/
assert(Number(0n) === 0)
assert(Number(1n) === 1)
assert(Number(2n) === 2)
assert(Number(0x100n) === 256)
assert(Number(-1n) === -1)
assert(Number(-2n) === -2)
assert(Number(-0x100n) === -256)
assert(Number(0x1fffffffffffffn) === 0x1fffffffffffff)
assert(Number(-0x3fffffffffffffn) === -0x40000000000000)
assert(Number(1000n ** 1000n) === Number.POSITIVE_INFINITY)
assert(Number((-1000n) ** 1001n) === Number.NEGATIVE_INFINITY)
// Rounding to even
assert(Number(0x80000000000004n) === 0x80000000000000)
assert(Number(0x80000000000008n) === 0x80000000000008)
assert(Number(0x8000000000000cn) === 0x80000000000010)
assert(Number(0x80000000000004n) === 0x80000000000000)
assert(Number(0x80000000000006n) === 0x80000000000008)
assert(Number(0x800000000000f400000000000000000000000000000000n) === 0x800000000000f000000000000000000000000000000000)
assert(Number(0x800000000000f400000000000000000000000000000001n) === 0x800000000000f800000000000000000000000000000000)
// Construct
assert((new Number(0n)).valueOf() === 0)
assert((new Number(-3256n)).valueOf() == -3256)
-52
View File
@@ -1,52 +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);
}
}
// Test with invalid literals
checkSyntaxError("0c");
checkSyntaxError("0b");
checkSyntaxError("0b0123456");
checkSyntaxError("0b2");
checkSyntaxError("0C");
checkSyntaxError("0B");
checkSyntaxError("0B2");
checkSyntaxError("000b01010101");
checkSyntaxError("010b01010101");
checkSyntaxError("11 0b01010101");
// Test with valid literals
assert(0b111 === 7);
assert(0b111110111 === 503);
assert(0b111101010101 === 3925);
assert(0b00000000000001 === 1);
assert(0b00000000000000 === 0);
assert(0b1101001 === parseInt ("1101001", 2));
assert(0B111 === 7);
assert(0B111110111 === 503);
assert(0B111101010101 === 3925);
assert(0B00000000000001 === 1);
assert(0B00000000000000 === 0);
assert(0B1101001 === parseInt ("1101001", 2));
-56
View File
@@ -1,56 +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 check_syntax_error (script)
{
try
{
eval (script);
assert (false);
}
catch (e)
{
assert (e instanceof SyntaxError);
}
}
eval("function f(){}; var f;");
eval("var f; function f(){};");
eval("function f(){}; { var f; }")
eval("{ var f; } function f(){};")
eval("{ function f(){}; } var f;")
eval("var f; { function f(){}; }")
check_syntax_error ("{ function f(){}; var f; }");
check_syntax_error ("{ var f; function f(){}; }");
eval("{ { function f(){}; } var f; }")
eval("{ var f; { function f(){}; } }")
check_syntax_error ("{ function f(){}; { var f; } }")
check_syntax_error ("{ { var f; } function f(){}; }")
eval("{ { function f(){}; } { var f; } }")
eval("{ { var f; } { function f(){}; } }")
eval("function g(){ function f(){}; var f; }")
eval("function g(){ var f; function f(){}; }")
eval("function g(){ function f(){}; { var f; } }")
eval("function g(){ { var f; } function f(){}; }")
eval("function g(){ { function f(){}; } var f; }")
eval("function g(){ var f; { function f(){}; } }")
@@ -1,48 +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 test_failed = false;
function verifyConfigurableAccessor (obj, name, string) {
let prop = Object.getOwnPropertyDescriptor (obj, name);
if (prop.get && !prop.configurable) {
print (string + " should be configurable, but wasn't");
test_failed = true;
}
}
for (let builtin_name of Reflect.ownKeys (this)) {
let builtin_obj = this[builtin_name];
if (builtin_name[0] === builtin_name[0].toUpperCase () && typeof builtin_obj == "function") {
for (let prop of Reflect.ownKeys (builtin_obj)) {
verifyConfigurableAccessor (builtin_obj, prop, builtin_name + "." + prop.toString ());
}
let builtin_proto = builtin_obj.prototype;
if (builtin_proto) {
for (let prop of Reflect.ownKeys (builtin_proto)) {
verifyConfigurableAccessor (builtin_proto, prop, builtin_name + ".prototype." + prop.toString ());
}
}
builtin_proto = Reflect.getPrototypeOf (builtin_obj);
if (builtin_proto !== Function.prototype) {
for (let prop of Reflect.ownKeys (builtin_proto.prototype)) {
verifyConfigurableAccessor (builtin_proto.prototype, prop, builtin_name + ".[[Prototype]].prototype." + prop.toString ());
}
}
}
}
assert (!test_failed);
-60
View File
@@ -1,60 +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 prototypes = [
Date.prototype,
RegExp.prototype,
Error.prototype,
EvalError.prototype,
RangeError.prototype,
ReferenceError.prototype,
SyntaxError.prototype,
TypeError.prototype,
URIError.prototype
]
for (proto of prototypes) {
assert (Object.prototype.toString.call (proto) === '[object Object]');
}
try {
Date.prototype.valueOf();
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
RegExp.prototype.exec("");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
try {
RegExp.prototype.compile("a", "u");
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
assert (RegExp.prototype.source === '(?:)');
assert (RegExp.prototype.global === undefined);
assert (RegExp.prototype.ignoreCase === undefined);
assert (RegExp.prototype.multiline === undefined);
assert (RegExp.prototype.sticky === undefined);
assert (RegExp.prototype.unicode === undefined);
assert (RegExp.prototype.dotAll === undefined);
assert (RegExp.prototype.flags === '');
-182
View File
@@ -1,182 +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 check_syntax_error(code)
{
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
}
function check_property(obj, name, value)
{
property = Object.getOwnPropertyDescriptor(obj, name)
assert(typeof property === "object")
assert(property.value === value)
}
check_syntax_error("class C { get a = 5 }");
check_syntax_error("class C { id1 id2 }");
check_syntax_error("class C { a = 5,6 }");
check_syntax_error("class C { set\na = 6 }");
check_syntax_error("class C { constructor }");
check_syntax_error("class C { static constructor }");
check_syntax_error("class C { constructor = 1 }");
check_syntax_error("class C { static constructor = 1 }");
check_syntax_error("class C { f = arguments }");
check_syntax_error("class C { static f = a\\u0072guments }");
check_syntax_error("class C { f = () => arguments }");
check_syntax_error("class C { f = arguments => 1 }");
check_syntax_error("class C { f = ([arguments]) => 1 }");
check_syntax_error("new class { f = eval('arguments') }");
check_syntax_error("new class { f = eval('arguments => 1') }");
var res = 10
var counter = 0
function f1() {
counter++
return 5
}
var C1 = class {
get = "a" + f1()
static; set; a = () => Math.cos(0)
v\u0061r
f\u006fr = () => this
arguments = this
}
res = new C1
check_property(res, "get", "a5")
check_property(res, "static", undefined)
check_property(res, "set", undefined)
assert(res.a() === 1)
check_property(res, "var", undefined)
assert(res.for() === res)
assert(res.arguments === res)
class C2 {
constructor(a = this.x, b = this.y) {
assert(a === undefined)
assert(b === undefined)
check_property(this, 'x', 11)
check_property(this, 'y', "ab")
}
x = 5 + 6
y = "a" + 'b'
}
res = new C2
class C3 {
constructor() {
assert(this.x === 1)
return { z:"zz" }
}
x = 1
}
class C4 extends C3 {
constructor() {
super()
assert(Object.getOwnPropertyDescriptor(this, "x") === undefined)
check_property(this, "y", 2)
check_property(this, "z", "zz")
}
y = 2
}
new C4
var o = {}
class C5 extends C3 {
'pr op' = o
3 = true
}
res = new C5
assert(Object.getOwnPropertyDescriptor(res, "x") === undefined)
check_property(res, "pr op", o)
check_property(res, "3", true)
check_property(res, "z", "zz")
class C6 {
a= () => this
b= this
}
class C7 extends C6 {
c= () => this
d= this
}
count = 0
class C8 extends C7 {
constructor() {
count++
super()
}
e= () => this
f= this
}
var res = new C8
assert(res.a() === res)
assert(res.b === res)
assert(res.c() === res)
assert(res.d === res)
assert(res.e() === res)
assert(res.f === res)
count = 0
class C9 {
a=assert(++count === 5)
a=assert(++count === 6)
a=assert(++count === 7)
a=assert(++count === 8)
static a=assert(++count === 1)
static a=assert(++count === 2)
static a=assert(++count === 3)
static a=assert(++count === 4)
}
assert(count === 4)
new C9
assert(count === 8)
count = 0
class C10 {
[(assert(++count == 1), "aa")] = assert(++count == 5);
[(assert(++count == 2), "bb")] = assert(++count == 6);
cc = assert(++count == 7);
[(assert(++count == 3), "aa")] = assert(++count == 8);
[(assert(++count == 4), "bb")] = assert(++count == 9);
}
assert(count == 4)
assert(Reflect.ownKeys(new C10).toString() === "aa,bb,cc");
assert(count == 9)
res = "p"
class C11 {
p1 = assert(Reflect.ownKeys(this).toString() === "");
[res + 2] = assert(Reflect.ownKeys(this).toString() === "p1");
[res + 1] = assert(Reflect.ownKeys(this).toString() === "p1,p2");
p3 = assert(Reflect.ownKeys(this).toString() === "p1,p2");
[res + 4] = assert(Reflect.ownKeys(this).toString() === "p1,p2,p3");
}
new C11
-139
View File
@@ -1,139 +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 count = 0
class C1 {
error = assert(++count === 1)
error = function() { throw 40.5 }()
}
try {
new C1
assert(false)
} catch(e) {
assert(e === 40.5)
assert(count === 1)
}
count = 0
class C2 {
constructor(a = assert(++count === 1)) {}
error = function() { throw "Err" }()
error = assert(false)
}
try {
new C2
assert(false)
} catch(e) {
assert(e === "Err")
assert(count === 1)
}
count = 0
var o = {}
class C3 extends class {
error = function() { throw o }()
} {
constructor() {
assert(++count === 1)
super()
assert(false)
}
}
try {
new C3
assert(false)
} catch (e) {
assert(e === o)
assert(count === 1)
}
count = 0
class C4 {
constructor() {
assert(++count === 2)
}
a = assert(++count === 1)
}
class C5 extends C4 {
ok = assert(++count === 3)
error = function() { assert(++count === 4); throw "Except" }()
never = assert(false)
}
try {
new C5
assert(false)
} catch (e) {
assert(e === "Except")
assert(count === 4)
}
count = 0
o = []
class C6 {
a = assert(++count === 2)
}
class C7 extends C6 {
constructor() {
assert(++count === 1)
eval('super()')
assert(false)
}
ok = assert(++count === 3)
error = function() { assert(++count === 4); throw o }()
never = assert(false)
}
try {
new C7
assert(false)
} catch (e) {
assert(e === o)
assert(count === 4)
}
var res
class C8 {
/* Create a non-configurable accessor */
a = (res = this, Object.defineProperty(this, "b", { get() {} }));
b = 6
}
try {
new C8
assert(false)
} catch(e) {
assert(e instanceof TypeError)
assert(Reflect.ownKeys(res).toString() === "b,a")
}
class C9 {
["p" + 1]
["p" + 2] = (res = this, Object.freeze(this));
p3
}
try {
new C9
assert(false)
} catch(e) {
assert(e instanceof TypeError)
assert(Reflect.ownKeys(res).toString() === "p1")
}
-83
View File
@@ -1,83 +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 check_property(obj, name, value)
{
property = Object.getOwnPropertyDescriptor(obj, name)
assert(typeof property === "object")
assert(property.value === value)
}
var o = {}
var name = "Pro"
var res = 0
var counter = 0
function f1() {
counter++
}
class C1 {
static
v\u0061r
static Prop =
res
=
"msg"
static
Prop
=
f1()
static [name + "p"] = (f1(), o)
static 22 = 3 * 4 ;static 23 = 5 + 6
static 'a b'
}
check_property(C1, "var", undefined)
check_property(C1, "Prop", o)
check_property(C1, 22, 12)
check_property(C1, 23, 11)
check_property(C1, "a b", undefined)
assert(res === "msg")
assert(counter === 2)
counter = 0
class C2 {
static a = (assert(++counter === 6), "x")
static [(assert(++counter === 1), "b")]
static [(assert(++counter === 2), "f")]() {}
static [(assert(++counter === 3), "c")] = (assert(++counter === 7), this);
[(assert(++counter === 4), "a")]
static [(assert(++counter === 5), "d")];static e = (assert(++counter === 8), C2)
}
assert(counter === 8)
check_property(C2, "a", "x")
check_property(C2, "b", undefined)
check_property(C2, "c", C2)
check_property(C2, "d", undefined)
check_property(C2, "e", C2)
res = new C2
check_property(res, "a", undefined)
let C3 = class C4 {
static f() {}
static xx = C4
static yy = this
}
assert(Reflect.ownKeys(C3).toString() === "length,name,prototype,f,xx,yy")
check_property(C3, "xx", C3)
check_property(C3, "yy", C3)
-82
View File
@@ -1,82 +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.
try {
{
A;
class A { }
}
assert(false)
} catch (e) {
assert(e instanceof ReferenceError)
}
try {
{
class A { [A] () {} }
}
assert(false)
} catch (e) {
assert(e instanceof ReferenceError)
}
try {
{
var a = class A { [A] () {} }
}
assert(false)
} catch (e) {
assert(e instanceof ReferenceError)
}
{
class C {
a = C
static b = C
}
var X = C
C = 6
var c = new X
assert(X.b === X)
assert(c.a === X)
}
{
let a = 6
let b = 7
class C {
p = a + b
}
assert((new C).p === 13)
}
try {
{
class C { static a = C = 5 }
}
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
try {
{
class C { static [C = 5] = 6 }
}
assert(false)
} catch (e) {
assert(e instanceof ReferenceError)
}
-87
View File
@@ -1,87 +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 count = 0
class C1 {
constructor() {
assert(++count === 3)
}
a = (assert(++count === 2), 1.1)
}
class C2 extends C1 {
constructor() {
var s = () => super()
function g() {
assert(++count === 1)
eval("s()");
}
g();
assert(++count === 5)
}
b = (assert(++count === 4), "prop")
}
var c = new C2
assert(count === 5)
assert(c.a === 1.1)
assert(c.b === "prop")
var o = {}
count = 0
class C3 extends C1 {
constructor() {
var s = () => () => eval("() => eval('super()')")
function g() {
assert(++count === 1)
s()()()
}
g();
assert(++count === 5)
}
b = (assert(++count === 4), o)
}
c = new C3
assert(count === 5)
assert(c.a === 1.1)
assert(c.b === o)
var f
class C4 extends Array {
a = 6.6
constructor() {
f = () => super()
super()
}
}
c = new C4
assert(c.a === 6.6)
try {
f()
assert(false)
} catch(e) {
assert(e instanceof ReferenceError)
}
@@ -1,42 +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 {
// Test skipping spaces
get (a, b, c) {
return a + b + c;
}
// Test skipping spaces
static get(a, b, c) {
return a - b - c;
}
set (a, b) {
return a * b;
}
static set (a, b) {
return a / b;
}
}
assert(A.get(1, 2, 3) === -4);
assert(A.set(2, 1) === 2);
var a = new A;
assert(a.get(1, 2, 3) === 6);
assert(a.set(2, 2) === 4);
@@ -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,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.
*/
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);
// 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,141 +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 () } }");
must_throw ("class A extends a * b {}");
must_throw ("class A extends a = b {}");
must_throw ("class A extends a++ {}");
must_throw ("class A extends -a {}");
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,47 +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.
*/
/* Create bound implicit class constructor */
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));
/* Add a new element to the bound function chain */
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));
/* Add a new element to the bound function chain */
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,62 +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.
*/
// TODO: enable this test when super keyword is supported for normal functions
/*
var console = { assert : assert };
class C1 {
f () {
return 5;
}
}
class C2 extends C1 {
f () {
assert (super.f () === 5);
class G {
g () {
assert (super.f === undefined);
assert (super.toString () === "[object Object]");
var a = super.valueOf ();
try {
a ();
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
}
constructor () {
// Test to overwrite the current lit-object
console.assert (Object.getPrototypeOf (this) === G.prototype);
try {
eval ("super ()");
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
}
}
var g = new G ();
g.g ();
}
}
(new C2).f ();
*/
@@ -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,102 +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 Base {
constructor () {
this.parent_value = 100;
}
parent_value () {
return this.parent_value;
}
parent_value_arg (a, b, c) {
if (c) {
return this.parent_value + a + b + c;
} else if (b) {
return this.parent_value + a + b;
} else {
return this.parent_value + a;
}
}
method () {
return {
method: function (a, b, c, d, e) { return -50 + a + b + c + d + e; }
}
}
}
class Target extends Base {
constructor () {
super ();
this.parent_value = -10;
}
parent_value () {
throw new Error ('(parent_value)');
}
parent_value_direct () {
return super.parent_value ();
}
parent_value_direct_arg (a, b, c) {
if (c) {
return super.parent_value_arg (a, b, c);
} else if (b) {
return super.parent_value_arg (a, b);
} else {
return super.parent_value_arg (a);
}
}
method () {
throw new Error ("(method)");
}
parent_method_dot () {
return super.method ().method (1, 2, 3, 4, 5)
}
parent_method_index () {
return super['method']()['method'](1, 2, 3, 4, 5);
}
}
var obj = new Target ();
assert (obj.parent_value_direct () === -10);
assert (obj.parent_value_direct_arg (1) === -9);
assert (obj.parent_value_direct_arg (1, 2) === -7);
assert (obj.parent_value_direct_arg (1, 2, 3) === -4);
try {
obj.parent_value();
assert (false)
} catch (ex) {
/* 'obj.parent_value is a number! */
assert (ex instanceof TypeError);
}
assert (obj.parent_method_dot () === -35);
assert (obj.parent_method_index () === -35);
try {
obj.method ();
assert (false);
} catch (ex) {
assert (ex.message === '(method)');
}
@@ -1,114 +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 Base {
constructor () {
this.parent_value = 100;
}
parent_value () {
return this.parent_value;
}
parent_value_arg (a, b, c) {
if (c) {
return this.parent_value + a + b + c;
} else if (b) {
return this.parent_value + a + b;
} else {
return this.parent_value + a;
}
}
method () {
return {
method: function (a, b, c, d, e) { return -50 + a + b + c + d + e; }
}
}
}
class Target extends Base {
constructor () {
super ();
this.parent_value = -10;
}
parent_value () {
throw new Error ('(parent_value)');
}
parent_value_indirect () {
return super.parent_value.call (this);
}
parent_value_indirect_arg (a, b, c) {
if (c) {
return super.parent_value_arg.call (this, a, b, c);
} else if (b) {
return super.parent_value_arg.call (this, a, b);
} else {
return super.parent_value_arg.call (this, a);
}
}
method () {
throw new Error ("(method)");
}
parent_method_dot () {
return super.method.call (this).method (1, 2, 3, 4, 5)
}
parent_method_index() {
return super['method'].call (this)['method'] (1, 2, 3, 4, 5);
}
}
var obj = new Target();
assert (obj.parent_value_indirect () === -10);
assert (obj.parent_value_indirect_arg (1) === -9);
assert (obj.parent_value_indirect_arg (1, 2) === -7);
assert (obj.parent_value_indirect_arg (1, 2, 3) === -4);
try {
obj.parent_value ();
assert (false);
} catch (ex) {
/* 'obj.parent_value is a number! */
assert (ex instanceof TypeError);
}
assert (obj.parent_method_dot () === -35);
assert (obj.parent_method_index () === -35);
try {
obj.method();
assert (false);
} catch (ex) {
assert (ex.message === '(method)');
}
var demo_object = {
parent_value: 1000,
method: function () {
throw new Error ('Very bad!');
}
}
assert (obj.parent_value_indirect_arg.call (demo_object, 1) === 1001);
assert (obj.parent_value_indirect_arg.call (demo_object, 1, 2) === 1003);
assert (obj.parent_method_dot.call (demo_object) === -35);
-31
View File
@@ -1,31 +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 called = false
var obj = { f() { assert(this === obj); called = true } }
function f() {
assert(false)
}
with (obj) {
new class {
constructor() {
f()
}
}
}
assert(called)
-345
View File
@@ -1,345 +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 { static get prototype() {} }");
must_throw("class A { static set prototype() {} }");
must_throw("class A { static prototyp\u{0065}() {} }");
must_throw("class A { static get prototyp\u{0065}() {} }");
must_throw("class A { static set prototyp\u{0065}() {} }");
must_throw("class A { static 'prototype'() {} }");
must_throw("class A { static get 'prototype'() {} }");
must_throw("class A { static set 'prototype'() {} }");
must_throw("class A { static 'prototyp\u{0065}'() {} }");
must_throw("class A { static get 'prototyp\u{0065}'() {} }");
must_throw("class A { static set 'prototyp\u{0065}'() {} }");
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 { g\\u0065t e() {} }");
must_throw('class A { "static" e() {} }');
must_throw('class A { *constructor() {} }');
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 A1 {
["constructor"]() {
return 5;
}
}
assert ((new A1).constructor() === 5);
class A2 {
*["constructor"]() {
yield 5;
}
}
assert ((new A2).constructor().next().value === 5);
class B {
}
var b = new B;
assert (typeof B === "function");
assert (typeof b === "object");
assert (b.constructor === B);
class C {
c1() {
return 5;
}
c2() {
return this._c;
}
3() {
return 3;
}
super() {
return 42;
}
return() {
return 43;
}
static *constructor() {
return 44;
}
}
var c = new C;
assert (c.c1() === 5);
assert (c.c2() === undefined);
assert (c["3"]() === 3);
assert (c.super() === 42);
assert (c.return() === 43);
assert (c.constructor === C);
assert (C.constructor().next().value === 44);
class D {
constructor(d) {
this._d = d;
}
d1() {
return this._d;
}
}
var d = new D(5);
assert (d.d1() === 5);
assert (d.constructor === D);
class E {
constructor(e) {
this._e = e;
}
get e() {
return this._e;
}
set e(e) {
this._e = e;
}
get () {
return 11;
}
set () {
return 12;
}
}
var e = new E (5);
assert (e.e === 5);
e.e = 10;
assert (e.e === 10);
assert (e.get() === 11);
assert (e.set() === 12);
assert (e.constructor === E);
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;
}
static function(a) {
return 3 * 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);
assert (F.function(5) === 15);
assert (f.constructor === F);
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 get() {
return 11;
}
static set() {
return 12;
}
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);
assert (G.get() == 11);
assert (G.set() == 12);
G.constructor = 30;
assert (G.constructor === 30);
class H {
method() { assert (typeof H === 'function'); return H; }
}
let H_original = H;
var H_method = H.prototype.method;
C = undefined;
assert(C === undefined);
C = H_method();
assert(C === H_original);
var I = class C {
method() { assert(typeof C === 'function'); return C; }
}
let I_original = I;
var I_method = I.prototype.method;
I = undefined;
assert(I === undefined);
I = I_method();
assert(I == I_original);
var J_method;
class J {
static [(J_method = eval('(function() { return J; })'), "X")]() {}
}
var J_original = J;
J = 6;
assert (J_method() == J_original);
var K_method;
class K {
constructor () {
K_method = function() { return K; }
}
}
var K_original = K;
new K;
K = 6;
assert (K_method() == K_original);
var L_method;
class L extends (L_method = function() { return L; }) {
}
var L_original = L;
L = 6;
assert (L_method() == L_original);
/* Test cleanup class environment */
try {
class A {
[d]() {}
}
let d;
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
}
try {
class A extends d {}
let d;
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
}
try {
var a = 1 + 2 * 3 >> class A extends d {};
let d;
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
}
-147
View File
@@ -1,147 +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 check_syntax_error(code) {
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
}
check_syntax_error("static {}");
check_syntax_error("class C { #static {} }");
check_syntax_error("function foo() { static {} }");
check_syntax_error("class C { static { return; } }");
check_syntax_error("class C { static { break; } }");
check_syntax_error("class C { static { continue; } }");
check_syntax_error("class C { static { await => 0; } }");
check_syntax_error("class C { static { yield } }");
check_syntax_error("class C { static { super(); } }");
check_syntax_error("class C { static { let a; let a; } }");
check_syntax_error("class C { static { label: label: 0 } }");
check_syntax_error("class C { static { let #a; } }");
check_syntax_error("class C { static { (class { [arguments]() { } }); } }");
check_syntax_error("class C { static {x: while (false) {continue y; } } }");
check_syntax_error("function* g() { class C { static { yield; } } }");
try {
class C {
static {
function foo() {
return this.a
};
foo()
}
}
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
class Parent {
static fieldP = 'fieldP'
}
class C1 extends Parent{
static a = 0;
static #privateField = 1;
static {
assert(this.a === 0)
assert(this.#privateField === 1)
this.a = 1
this.b = super.fieldP
this.c = new.target
assert(this.a === 1)
assert(this.b === 'fieldP')
assert(this.c === undefined)
assert(this.d === undefined)
}
static d = 2
static {
assert(this.b === 'fieldP')
assert(this.d === 2)
}
static {
function f() {
assert(this === undefined)
}
let a = 11
assert (this.a !== a)
}
}
class C2 {
getPrivateField;
static getPrivateField2;
static invalidAccess;
}
let getPrivateField;
class C3 {
#privateField = 'invalid';
static #staticPrivateField = 'private';
constructor(p) {
this.#privateField = p;
}
static {
getPrivateField = (d) => d.#privateField;
C2.getPrivateField = () => this.#staticPrivateField;
C2.getPrivateField2 = () => this.#staticPrivateField;
C2.invalidAccess = () => this.#privateField;
}
}
assert(getPrivateField(new C3('private field')) == 'private field');
assert(C2.getPrivateField() === 'private')
assert(C2.getPrivateField2() === 'private')
try {
C2.invalidAccess()
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
let a = 'outter'
let b, c
class C5 {
static {
let a = 'first block'
b = a
}
static {
let a = "second block"
c = a
}
}
assert(a === "outter")
assert(b === "first block")
assert(c === "second block")
-74
View File
@@ -1,74 +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.
*/
const a = 6
assert(!delete a)
assert(a === 6)
try {
eval("a = 7")
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
function check_type_error(code) {
try {
eval(code)
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
}
// Register cases
check_type_error("{ const a = 0; a = 1 }");
check_type_error("{ const a = 0; a += 1 }");
check_type_error("{ const a = 0; a -= 1 }");
check_type_error("{ const a = 0; a *= 1 }");
check_type_error("{ const a = 0; a %= 1 }");
check_type_error("{ const a = 0; a /= 1 }");
check_type_error("{ const a = 0; a <<= 1 }");
check_type_error("{ const a = 0; a >>= 1 }");
check_type_error("{ const a = 0; a >>>= 1 }");
check_type_error("{ const a = 0; a &= 1 }");
check_type_error("{ const a = 0; a |= 1 }");
check_type_error("{ const a = 0; a ^= 1 }");
check_type_error("{ const a = 0; a++ }");
check_type_error("{ const a = 0; a-- }");
check_type_error("{ const a = 0; ++a }");
check_type_error("{ const a = 0; --a }");
check_type_error("{ const a = 0; [a] = [1] }");
check_type_error("{ const a = 0; ({a} = { a:1 }) }");
// Non-register cases
check_type_error("{ const a = 0; (function (){ a = 1 })() }");
check_type_error("{ const a = 0; (function (){ a += 1 })() }");
check_type_error("{ const a = 0; (function (){ a -= 1 })() }");
check_type_error("{ const a = 0; (function (){ a *= 1 })() }");
check_type_error("{ const a = 0; (function (){ a %= 1 })() }");
check_type_error("{ const a = 0; (function (){ a /= 1 })() }");
check_type_error("{ const a = 0; (function (){ a <<= 1 })() }");
check_type_error("{ const a = 0; (function (){ a >>= 1 })() }");
check_type_error("{ const a = 0; (function (){ a >>>= 1 })() }");
check_type_error("{ const a = 0; (function (){ a &= 1 })() }");
check_type_error("{ const a = 0; (function (){ a |= 1 })() }");
check_type_error("{ const a = 0; (function (){ a ^= 1 })() }");
check_type_error("{ const a = 0; (function (){ a++ })() }");
check_type_error("{ const a = 0; (function (){ a-- })() }");
check_type_error("{ const a = 0; (function (){ ++a })() }");
check_type_error("{ const a = 0; (function (){ --a })() }");
check_type_error("{ const a = 0; (function (){ [a] = [1] })() }");
check_type_error("{ const a = 0; (function (){ ({a} = { a:1 }) })() }");
-44
View File
@@ -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.
*/
for (var i = 0; i < 1000; i++)
{
switch (1)
{
default:
/* This block must not be enclosed in braces. */
let j = eval();
continue;
}
}
next:
for (var i = 0; i < 1000; i++)
{
for (let j = eval(); true; )
{
continue next;
}
}
next:
for (var i = 0; i < 1000; i++)
{
for (let j in {a:1})
{
eval()
continue next;
}
}
-265
View File
@@ -1,265 +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.
*/
/* ES11 24.3.2.1.1 */
try {
DataView ();
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
/* ES11 24.3.2.1.2 (not object) */
try {
new DataView (5);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
/* ES11 24.3.2.1.2 (no [[ArrayBufferData]] internal slot) */
try {
new DataView ({});
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
var buffer = new ArrayBuffer (16);
/* ES11 24.3.2.1.3 (offset < 0)*/
try {
new DataView (buffer, -1);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
/* ES11 24.3.2.1.3 (offset > 2^53) */
try {
new DataView (buffer, Number.MAX_SAFE_INTEGER + 1);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
/* ES11 24.3.2.1.3 (ToInteger throws ReferenceError) */
try {
new DataView (buffer, { toString: function () { throw new ReferenceError ('foo') } });
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
assert (e.message === 'foo');
}
/* ES11 24.3.2.1.6 */
try {
new DataView (buffer, 17);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
/* ES11 24.3.2.1.8.a */
try {
new DataView (buffer, 0, { toString: function () { throw new ReferenceError ('bar') } });
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
assert (e.message === 'bar');
}
/* ES11 24.3.2.1.8.a */
try {
new DataView (buffer, 0, Infinity);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
/* ES11 24.3.2.1.8.b */
try {
new DataView (buffer, 4, 13);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
/* Tests accessors: ES11 24.3.4.{1, 2, 3}.2 */
var accessorList = ['buffer', 'byteLength', 'byteOffset'];
accessorList.forEach (function (prop) {
try {
var obj = {};
Object.setPrototypeOf (obj, DataView.prototype);
obj[prop];
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
});
buffer = new ArrayBuffer (32);
var view1 = new DataView (buffer);
assert (view1.buffer === buffer);
assert (view1.byteOffset === 0);
assert (view1.byteLength === buffer.byteLength);
var view2 = new DataView (buffer, 8);
assert (view2.buffer === buffer);
assert (view2.byteOffset === 8);
assert (view2.byteLength === buffer.byteLength - view2.byteOffset);
var view3 = new DataView (buffer, 8, 16);
assert (view3.buffer === buffer);
assert (view3.byteOffset === 8);
assert (view3.byteLength === 16);
/* Test get/set routines */
var getters = ['getInt8', 'getUint8', 'getInt16', 'getUint16', 'getInt32', 'getUint32', 'getFloat32', 'getFloat64'];
var setters = ['setInt8', 'setUint8', 'setInt16', 'setUint16', 'setInt32', 'setUint32', 'setFloat32', 'setFloat64'];
var gettersSetters = getters.concat (setters);
gettersSetters.forEach (function (propName) {
/* ES11 24.3.1.{1, 2}.1 */
var routine = DataView.prototype[propName];
try {
DataView.prototype[propName].call (5);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
/* ES11 24.3.1.{1, 2}.1 */
try {
DataView.prototype[propName].call ({});
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
/* ES11 24.3.1.{1, 2}.3 (ToInteger throws ReferenceError) */
try {
var buffer = new ArrayBuffer (16);
var view = new DataView (buffer)
view[propName] ({ toString : function () { throw new ReferenceError ('fooBar') } });
assert (false);
} catch (e) {
assert (e instanceof ReferenceError);
assert (e.message == 'fooBar');
}
var buffer = new ArrayBuffer (16);
var view = new DataView (buffer)
/* ES11 24.3.1.{1, 2}.3 (getIndex < 0) */
try {
view[propName] (-1);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
/* ES11 24.3.1.1.10, 24.3.1.2.12 */
try {
view[propName] (20);
assert (false);
} catch (e) {
assert (e instanceof RangeError);
}
});
/* Test the endianness */
function validateResult (view, offset, isLitteEndian, results) {
for (var i = 0; i < getters.length; i++) {
assert (results[i] === view[getters[i]](offset, isLitteEndian));
}
}
buffer = new ArrayBuffer (24);
view1 = new DataView (buffer);
view2 = new DataView (buffer, 4, 12);
view3 = new DataView (buffer, 6, 18);
view4 = new DataView (buffer);
view5 = new DataView (buffer);
view1.setUint8 (0, 255);
validateResult(view1, 0, false, [-1, 255, -256, 65280, -16777216, 4278190080, -1.7014118346046924e+38, -5.486124068793689e+303]);
validateResult(view1, 0, true, [-1, 255, 255, 255, 255, 255, 3.5733110840282835e-43, 1.26e-321]);
validateResult(view1, 2, false, [0, 0, 0, 0, 0, 0, 0, 0]);
validateResult(view1, 2, true, [0, 0, 0, 0, 0, 0, 0, 0]);
view1.setInt16 (4, 40000);
validateResult(view1, 4, false, [-100, 156, -25536, 40000, -1673527296, 2621440000, -6.352747104407253e-22, -1.2938158758247024e-172]);
validateResult(view2, 0, false, [-100, 156, -25536, 40000, -1673527296, 2621440000, -6.352747104407253e-22, -1.2938158758247024e-172]);
validateResult(view1, 4, true, [-100, 156, 16540, 16540, 16540, 16540, 2.3177476599932474e-41, 8.172e-320]);
validateResult(view2, 0, true, [-100, 156, 16540, 16540, 16540, 16540, 2.3177476599932474e-41, 8.172e-320]);
view2.setUint32 (2, 3000000000, true);
validateResult(view2, 2, false, [0, 0, 94, 94, 6213810, 6213810, 8.707402410606192e-39, 6.856613170926581e-307]);
validateResult(view3, 0, false, [0, 0, 94, 94, 6213810, 6213810, 8.707402410606192e-39, 6.856613170926581e-307]);
validateResult(view2, 2, true, [0, 0, 24064, 24064, -1294967296, 3000000000, -2.425713319098577e-8, 1.4821969375e-314]);
validateResult(view3, 0, true, [0, 0, 24064, 24064, -1294967296, 3000000000, -2.425713319098577e-8, 1.4821969375e-314]);
view3.setFloat32 (4, 8.5);
validateResult(view3, 4, false, [65, 65, 16648, 16648, 1091043328, 1091043328, 8.5, 196608]);
validateResult(view3, 4, true, [65, 65, 2113, 2113, 2113, 2113, 2.9609436551183385e-42, 1.044e-320]);
validateResult(view2, 4, false, [-48, 208, -12110, 53426, -793624312, 3501342984, -23924850688, -5.411000515087672e+80]);
validateResult(view2, 4, true, [-48, 208, -19760, 45776, 138523344, 138523344, 5.828901796903399e-34, 6.84396254e-316]);
view4.setBigInt64 (0, 2n);
assert(view4.getBigInt64(0) === 2n);
view4.setBigInt64 (1, -2n);
assert(view4.getBigInt64(1) === -2n);
assert(view4.getBigUint64(1) === 18446744073709551614n);
view5.setBigUint64 (0, 2n);
assert(view5.getBigUint64(0) === 2n);
view5.setBigUint64 (1, -2n);
assert(view5.getBigUint64(1) === 18446744073709551614n);
assert(view5.getBigInt64(1) === -2n);
/* Second and third arguments can be "undefined" and there should be no error. */
var arrayBufferOk = new ArrayBuffer (12);
var dtviewA = new DataView (arrayBufferOk, 0, undefined);
assert (dtviewA.byteLength === 12);
assert (dtviewA.byteOffset === 0);
var dtviewB = new DataView (arrayBufferOk, 1, undefined);
assert (dtviewB.byteLength === 11);
assert (dtviewB.byteOffset === 1);
var dtviewC = new DataView (arrayBufferOk, null, undefined);
assert (dtviewC.byteLength === 12);
assert (dtviewC.byteOffset === 0);
var dtviewD = new DataView (arrayBufferOk, 0, null);
assert (dtviewD.byteLength === 0);
assert (dtviewD.byteOffset === 0);
var dtviewE = new DataView (arrayBufferOk, null, null);
assert (dtviewE.byteLength === 0);
assert (dtviewE.byteOffset === 0);
var dtviewF = new DataView (arrayBufferOk, null, 1);
assert (dtviewF.byteLength === 1);
assert (dtviewF.byteOffset === 0);
var dtviewF = new DataView (arrayBufferOk, undefined, 1);
assert(dtviewF.byteLength === 1);
assert(dtviewF.byteOffset === 0);
-65
View File
@@ -1,65 +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 sym = Symbol();
var date;
try {
date = new Date(sym, 11, 17, 3, 24, 0);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
try {
date = new Date(1997, sym, 17, 3, 24, 0);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
try {
date = new Date(1997, 11, sym, 3, 24, 0);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
try {
date = new Date(1997, 11, 17, sym, 24, 0);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
try {
date = new Date(1997, 11, 17, 3, sym, 0);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
try {
date = new Date(1997, 11, 17, 3, 24, sym);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
try {
date = new Date(1997, 11, 17, 3, 24, 0, sym);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
@@ -1,59 +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 dateObj = new Date("1997-04-10");
var dateNaN = new Date(NaN);
// Test with default hint
var result = dateObj[Symbol.toPrimitive]("default");
assert(result.toString().substring(0,15) === "Thu Apr 10 1997");
result = dateNaN[Symbol.toPrimitive]("default");
assert(dateNaN == "Invalid Date");
// Test with number hint
result = dateObj[Symbol.toPrimitive]("number");
assert(result.toString() === "860630400000");
result = dateNaN[Symbol.toPrimitive]("number");
assert(isNaN(result) === true);
// Test with string hint
result = dateObj[Symbol.toPrimitive]("string");
assert(result.toString().substring(0,15) === "Thu Apr 10 1997");
result = dateNaN[Symbol.toPrimitive]("string");
assert(result == "Invalid Date");
// Test with invalid hint
try {
result = dateObj[Symbol.toPrimitive](90);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
// Test with invalid hint value
try {
dateObj[Symbol.toPrimitive]('error');
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
// Test when unable to call toPrimitive
try {
Date.prototype[Symbol.toPrimitive].call(undefined);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
@@ -1,47 +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.
// valid decimal with leading zero
assert (01239 === 1239)
assert (0999 === 999)
assert (0000000000009 === 9)
function invalid_strict_cases (string)
{
"use strict"
try {
eval (string)
assert (false)
} catch (e) {
assert (true)
}
}
// invalid strict test-cases
invalid_strict_cases ("09")
invalid_strict_cases ("01239")
// invalid to create bigint with decimal with leading zero
function invalid_cases (string)
{
try {
eval (string)
assert (false)
} catch (e) {
assert (true)
}
}
invalid_cases ("09n")
invalid_cases ("01239n")
-35
View File
@@ -1,35 +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 check_syntax_error (code)
{
try {
eval (code)
assert (false)
} catch (e) {
assert (e instanceof SyntaxError)
}
}
eval("function f(a, b = 4) { }")
check_syntax_error ("function f(a, b = 4) { 'use strict' }")
eval('function f(...a) { }')
check_syntax_error ('function f(...a) { "use strict" }')
eval("({ f([a,b]) { } })")
check_syntax_error ("({ f([a,b]) { 'use strict' } })")
eval("function f(a, b = 4) { 'directive1'\n'directive2'\n }")
check_syntax_error ("function f(a, b = 4) { 'directive1'\n'directive2'\n'use strict' }")
-43
View File
@@ -1,43 +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 items = [
[TypeError, "TypeError"],
[SyntaxError, "SyntaxError"],
[URIError, "URIError"],
[EvalError, "EvalError"],
[RangeError, "RangeError"],
[ReferenceError, "ReferenceError"],
];
for (var idx = 0; idx < items.length; idx++) {
var type = items[idx][0];
var expected_name = items[idx][1];
assert (type.name === expected_name);
assert ((new type).name === expected_name);
}
assert (AggregateError.name === "AggregateError");
assert (new AggregateError([]).name === "AggregateError")
try
{
new AggregateError.name === "TypeError";
}
catch(e)
{
assert (e instanceof TypeError)
}
-22
View File
@@ -1,22 +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.
/* Prototype of NativeErrors should be Error */
assert(Object.getPrototypeOf(EvalError) === Error);
assert(Object.getPrototypeOf(RangeError) === Error);
assert(Object.getPrototypeOf(ReferenceError) === Error);
assert(Object.getPrototypeOf(SyntaxError) === Error);
assert(Object.getPrototypeOf(TypeError) === Error);
assert(Object.getPrototypeOf(URIError) === Error);
assert(Object.getPrototypeOf(AggregateError) === Error);
-73
View File
@@ -1,73 +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 two = 2
var three = 3
// Precedence (right-to-left) tests
assert(2 ** 3 ** 2 === 512)
assert((2 ** 3) ** 2 === 64)
assert(2 ** (3 ** 2) === 512)
assert(two ** three ** two === 512)
assert((two ** three) ** two === 64)
assert(two ** (three ** two) === 512)
assert(2 ** 2 * 3 ** 3 === 4 * 27)
assert(two ** two * three ** three === 4 * 27)
var a = 3
assert((a **= 3) === 27)
assert(a === 27)
a = 2
assert((a **= a **= 2) === 16)
assert(a === 16)
function assertThrows(src) {
try {
eval(src)
assert(false)
} catch (e) {
assert(e instanceof SyntaxError)
}
}
assertThrows("-2 ** 2")
assertThrows("+a ** 2")
assertThrows("!a ** 2")
assertThrows("~a ** 2")
assertThrows("void a ** 2")
assertThrows("typeof a ** 2")
assertThrows("delete a ** 2")
assertThrows("!(-a) ** 2")
assert((-2) ** 2 === 4)
a = 3
assert((-+-a) ** 3 === 27)
a = 0
assert((!a) ** 2 === 1)
a = 0
assert(isNaN((void a) ** 3))
a = -4
assert(++a ** 2 === 9)
assert(a === -3)
a = -2
assert(a-- ** 2 === 4)
assert(a === -3)
@@ -1,649 +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 successCount = 0;
// Test 1
var asyncIter1 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: "Val", done: false })
}
/* No return() function */
}
}
}
async function f1() {
for await (var v of asyncIter1) {
assert(v === "Val")
break
}
successCount++
exit:
for await (var v of asyncIter1) {
for await (var v of asyncIter1) {
assert(v === "Val")
break exit
}
assert(false)
}
successCount++
try {
for await (var v of asyncIter1) {
assert(v === "Val")
throw 3.75
}
assert(false)
} catch (e) {
assert(e === 3.75)
successCount++
}
try {
for await (var v of asyncIter1) {
assert(v === "Val")
return {}
}
assert(false)
} finally {
successCount++
}
assert(false)
}
f1()
// Test 2
var o2 = {}
var returnCount2 = 0
var asyncIter2 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: o2, done: false })
},
return(...v) {
assert(v.length === 0)
returnCount2++
return Promise.resolve({})
}
}
}
}
async function f2() {
for await (var v of asyncIter2) {
assert(v === o2)
break
}
successCount++
exit:
for await (var v of asyncIter2) {
for await (var v of asyncIter2) {
assert(v === o2)
break exit
}
assert(false)
}
successCount++
try {
for await (var v of asyncIter2) {
assert(v === o2)
throw o2
}
assert(false)
} catch (e) {
assert(e === o2)
successCount++
}
try {
for await (var v of asyncIter2) {
assert(v === o2)
return "Ret"
}
assert(false)
} finally {
successCount++
}
assert(false)
print("OK")
}
f2()
// Test 3
var asyncIter3 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
return() {
throw "Error"
}
}
}
}
async function *f3() {
try {
for await (var v of asyncIter3) {
assert(v === -4.5)
break
}
assert(false)
} catch (e) {
assert(e === "Error")
successCount++
}
try {
for await (var v of asyncIter3) {
assert(v === -4.5)
return
}
assert(false)
} catch (e) {
assert(e === "Error")
successCount++
}
try {
for await (var v of asyncIter3) {
assert(v === -4.5)
throw "Exit"
}
assert(false)
} catch (e) {
assert(e === "Exit")
successCount++
}
}
f3().next()
// Test 4
var o4 = {}
var asyncIter4 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
get return() {
throw o4
}
}
}
}
async function *f4() {
try {
for await (var v of asyncIter4) {
assert(v === -4.5)
break
}
assert(false)
} catch (e) {
assert(e === o4)
successCount++
}
try {
for await (var v of asyncIter4) {
assert(v === -4.5)
return
}
assert(false)
} catch (e) {
assert(e === o4)
successCount++
}
try {
for await (var v of asyncIter4) {
assert(v === -4.5)
throw 9.25
}
assert(false)
} catch (e) {
assert(e === 9.25)
successCount++
}
}
f4().next()
// Test 5
var asyncIter5 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
get return() {
return "Not callable"
}
}
}
}
async function f5() {
try {
for await (var v of asyncIter5) {
assert(v === -4.5)
break
}
assert(false)
} catch (e) {
assert(e instanceof TypeError)
successCount++
}
try {
for await (var v of asyncIter5) {
assert(v === -4.5)
return
}
assert(false)
} catch (e) {
assert(e instanceof TypeError)
successCount++
}
var o = {}
try {
for await (var v of asyncIter5) {
assert(v === -4.5)
throw o
}
assert(false)
} catch (e) {
assert(e === o)
successCount++
}
}
f5()
// Test 6
var asyncIter6 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
return() {
return Promise.resolve(4.5)
}
}
}
}
async function f6() {
try {
for await (var v of asyncIter6) {
assert(v === -4.5)
break
}
assert(false)
} catch (e) {
assert(e instanceof TypeError)
successCount++
}
try {
for await (var v of asyncIter6) {
assert(v === -4.5)
return
}
assert(false)
} catch (e) {
assert(e instanceof TypeError)
successCount++
}
try {
for await (var v of asyncIter6) {
assert(v === -4.5)
throw true
}
assert(false)
} catch (e) {
assert(e === true)
successCount++
}
}
f6()
// Test 7
var asyncIter7 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
return() {
return Promise.reject("Rejected")
}
}
}
}
async function f7() {
try {
for await (var v of asyncIter7) {
assert(v === -4.5)
break
}
assert(false)
} catch (e) {
assert(e === "Rejected")
successCount++
}
try {
for await (var v of asyncIter7) {
assert(v === -4.5)
return
}
assert(false)
} catch (e) {
assert(e === "Rejected")
successCount++
}
try {
for await (var v of asyncIter7) {
assert(v === -4.5)
throw true
}
assert(false)
} catch (e) {
assert(e === true)
successCount++
}
}
f7()
// Test 8
var asyncIter8 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
return() {
return {}
}
}
}
}
async function f8() {
for await (var v of asyncIter8) {
assert(v === -4.5)
break
}
successCount++
try {
for await (var v of asyncIter8) {
assert(v === -4.5)
throw null
}
assert(false)
} catch (e) {
assert(e === null)
successCount++
}
try {
for await (var v of asyncIter8) {
assert(v === -4.5)
return
}
assert(false)
} finally {
successCount++
}
}
f8()
// Test 9
var asyncIter9 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
assert(++idx === 1)
return Promise.resolve({ value: -4.5, done: false })
},
return() {
throw "Except"
}
}
}
}
async function f9() {
try {
for await (var v of asyncIter9) {
assert(v === -4.5)
break
}
assert(false)
} catch (e) {
assert(e === "Except")
successCount++
}
try {
for await (var v of asyncIter9) {
assert(v === -4.5)
throw 7.5
}
assert(false)
} catch (e) {
assert(e === 7.5)
successCount++
}
try {
for await (var v of asyncIter9) {
assert(v === -4.5)
for await (var v of asyncIter9) {
assert(v === -4.5)
for await (var v of asyncIter9) {
assert(v === -4.5)
throw "Leave"
}
assert(false)
}
assert(false)
}
assert(false)
} catch (e) {
assert(e === "Leave")
successCount++
}
try {
for await (var v of asyncIter9) {
assert(v === -4.5)
return
}
assert(false)
} catch (e) {
assert(e === "Except")
successCount++
}
}
f9()
// Test 10
var asyncIter10 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
throw "NoNext"
},
return() {
assert(false)
},
throw() {
assert(false)
}
}
}
}
async function f10() {
try {
try {
for await (var v of asyncIter10) {
assert(false)
}
assert(false)
} finally {
successCount++
}
} catch (e) {
assert(e === "NoNext")
successCount++
}
}
f10()
// Test 11
var asyncIter11 = {
[Symbol.asyncIterator]() {
var idx = 0;
return {
next() {
if (++idx < 3)
return Promise.resolve({ value: -4.5, done: false })
throw "NoNext"
},
return() {
assert(false)
},
throw() {
assert(false)
}
}
}
}
async function f11() {
try {
try {
for await (var v of asyncIter11) {
assert(v === -4.5)
}
assert(false)
} finally {
successCount++
}
} catch (e) {
assert(e === "NoNext")
successCount++
}
}
f11()
// Test 12
var o12 = {}
async function *gen12()
{
try {
yield 9.5
assert(false)
} finally {
successCount++
}
assert(false)
}
async function f12()
{
for await (var v of gen12())
{
assert(v === 9.5)
break;
}
successCount++
}
f12()
// END
function __checkAsync() {
assert(returnCount2 === 5)
assert(successCount === 36)
}
-230
View File
@@ -1,230 +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 check_syntax_error (code)
{
try {
eval (code);
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
}
check_syntax_error ("for await (a of b)");
check_syntax_error ("async function f() { for await (a in b) ; }");
check_syntax_error ("async function f() { for await ( ; ; ) ; }");
check_syntax_error ("async function f() { for await (let a = 0; a < 4; a++) ; }");
var successCount = 0;
// Test 1
var promise1 = Promise.resolve("Resolved");
var asyncIter1 = {
[Symbol.asyncIterator]() {
var idx = 0;
function next() {
idx++;
if (idx == 1) {
return { value:"Val", done: false }
} else if (idx == 2) {
return { value:promise1, done: false }
} else if (idx == 3) {
return { value:4.5, done: false }
}
return { value:promise1, done: true }
}
successCount++
return { next }
}
}
function checkAsyncIter1(v, idx)
{
if (idx === 1) {
assert(v === "Val")
} else if (idx === 2) {
assert(v === promise1)
} else if (idx === 3) {
assert(v === 4.5)
} else {
assert(false)
}
}
async function f1a() {
var idx = 0;
for await (var v of asyncIter1) {
checkAsyncIter1(v, ++idx);
successCount++;
}
successCount++;
}
f1a()
async function f1b() {
await promise1
var idx = 0;
for await (var v of asyncIter1) {
checkAsyncIter1(v, ++idx);
successCount++;
}
successCount++;
}
f1b()
async function *f1c() {
var idx = 0;
for await (var v of asyncIter1) {
checkAsyncIter1(v, ++idx);
successCount++;
}
successCount++;
}
f1c().next()
async function *f1d() {
await promise1
var idx = 0;
for await (var v of asyncIter1) {
checkAsyncIter1(v, ++idx);
successCount++;
}
successCount++;
}
f1d().next()
// Test 2
var state2 = 0
var promise2 = Promise.reject("Rejected");
var asyncIter2 = {
[Symbol.asyncIterator]() {
var idx = 0;
assert(++state2 === 1)
function next() {
idx++;
if (idx == 1) {
assert(++state2 === 2)
return { value:"Str", done: false }
} else if (idx == 2) {
assert(++state2 === 4)
return { value:promise2, done: false }
} else if (idx == 3) {
assert(++state2 === 6)
return { value:-3.5, done: false }
}
assert(++state2 === 8)
return { value:promise2, done: true }
}
successCount++
return { next }
}
}
function checkAsyncIter2(v, idx)
{
if (idx === 1) {
assert(v === "Str")
} else if (idx === 2) {
assert(v === promise2)
} else if (idx === 3) {
assert(v === -3.5)
} else {
assert(false)
}
}
async function *f2a() {
var idx = 0;
for await (var v of asyncIter2) {
checkAsyncIter2(v, ++idx)
yield v
}
successCount++;
}
async function f2b() {
var idx = 0;
var g = f2a();
var v;
while (true) {
v = await g.next()
if (v.done) {
break;
}
checkAsyncIter2(v.value, ++idx)
++state2
assert(state2 === 3 || state2 === 5 || state2 === 7)
}
successCount++;
}
f2b();
// Test 3
var o3 = {}
async function* gen3()
{
yield o3
yield "Res"
}
async function f3()
{
var idx = 0
for await (var v of gen3())
{
idx++
if (idx === 1)
{
assert(v === o3)
}
else
{
assert(idx === 2)
assert(v === "Res")
}
}
successCount++
}
f3()
// END
function __checkAsync() {
assert(state2 === 8)
assert(successCount === 24)
}
@@ -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.
function check_reference_error (code)
{
try {
eval (code)
assert (false)
} catch (e) {
assert (e instanceof ReferenceError)
}
}
check_reference_error("for (let x of [x]) {}")
check_reference_error("for (const x of [x]) {}")
check_reference_error("for (let x in {x}) {}")
check_reference_error("for (const x in {x}) {}")
-105
View File
@@ -1,105 +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 arr = [];
for (let i = 0, j = 0; i < 10; j++)
{
arr[i] = function() { return i + j; }
i++;
}
for (let i = 0; i < 10; i++)
assert(arr[i]() === (i * 2 + 1));
var j = 0, k = 0;
for (let i = 0; j = i, i < 10; i++)
{
let i = -3;
assert(i === -3);
assert(j === k);
k++;
}
var j = 0, k = 0;
for (let i = 0; eval("j = i"), i < 10; i++)
{
let i = -3;
assert(i === -3);
assert(j === k);
k++;
}
var arr = [];
for (let i in { x:1, y:1, z:1 })
{
let str = "P";
arr.push(function () { return str + i; });
}
assert(arr[0]() === "Px");
assert(arr[1]() === "Py");
assert(arr[2]() === "Pz");
try {
for (let i in (function() { return i; })()) {}
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
}
try {
for (let i = 0, j = 0; i < 5; i++, j++)
{
if (i === 3)
{
eval("throw -42")
}
}
assert(false);
} catch (e) {
assert(e === -42);
}
exit: {
for (let i = 0, j = 0; i < 5; i++, j++)
{
if (eval("i === 3")) {
assert(i === 3);
break exit;
}
}
assert(false);
}
var f = null, g = null, h = null;
for (let i = 0;
f = function() { return i }, i < 1;
i++, g = function() { return i })
{
h = function() { return i };
}
assert(f() === 1);
assert(g() === 1);
assert(h() === 0);
var arr = [];
for (const i in { aa:4, bb:5, cc:6 })
{
arr.push(function () { return i });
}
assert(arr[0]() === "aa");
assert(arr[1]() === "bb");
assert(arr[2]() === "cc");
@@ -1,244 +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 createIterable(arr, methods = {}) {
let iterable = function *() {
let idx = 0;
while (idx < arr.length) {
yield arr[idx];
idx++;
}
}();
iterable['return'] = methods['return'];
iterable['throw'] = methods['throw'];
return iterable;
};
function close1() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
for (var it of iter) break;
return closed;
}
assert(close1());
function close2() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
try {
for (var it of iter) throw 0;
assert(false);
} catch(e){
assert(e === 0);
}
return closed;
}
assert(close2());
function close3() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
for (var it of iter) continue;
return closed;
}
assert(!close3());
function close4() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; throw 6; }
});
try {
for (var it of iter) throw 5;
assert(false);
} catch(e) {
assert(e === 5);
}
return closed;
}
assert(close4());
function close5() {
var closed_called = 0;
var iter = createIterable([1, 2, 3], {
'return': function() { closed_called++; throw 6; }
});
try {
for (var it of iter) {
for (var it of iter) {
throw 5;
}
assert(false);
}
assert(false);
} catch(e) {
assert(e === 5);
}
return closed_called === 2;
}
assert(close5());
function close6() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
for (var it of iter) {};
return closed;
}
assert(!close6());
var close7_result = false;
function close7() {
var iter = createIterable([1, 2, 3], {
'return': function() { close7_result = true; throw "5"; }
});
for (var it of iter) {
return "foo";
}
}
try {
close7();
assert(false);
} catch (e) {
assert(close7_result);
assert(e === "5");
}
function close8() {
var iter = createIterable([1, 2, 3], {
'return': function() { close8_result = true; throw "5"; }
});
for (var it of iter) {
throw "foo";
}
}
var close8_result = false;
try {
close8();
assert(false);
} catch (e) {
assert(e === "foo");
assert(close8_result);
}
function close9() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; throw "5"; }
});
try {
for (var it of iter) {
break;
}
} finally {
assert(closed);
throw "foo"
}
}
try {
close9();
assert(false);
} catch (e) {
assert(e === "foo");
}
function close10() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; return {}; }
});
try {
for (var it of iter) {
return "foo";
}
} finally {
assert(closed);
throw "bar";
}
}
try {
close10();
assert(false);
} catch (e) {
assert(e === "bar");
}
function close11() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; throw "5"; }
});
try {
for (var it of iter) {
return "foo";
}
} finally {
assert(closed);
throw "bar";
}
}
try {
close11();
assert(false);
} catch (e) {
assert(e === "bar");
}
function close12() {
var closed = false;
var iter = createIterable([1, 2, 3], {
'return': function() { closed = true; throw "5"; }
});
try {
for (var it of iter) {
throw "foo";
}
} finally {
assert(closed);
throw "bar";
}
}
try {
close12();
assert(false);
} catch (e) {
assert(e === "bar");
}
@@ -1,16 +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.
for (a of [1] || [2]) {}
-167
View File
@@ -1,167 +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 parse (txt) {
try {
eval (txt)
assert (false)
} catch (e) {
assert (e instanceof SyntaxError)
}
}
function checkError (obj) {
try {
for (var a of obj);
assert (false)
} catch (e) {
assert (e instanceof TypeError)
}
}
var arr = [1,2,3,4]
var forOf =
"for var prop of obj" +
" obj [prop] += 4"
parse (forOf)
var forOf =
"for [var prop of obj]" +
" obj[prop] += 4;"
parse (forOf)
var forOf =
"for (var prop obj)" +
" obj[prop] += 4;"
parse (forOf)
var forOf =
"foreach (var prop of obj)" +
" obj[prop] += 4;"
parse (forOf)
var forOf =
"for (var a \"of\" []) {}"
parse (forOf)
var forOf =
"for (let x of [], []) {}"
parse (forOf)
var forOf =
"for (var x of [], []) {}"
parse (forOf)
checkError(7)
var obj = {}
Object.defineProperty(obj, Symbol.iterator, { get : function () { throw TypeError ('foo');}});
checkError (obj);
var obj = {
[Symbol.iterator] : 5
}
checkError (obj);
var obj = {
[Symbol.iterator] () {
return 5
}
}
checkError(obj);
var obj = {
[Symbol.iterator] () {
return {}
}
}
checkError(obj);
var obj = {
[Symbol.iterator] () {
return {
next() {
return 5;
}
}
}
}
checkError(obj);
var array = [0, 1, 2, 3, 4, 5];
var i = 0;
for (var a of array) {
assert (a === i++);
}
var obj = {
[Symbol.iterator]() {
return {
counter : 0,
next () {
if (this.counter == 10) {
return { done : true, value : undefined };
}
return { done: false, value: this.counter++ };
}
}
}
}
var i = 0;
for (var a of obj) {
assert (a === i++);
}
var status = 0;
i = 0;
function yieldNext() {
++status
assert(status === 3 || status === 6 || status === 9)
return {
get value() {
++status
assert(status === 4 || status === 7)
return "Res"
},
done: ++i >= 3
}
}
obj = {
[Symbol.iterator]() {
assert(++status === 1)
return {
get next() {
assert(++status === 2)
return yieldNext
}
}
}
}
function getX() {
++status
assert(status === 5 || status === 8)
return { x:0 }
}
for (getX().x of obj)
;
assert(status == 9)
-119
View File
@@ -1,119 +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 check_syntax_error (code)
{
try {
eval (code)
assert (false)
} catch (e) {
assert (e instanceof SyntaxError)
}
}
var idx = 0;
for (var [a,b] of [[1,2], [3,4]])
{
if (idx == 0)
{
assert(a === 1);
assert(b === 2);
idx = 1;
}
else
{
assert(a === 3);
assert(b === 4);
}
}
assert(a === 3);
assert(b === 4);
idx = 0;
for (let [a,b] of [[5,6], [7,8]])
{
if (idx == 0)
{
assert(a === 5);
assert(b === 6);
idx = 1;
}
else
{
assert(a === 7);
assert(b === 8);
}
}
assert(a === 3);
assert(b === 4);
idx = 0;
for (let [a,b] of [[11,12], [13,14]])
{
if (idx == 0)
{
eval("assert(a === 11)");
eval("assert(b === 12)");
idx = 1;
}
else
{
eval("assert(a === 13)");
eval("assert(b === 14)");
}
}
assert(a === 3);
assert(b === 4);
check_syntax_error("for (let [a,b] = [1,2] of [[3,4]]) {}")
idx = 0;
for ([a,b] of [[10,true], ["x",null]])
{
if (idx == 0)
{
assert(a === 10);
assert(b === true);
idx = 1;
}
else
{
assert(a === "x");
assert(b === null);
}
}
assert(a === "x");
assert(b === null);
check_syntax_error("for ([a,b] = [1,2] of [[3,4]]) {}")
var o = {}
for ([a, b] = [o,false]; false; )
{
assert(false);
}
assert(a === o);
assert(b === false);
for ([a, b] + [a, b]; false; )
{
assert(false);
}
check_syntax_error("for ([a,b] + 1 of [[3,4]]) {}")

Some files were not shown because too many files have changed in this diff Show More