Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce reliance on fnGlobalObject.js #595

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions test/annexB/built-ins/escape/B.2.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ es5id: B.2.1
description: >
Object.getOwnPropertyDescriptor returns data desc for functions on
built-ins (Global.escape)
includes:
- fnGlobalObject.js
- propertyHelper.js
includes: [propertyHelper.js]
---*/

var global = fnGlobalObject();
var global = this;

verifyWritable(global, "escape");
verifyNotEnumerable(global, "escape");
Expand Down
12 changes: 4 additions & 8 deletions test/annexB/built-ins/unescape/B.2.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ es5id: B.2.2
description: >
Object.getOwnPropertyDescriptor returns data desc for functions on
built-ins (Global.unescape)
includes:
- fnGlobalObject.js
- propertyHelper.js
includes: [propertyHelper.js]
---*/

var global = fnGlobalObject();

verifyWritable(global, "unescape");
verifyNotEnumerable(global, "unescape");
verifyConfigurable(global, "unescape");
verifyWritable(this, "unescape");
verifyNotEnumerable(this, "unescape");
verifyConfigurable(this, "unescape");
3 changes: 1 addition & 2 deletions test/built-ins/Array/isArray/15.4.3.2-1-15.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/*---
es5id: 15.4.3.2-1-15
description: Array.isArray applied to the global object
includes: [fnGlobalObject.js]
---*/

assert.sameValue(Array.isArray(fnGlobalObject()), false, 'Array.isArray(fnGlobalObject())');
assert.sameValue(Array.isArray(this), false, 'Array.isArray(this)');
15 changes: 7 additions & 8 deletions test/built-ins/Array/prototype/every/15.4.4.16-2-15.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/*---
es5id: 15.4.4.16-2-15
description: Array.prototype.every - 'length' is property of the global object
includes: [fnGlobalObject.js]
---*/

function callbackfn1(val, idx, obj) {
Expand All @@ -15,11 +14,11 @@ includes: [fnGlobalObject.js]
return val > 11;
}

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = 12;
fnGlobalObject()[1] = 11;
fnGlobalObject()[2] = 9;
fnGlobalObject().length = 2;
var oldLen = this.length;
this[0] = 12;
this[1] = 11;
this[2] = 9;
this.length = 2;

assert(Array.prototype.every.call(fnGlobalObject(), callbackfn1), 'Array.prototype.every.call(fnGlobalObject(), callbackfn1) !== true');
assert.sameValue(Array.prototype.every.call(fnGlobalObject(), callbackfn2), false, 'Array.prototype.every.call(fnGlobalObject(), callbackfn2)');
assert(Array.prototype.every.call(this, callbackfn1), 'Array.prototype.every.call(this, callbackfn1) !== true');
assert.sameValue(Array.prototype.every.call(this, callbackfn2), false, 'Array.prototype.every.call(this, callbackfn2)');
5 changes: 3 additions & 2 deletions test/built-ins/Array/prototype/every/15.4.4.16-5-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
es5id: 15.4.4.16-5-1
description: Array.prototype.every - thisArg not passed
flags: [noStrict]
includes: [fnGlobalObject.js]
---*/

var global = this;

function callbackfn(val, idx, obj)
{
return this === fnGlobalObject();
return this === global;
}

var arr = [1];
Expand Down
6 changes: 3 additions & 3 deletions test/built-ins/Array/prototype/every/15.4.4.16-5-21.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
/*---
es5id: 15.4.4.16-5-21
description: Array.prototype.every - the global object can be used as thisArg
includes: [fnGlobalObject.js]
---*/

var global = this;
var accessed = false;

function callbackfn(val, idx, obj) {
accessed = true;
return this === fnGlobalObject();
return this === global;
}

assert([11].every(callbackfn, fnGlobalObject()), '[11].every(callbackfn, fnGlobalObject()) !== true');
assert([11].every(callbackfn, global), '[11].every(callbackfn, global) !== true');
assert(accessed, 'accessed !== true');
9 changes: 4 additions & 5 deletions test/built-ins/Array/prototype/every/15.4.4.16-7-c-i-23.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ es5id: 15.4.4.16-7-c-i-23
description: >
Array.prototype.every - This object is an global object which
contains index property
includes: [fnGlobalObject.js]
---*/

function callbackfn(val, idx, obj) {
Expand All @@ -17,8 +16,8 @@ includes: [fnGlobalObject.js]
}
}

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = 11;
fnGlobalObject().length = 1;
var oldLen = this.length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not the focus for this PR but this line is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on both counts

this[0] = 11;
this.length = 1;

assert.sameValue(Array.prototype.every.call(fnGlobalObject(), callbackfn), false, 'Array.prototype.every.call(fnGlobalObject(), callbackfn)');
assert.sameValue(Array.prototype.every.call(this, callbackfn), false, 'Array.prototype.every.call(this, callbackfn)');
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ es5id: 15.4.4.16-7-c-iii-27
description: >
Array.prototype.every - return value of callbackfn is the global
object
includes: [fnGlobalObject.js]
---*/

