Skip to content
Snippets Groups Projects
Unverified Commit 3b7a456d authored by Rick Waldron's avatar Rick Waldron Committed by GitHub
Browse files

Merge pull request #1532 from anba/compat-new

Various test cases for cross-browser compliance bugs
parents 9721aa8e b552dad5
No related branches found
No related tags found
No related merge requests found
Showing
with 617 additions and 0 deletions
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-web-compat-functiondeclarationinstantiation
description: >
Nested function declarations, the second declaration is not Annex-B applicable.
info: |
B.3.3.1 Changes to FunctionDeclarationInstantiation
1. If strict is false, then
a. For each FunctionDeclaration f that is directly contained in the
StatementList of a Block, CaseClause, or DefaultClause, do
i. Let F be StringValue of the BindingIdentifier of FunctionDeclaration f.
ii. If replacing the FunctionDeclaration f with a VariableStatement that
has F as a BindingIdentifier would not produce any Early Errors for
func and F is not an element of parameterNames, then
...
flags: [noStrict]
---*/
function g() {
// Create an outer block-statement.
{
// A lexically declared function declaration.
// This function is applicable for Annex-B semantics.
function f() { return 1; }
// An inner block-statement with another function declaration.
// This function is not applicable for Annex-B semantics, because
// replacing it with |var f| would result in a SyntaxError.
{
function f() { return 2; }
}
}
assert.sameValue(f(), 1);
}
g();
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.filter
description: >
Non-writable properties are overwritten by CreateDataPropertyOrThrow.
info: |
22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] )
...
8. Repeat, while k < len
...
c. If kPresent is true, then
...
iii. If selected is true, then
1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(to), kValue).
...
features: [Symbol.species]
includes: [propertyHelper.js]
---*/
var a = [1];
a.constructor = {};
a.constructor[Symbol.species] = function(len) {
var q = new Array(0);
Object.defineProperty(q, 0, {
value: 0, writable: false, configurable: true, enumerable: false,
});
return q;
};
var r = a.filter(function(){ return true; });
verifyProperty(r, 0, {
value: 1, writable: true, configurable: true, enumerable: true,
});
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.indexof
description: >
Calls [[HasProperty]] on the prototype to check for existing elements.
info: |
22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
...
2. Let len be ? ToLength(? Get(O, "length")).
...
4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.)
...
8. Repeat, while k < len
a. Let kPresent be ? HasProperty(O, ! ToString(k)).
b. If kPresent is true, then
i. Let elementK be ? Get(O, ! ToString(k)).
...
includes: [proxyTrapsHelper.js]
features: [Proxy]
---*/
var array = [1, null, 3];
Object.setPrototypeOf(array, new Proxy(Array.prototype, allowProxyTraps({
has: function(t, pk) {
return pk in t;
}
})));
var fromIndex = {
valueOf: function() {
// Zero the array's length. The loop in step 8 iterates over the original
// length value of 100, but the only prototype MOP method which should be
// called is [[HasProperty]].
array.length = 0;
return 0;
}
};
Array.prototype.indexOf.call(array, 100, fromIndex);
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.lastindexof
description: >
Calls [[HasProperty]] on the prototype to check for existing elements.
info: |
22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
...
2. Let len be ? ToLength(? Get(O, "length")).
...
4. If fromIndex is present, let n be ? ToInteger(fromIndex); else let n be len-1.
...
7. Repeat, while k ≥ 0
a. Let kPresent be ? HasProperty(O, ! ToString(k)).
b. If kPresent is true, then
i. Let elementK be ? Get(O, ! ToString(k)).
...
includes: [proxyTrapsHelper.js]
features: [Proxy]
---*/
var array = [5, undefined, 7];
Object.setPrototypeOf(array, new Proxy(Array.prototype, allowProxyTraps({
has: function(t, pk) {
return pk in t;
}
})));
var fromIndex = {
valueOf: function() {
// Zero the array's length. The loop in step 8 iterates over the original
// length value of 100, but the only prototype MOP method which should be
// called is [[HasProperty]].
array.length = 0;
return 2;
}
};
Array.prototype.lastIndexOf.call(array, 100, fromIndex);
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.map
description: >
Non-writable properties are overwritten by CreateDataPropertyOrThrow.
info: |
22.1.3.16 Array.prototype.map ( callbackfn [ , thisArg ] )
...
7. Repeat, while k < len
...
c. If kPresent is true, then
...
iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
...
features: [Symbol.species]
includes: [propertyHelper.js]
---*/
var a = [1];
a.constructor = {};
a.constructor[Symbol.species] = function(len) {
var q = new Array(0);
Object.defineProperty(q, 0, {
value: 0, writable: false, configurable: true, enumerable: false,
});
return q;
};
var r = a.map(function(){ return 2; });
verifyProperty(r, 0, {
value: 2, writable: true, configurable: true, enumerable: true,
});
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.slice
description: >
Non-writable properties are overwritten by CreateDataPropertyOrThrow.
info: |
22.1.3.23 Array.prototype.slice ( start, end )
...
10. Repeat, while k < final
...
c. If kPresent is true, then
...
ii. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), kValue).
...
features: [Symbol.species]
includes: [propertyHelper.js]
---*/
var a = [1];
a.constructor = {};
a.constructor[Symbol.species] = function(len) {
var q = new Array(0);
Object.defineProperty(q, 0, {
value: 0, writable: false, configurable: true, enumerable: false,
});
return q;
};
var r = a.slice(0);
verifyProperty(r, 0, {
value: 1, writable: true, configurable: true, enumerable: true,
});
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.splice
description: >
Ensure the correct property traps are called on the new array.
features: [Proxy, Symbol.species]
includes: [compareArray.js]
---*/
var log = [];
var a = [0, 1];
a.constructor = {};
a.constructor[Symbol.species] = function(len) {
return new Proxy(new Array(len), new Proxy({}, {
get(t, pk, r) {
log.push(pk);
}
}));
};
var r = a.splice(0);
assert.compareArray([
// Step 11.c.ii: CreateDataPropertyOrThrow(A, ! ToString(k), fromValue).
"defineProperty",
// Step 11.c.ii: CreateDataPropertyOrThrow(A, ! ToString(k), fromValue).
"defineProperty",
// Step 12: Perform ? Set(A, "length", actualDeleteCount, true).
"set",
"getOwnPropertyDescriptor",
"defineProperty",
], log);
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.splice
description: >
Non-writable properties are overwritten by CreateDataPropertyOrThrow.
info: |
22.1.3.26 Array.prototype.splice ( start, deleteCount, ...items )
...
11. Repeat, while k < actualDeleteCount
...
c. If fromPresent is true, then
...
ii. Perform ? CreateDataPropertyOrThrow(A, ! ToString(k), fromValue).
...
features: [Symbol.species]
includes: [propertyHelper.js]
---*/
var a = [1];
a.constructor = {};
a.constructor[Symbol.species] = function(len) {
var q = new Array(0);
Object.defineProperty(q, 0, {
value: 0, writable: false, configurable: true, enumerable: false,
});
return q;
};
var r = a.splice(0);
verifyProperty(r, 0, {
value: 1, writable: true, configurable: true, enumerable: true,
});
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function.prototype.bind
description: >
The target function length can exceed 2**31-1.
info: |
19.2.3.2 Function.prototype.bind ( thisArg, ...args )
...
6. If targetHasLength is true, then
a. Let targetLen be ? Get(Target, "length").
b. If Type(targetLen) is not Number, let L be 0.
c. Else,
i. Let targetLen be ToInteger(targetLen).
ii. Let L be the larger of 0 and the result of targetLen minus the number of elements of args.
...
8. Perform ! SetFunctionLength(F, L).
...
---*/
function f(){}
Object.defineProperty(f, "length", {value: 2147483648});
assert.sameValue(f.bind().length, 2147483648);
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.assign
description: >
Symbol-valued properties are copied after String-valued properties.
info: |
19.1.2.1 Object.assign ( target, ...sources )
...
4. For each element nextSource of sources, in ascending index order, do
a. ...
b. Else,
i. Let from be ! ToObject(nextSource).
ii. Let keys be ? from.[[OwnPropertyKeys]]().
c. For each element nextKey of keys in List order, do
...
...
9.1.11.1 OrdinaryOwnPropertyKeys ( O )
...
3. For each own property key P of O that is a String but is not an integer index,
in ascending chronological order of property creation, do
a. Add P as the last element of keys.
4. For each own property key P of O that is a Symbol, in ascending chronological
order of property creation, do
a. Add P as the last element of keys.
...
includes: [compareArray.js]
---*/
var log = [];
var sym1 = Symbol("x");
var sym2 = Symbol("y");
var source = {};
Object.defineProperty(source, sym1, {
get: function(){ log.push("get sym(x)") },
enumerable: true, configurable: true,
});
Object.defineProperty(source, "a", {
get: function(){ log.push("get a") },
enumerable: true, configurable: true,
});
Object.defineProperty(source, sym2, {
get: function(){ log.push("get sym(y)") },
enumerable: true, configurable: true,
});
Object.defineProperty(source, "b", {
get: function(){ log.push("get b") },
enumerable: true, configurable: true,
});
var target = Object.assign({}, source);
assert.compareArray(log, ["get a", "get b", "get sym(x)", "get sym(y)"]);
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object.keys
description: >
Ensure the correct property traps are called on a proxy of an array.
info: |
19.1.2.16 Object.keys ( O )
...
2. Let nameList be ? EnumerableOwnPropertyNames(obj, "key").
...
7.3.21 EnumerableOwnPropertyNames ( O, kind )
...
2. Let ownKeys be ? O.[[OwnPropertyKeys]]().
...
4. For each element key of ownKeys in List order, do
a. If Type(key) is String, then
i. Let desc be ? O.[[GetOwnProperty]](key).
...
features: [Proxy]
includes: [compareArray.js]
---*/
var log = [];
Object.keys(new Proxy([], new Proxy({},{
get(t, pk, r) {
log.push(pk);
}
})));
assert.compareArray([
"ownKeys",
"getOwnPropertyDescriptor",
], log);
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sup-array.prototype.tolocalestring
description: >
Ensure "toLocaleString" is called with locale and options on number elements.
---*/
var n = 0;
var locale = "th-u-nu-thai";
var options = {
minimumFractionDigits: 3
};
assert.sameValue([n].toLocaleString(locale, options), n.toLocaleString(locale, options));
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sup-array.prototype.tolocalestring
description: >
Ensure "toLocaleString" is called with locale and options on number elements.
includes: [testTypedArray.js]
features: [TypedArray]
---*/
var n = 0;
var locale = "th-u-nu-thai";
var options = {
minimumFractionDigits: 3
};
var expected = n.toLocaleString(locale, options);
testWithTypedArrayConstructors(function(TA) {
assert.sameValue(new TA([n]).toLocaleString(locale, options), expected);
});
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-block-static-semantics-early-errors
description: >
Redeclaration with VariableDeclaration (FunctionDeclaration in BlockStatement)
info: |
13.2.1 Static Semantics: Early Errors
It is a Syntax Error if any element of the LexicallyDeclaredNames of
StatementList also occurs in the VarDeclaredNames of StatementList.
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
function g() {
// Create an outer block-statement.
{
// A lexically declared function declaration.
function f() {}
// An inner block-statement with a variable-declared name.
{
var f;
}
}
}
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-async-arrow-function-definitions
description: >
It is a SyntaxError if FormalParameters' default expressions contains await.
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
async(a = await => {}) => {};
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-async-arrow-function-definitions
description: >
It is a SyntaxError if FormalParameters' default expressions contains await.
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
async() => { (a = await/r/g) => {} };
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-async-arrow-function-definitions
description: >
It is a SyntaxError if FormalParameters' default expressions contains await.
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
async(a = (await) => {}) => {};
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-async-arrow-function-definitions
description: >
It is a SyntaxError if FormalParameters' default expressions contains await.
negative:
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated.";
async(a = (...await) => {}) => {};
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-async-arrow-function-definitions
description: >
Escaped "async" followed by a line-terminator is not misinterpreted as an AsyncArrowFunction.
info: |
14.7 Async Function Definitions
async [no LineTerminator here] AsyncArrowBindingIdentifier[?Yield] [no LineTerminator here] => AsyncConciseBody[?In]
5.1.5 Grammar Notation
Terminal symbols of the lexical, RegExp, and numeric string grammars are shown
in fixed width font, both in the productions of the grammars and throughout this
specification whenever the text directly refers to such a terminal symbol. These
are to appear in a script exactly as written. All terminal symbol code points
specified in this way are to be understood as the appropriate Unicode code points
from the Basic Latin range, as opposed to any similar-looking code points from
other Unicode ranges.
features: [async-functions]
---*/
// Throws ReferenceError because reference for "async" cannot be resolved.
assert.throws(ReferenceError, function() {
\u0061sync
p => {}
});
// Copyright (C) 2018 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-asyncgenerator-definitions-evaluatebody
description: >
The generator object is created after FunctionDeclarationInstantiation.
info: |
14.5.10 Runtime Semantics: EvaluateBody
1. Perform ? FunctionDeclarationInstantiation(functionObject, argumentsList).
2. Let generator be ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGeneratorPrototype%",
« [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] »).
3. Perform ! AsyncGeneratorStart(generator, FunctionBody).
...
features: [async-iteration]
---*/
var g = async function*(a = (g.prototype = null)) {}
var oldPrototype = g.prototype;
var it = g();
assert.notSameValue(Object.getPrototypeOf(it), oldPrototype);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment