Improve coverage for section 9 (#726)

* Assert creation of 'arguments' object

Ensure that the 'arguments' object is created in cases where it is not
required by the body but is required by the parameters.

* Add tests for cases that disable "arguments" map

* Add tests for NewTarget override of bound function

* Add test for properties of exotic String objects
This commit is contained in:
jugglinmike 2016-08-05 13:07:02 -04:00 committed by Tom Care
parent 8a6d7a49ee
commit c5cbf4122d
17 changed files with 464 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget
es6id: 9.4.1.2
description: >
The NewTarget value is changed to the target function when the bound function
object is constructed using Reflect.construct and the "bound target" is
specified as the NewTarget value (and the bound target is itself a bound
function)
info: |
[...]
5. If SameValue(F, newTarget) is true, let newTarget be target.
6. Return ? Construct(target, args, newTarget).
features: [Reflect, new.target]
---*/
var newTarget;
function A() {
newTarget = new.target;
}
var B = A.bind();
var C = B.bind();
var c = Reflect.construct(C, [], B);
assert.sameValue(newTarget, A);
assert.sameValue(Object.getPrototypeOf(c), A.prototype);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget
es6id: 9.4.1.2
description: >
The NewTarget value is changed to the target function when the bound function
object is constructed using Reflect.construct and the "bound target" is
specified as the NewTarget value
info: |
[...]
5. If SameValue(F, newTarget) is true, let newTarget be target.
6. Return ? Construct(target, args, newTarget).
features: [Reflect, new.target]
---*/
var newTarget;
function A() {
newTarget = new.target;
}
var B = A.bind();
var C = B.bind();
var c = Reflect.construct(C, [], A);
assert.sameValue(newTarget, A);
assert.sameValue(Object.getPrototypeOf(c), A.prototype);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget
es6id: 9.4.1.2
description: >
The NewTarget value is changed to the target function when the bound function
object is constructed using the `new` operator
info: |
[...]
5. If SameValue(F, newTarget) is true, let newTarget be target.
6. Return ? Construct(target, args, newTarget).
features: [new.target]
---*/
var newTarget;
function A() {
newTarget = new.target;
}
var B = A.bind();
var C = B.bind();
var c = new C();
assert.sameValue(newTarget, A);
assert.sameValue(Object.getPrototypeOf(c), A.prototype);

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget
es6id: 9.4.1.2
description: >
The NewTarget value is changed to the target function when the bound function
object is constructed using Reflect.construct and the bound function is
specified as the NewTarget value
info: |
[...]
5. If SameValue(F, newTarget) is true, let newTarget be target.
6. Return ? Construct(target, args, newTarget).
features: [Reflect, new.target]
---*/
var newTarget;
function A() {
newTarget = new.target;
}
var B = A.bind();
var C = B.bind();
var c = Reflect.construct(C, [], C);
assert.sameValue(newTarget, A);
assert.sameValue(Object.getPrototypeOf(c), A.prototype);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-string-exotic-objects-getownproperty-p
es6id: 9.4.3.1
description: >
Property descriptor for numeric "own" properties of an exotic String object
info: |
[...]
12. Let resultStr be a String value of length 1, containing one code unit
from str, specifically the code unit at index index.
13. Return a PropertyDescriptor{[[Value]]: resultStr, [[Writable]]: false,
[[Enumerable]]: true, [[Configurable]]: false}.
includes: [propertyHelper.js]
---*/
var str = new String('abc');
assert.sameValue(str[0], 'a');
verifyEnumerable(str, '0');
verifyNotWritable(str, '0');
verifyNotConfigurable(str, '0');
assert.sameValue(str[1], 'b');
verifyEnumerable(str, '1');
verifyNotWritable(str, '1');
verifyNotConfigurable(str, '1');
assert.sameValue(str[2], 'c');
verifyEnumerable(str, '2');
verifyNotWritable(str, '2');
verifyNotConfigurable(str, '2');

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments are "unmapped" when paramater list is non-simple due to "default"
parameter
info: |
[...]
9. Let simpleParameterList be IsSimpleParameterList of formals.
[...]
22. If argumentsObjectNeeded is true, then
a. If strict is true or if simpleParameterList is false, then
i. Let ao be CreateUnmappedArgumentsObject(argumentsList).
[...]
---*/
var value;
function dflt(a, b = 0) {
arguments[0] = 2;
value = a;
}
dflt(1);
assert.sameValue(value, 1);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments are "unmapped" when paramater list is non-simple due to
destructuring pattern
info: |
[...]
9. Let simpleParameterList be IsSimpleParameterList of formals.
[...]
22. If argumentsObjectNeeded is true, then
a. If strict is true or if simpleParameterList is false, then
i. Let ao be CreateUnmappedArgumentsObject(argumentsList).
[...]
---*/
var value;
function dstr(a, [b]) {
arguments[0] = 2;
value = a;
}
dstr(1, []);
assert.sameValue(value, 1);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments are "unmapped" when paramater list is non-simple due to "rest"
parameter
info: |
[...]
9. Let simpleParameterList be IsSimpleParameterList of formals.
[...]
22. If argumentsObjectNeeded is true, then
a. If strict is true or if simpleParameterList is false, then
i. Let ao be CreateUnmappedArgumentsObject(argumentsList).
[...]
---*/
var value;
function rest(a, ...b) {
arguments[0] = 2;
value = a;
}
rest(1);
assert.sameValue(value, 1);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a lexically-scoped
binding named "arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
var f = function(x = args = arguments) {
function arguments() {}
};
f();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a function named
"arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
var f = function (x = args = arguments) {
let arguments;
};
f();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a lexically-scoped
binding named "arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
var g = function* (x = args = arguments) {
function arguments() {}
};
g().next();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a function named
"arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
var g = function* (x = args = arguments) {
let arguments;
};
g().next();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a lexically-scoped
binding named "arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
function f(x = args = arguments) {
function arguments() {}
}
f();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a function named
"arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
function f(x = args = arguments) {
let arguments;
}
f();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a lexically-scoped
binding named "arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
function* g(x = args = arguments) {
function arguments() {}
}
g().next();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-functiondeclarationinstantiation
es6id: 9.2.12
description: >
Arguments object is created even when the body contains a function named
"arguments"
info: |
[...]
19. Else if "arguments" is an element of parameterNames, then
a. Let argumentsObjectNeeded be false.
20. Else if hasParameterExpressions is false, then
a. If "arguments" is an element of functionNames or if "arguments" is an
element of lexicalNames, then
i. Let argumentsObjectNeeded be false.
[...]
flags: [noStrict]
---*/
var args;
function* g(x = args = arguments) {
let arguments;
}
g().next();
assert.sameValue(typeof args, 'object');
assert.sameValue(args.length, 0);