var global = this;
var accessed = false;

function callbackfn(val, idx, obj) {
accessed = true;
return fnGlobalObject();
return global;
}

assert([11].every(callbackfn), '[11].every(callbackfn) !== true');
Expand Down
13 changes: 6 additions & 7 deletions test/built-ins/Array/prototype/filter/15.4.4.20-2-15.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
/*---
es5id: 15.4.4.20-2-15
description: Array.prototype.filter - 'length' is property of the global object
includes: [fnGlobalObject.js]
---*/

function callbackfn(val, idx, obj) {
return obj.length === 2;
}

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = 12;
fnGlobalObject()[1] = 11;
fnGlobalObject()[2] = 9;
fnGlobalObject().length = 2;
var newArr = Array.prototype.filter.call(fnGlobalObject(), callbackfn);
var oldLen = this.length;
this[0] = 12;
this[1] = 11;
this[2] = 9;
this.length = 2;
var newArr = Array.prototype.filter.call(this, callbackfn);

assert.sameValue(newArr.length, 2, 'newArr.length');
7 changes: 4 additions & 3 deletions test/built-ins/Array/prototype/filter/15.4.4.20-5-21.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
/*---
es5id: 15.4.4.20-5-21
description: Array.prototype.filter - the global object can be used as thisArg
includes: [fnGlobalObject.js]
---*/

var global = this;

var accessed = false;

function callbackfn(val, idx, obj) {
accessed = true;
return this === fnGlobalObject();
return this === global;
}

var newArr = [11].filter(callbackfn, fnGlobalObject());
var newArr = [11].filter(callbackfn, global);

assert.sameValue(newArr[0], 11, 'newArr[0]');
assert(accessed, 'accessed !== true');
9 changes: 4 additions & 5 deletions test/built-ins/Array/prototype/filter/15.4.4.20-9-c-i-23.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ es5id: 15.4.4.20-9-c-i-23
description: >
Array.prototype.filter - This object is the global object which
contains index property
includes: [fnGlobalObject.js]
---*/

function callbackfn(val, idx, obj) {
return idx === 0 && val === 11;
}

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = 11;
fnGlobalObject().length = 1;
var newArr = Array.prototype.filter.call(fnGlobalObject(), callbackfn);
var oldLen = this.length;
this[0] = 11;
this.length = 1;
var newArr = Array.prototype.filter.call(this, callbackfn);

assert.sameValue(newArr.length, 1, 'newArr.length');
assert.sameValue(newArr[0], 11, 'newArr[0]');
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ es5id: 15.4.4.20-9-c-iii-28
description: >
Array.prototype.filter - return value of callbackfn is the global
object
includes: [fnGlobalObject.js]
---*/

var global = this;
function callbackfn(val, idx, obj) {
return fnGlobalObject();
return global;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole test seems unnecessary. It's testing a ToBoolean(global) === true. That can be done with a simple {}.

}

var newArr = [11].filter(callbackfn);
Expand Down
13 changes: 6 additions & 7 deletions test/built-ins/Array/prototype/forEach/15.4.4.18-2-15.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
/*---
es5id: 15.4.4.18-2-15
description: Array.prototype.forEach - 'length' is property of the global object
includes: [fnGlobalObject.js]
---*/

var result = false;
function callbackfn(val, idx, obj) {
result = (obj.length === 2);
}

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = 12;
fnGlobalObject()[1] = 11;
fnGlobalObject()[2] = 9;
fnGlobalObject().length = 2;
Array.prototype.forEach.call(fnGlobalObject(), callbackfn);
var oldLen = this.length;
this[0] = 12;
this[1] = 11;
this[2] = 9;
this.length = 2;
Array.prototype.forEach.call(this, callbackfn);

assert(result, 'result !== true');
6 changes: 3 additions & 3 deletions test/built-ins/Array/prototype/forEach/15.4.4.18-5-21.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
/*---
es5id: 15.4.4.18-5-21
description: Array.prototype.forEach - the global object can be used as thisArg
includes: [fnGlobalObject.js]
---*/

var global = this;
var result = false;
function callbackfn(val, idx, obj) {
result = (this === fnGlobalObject());
result = (this === global);
}

[11].forEach(callbackfn, fnGlobalObject());
[11].forEach(callbackfn, this);

assert(result, 'result !== true');
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ es5id: 15.4.4.18-7-c-i-23
description: >
Array.prototype.forEach - This object is an global object which
contains index property
includes: [fnGlobalObject.js]
---*/

var testResult = false;
Expand All @@ -17,10 +16,10 @@ includes: [fnGlobalObject.js]
}
}

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = 11;
fnGlobalObject().length = 1;
var oldLen = this.length;
this[0] = 11;
this.length = 1;

Array.prototype.forEach.call(fnGlobalObject(), callbackfn);
Array.prototype.forEach.call(this, callbackfn);

assert(testResult, 'testResult !== true');
9 changes: 4 additions & 5 deletions test/built-ins/Array/prototype/indexOf/15.4.4.14-1-17.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
/*---
es5id: 15.4.4.14-1-17
description: Array.prototype.indexOf applied to the global object
includes: [fnGlobalObject.js]
---*/

var oldLen = fnGlobalObject().length;
fnGlobalObject()[1] = true;
fnGlobalObject().length = 2;
var oldLen = this.length;
this[1] = true;
this.length = 2;

assert.sameValue(Array.prototype.indexOf.call(fnGlobalObject(), true), 1, 'Array.prototype.indexOf.call(fnGlobalObject(), true)');
assert.sameValue(Array.prototype.indexOf.call(this, true), 1, 'Array.prototype.indexOf.call(this, true)');
15 changes: 7 additions & 8 deletions test/built-ins/Array/prototype/indexOf/15.4.4.14-2-15.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
/*---
es5id: 15.4.4.14-2-15
description: Array.prototype.indexOf - 'length' is property of the global object
includes: [fnGlobalObject.js]
---*/

var targetObj = {};

var oldLen = fnGlobalObject().length;
fnGlobalObject().length = 2;
var oldLen = this.length;
this.length = 2;

fnGlobalObject()[1] = targetObj;
this[1] = targetObj;

assert.sameValue(Array.prototype.indexOf.call(fnGlobalObject(), targetObj), 1, 'Array.prototype.indexOf.call(fnGlobalObject(), targetObj)');
assert.sameValue(Array.prototype.indexOf.call(this, targetObj), 1, 'Array.prototype.indexOf.call(this, targetObj)');

fnGlobalObject()[1] = {};
fnGlobalObject()[2] = targetObj;
this[1] = {};
this[2] = targetObj;

assert.sameValue(Array.prototype.indexOf.call(fnGlobalObject(), targetObj), -1, 'Array.prototype.indexOf.call(fnGlobalObject(), targetObj)');
assert.sameValue(Array.prototype.indexOf.call(this, targetObj), -1, 'Array.prototype.indexOf.call(this, targetObj)');
17 changes: 8 additions & 9 deletions test/built-ins/Array/prototype/indexOf/15.4.4.14-9-b-i-23.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
/*---
es5id: 15.4.4.14-9-b-i-23
description: Array.prototype.indexOf - This object is the global object
includes: [fnGlobalObject.js]
---*/

var targetObj = {};

var oldLen = fnGlobalObject().length;
fnGlobalObject()[0] = targetObj;
fnGlobalObject()[100] = "100";
fnGlobalObject()[200] = "200";
fnGlobalObject().length = 200;
var oldLen = this.length;
this[0] = targetObj;
this[100] = "100";
this[200] = "200";
this.length = 200;

assert.sameValue(Array.prototype.indexOf.call(fnGlobalObject(), targetObj), 0, 'Array.prototype.indexOf.call(fnGlobalObject(), targetObj)');
assert.sameValue(Array.prototype.indexOf.call(fnGlobalObject(), "100"), 100, 'Array.prototype.indexOf.call(fnGlobalObject(), "100")');
assert.sameValue(Array.prototype.indexOf.call(fnGlobalObject(), "200"), -1, 'Array.prototype.indexOf.call(fnGlobalObject(), "200")');
assert.sameValue(Array.prototype.indexOf.call(this, targetObj), 0, 'Array.prototype.indexOf.call(this, targetObj)');
assert.sameValue(Array.prototype.indexOf.call(this, "100"), 100, 'Array.prototype.indexOf.call(this, "100")');
assert.sameValue(Array.prototype.indexOf.call(this, "200"), -1, 'Array.prototype.indexOf.call(this, "200")');
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
/*---
es5id: 15.4.4.15-1-17
description: Array.prototype.lastIndexOf applied to the global object
includes: [fnGlobalObject.js]
---*/

var targetObj = ["global"];

var oldLen = fnGlobalObject().length;
fnGlobalObject()[1] = targetObj;
fnGlobalObject().length = 3;
var oldLen = this.length;
this[1] = targetObj;
this.length = 3;

assert.sameValue(Array.prototype.lastIndexOf.call(fnGlobalObject(), targetObj), 1, 'Array.prototype.lastIndexOf.call(fnGlobalObject(), targetObj)');
assert.sameValue(Array.prototype.lastIndexOf.call(this, targetObj), 1, 'Array.prototype.lastIndexOf.call(this, targetObj)');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is another case that could be done with an ordinary object.

And that's another case that shouldn't be focus of this PR.

Loading