Skip to content

Commit

Permalink
use isConstructor assertion in "non-constructor" tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb authored and rwaldron committed Apr 27, 2022
1 parent 7f2668f commit 28b31c0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/

assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);

var a = [];

a.constructor = {};
Expand Down
11 changes: 9 additions & 2 deletions test/built-ins/Array/prototype/filter/create-species-non-ctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/

assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);

var a = [];
var callCount = 0;
var cb = function() {
Expand All @@ -33,5 +40,5 @@ a.constructor[Symbol.species] = parseInt;

assert.throws(TypeError, function() {
a.filter(cb);
});
}, 'a.filter(cb) throws a TypeError exception');
assert.sameValue(callCount, 0);
11 changes: 9 additions & 2 deletions test/built-ins/Array/prototype/map/create-species-non-ctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/

assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);

var a = [];
var callCount = 0;
var cb = function() {
Expand All @@ -33,5 +40,5 @@ a.constructor[Symbol.species] = parseInt;

assert.throws(TypeError, function() {
a.map(cb);
});
}, 'a.map(cb) throws a TypeError exception');
assert.sameValue(callCount, 0);
11 changes: 9 additions & 2 deletions test/built-ins/Array/prototype/slice/create-species-non-ctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/

assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);

var a = [];

a.constructor = {};
a.constructor[Symbol.species] = parseInt;

assert.throws(TypeError, function() {
a.slice();
});
}, 'a.slice() throws a TypeError exception');
11 changes: 9 additions & 2 deletions test/built-ins/Array/prototype/splice/create-species-non-ctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ info: |
b. If C is null, let C be undefined.
[...]
9. If IsConstructor(C) is false, throw a TypeError exception.
features: [Symbol.species]
includes: [isConstructor.js]
features: [Symbol.species, Reflect.construct]
---*/

assert.sameValue(
isConstructor(parseInt),
false,
'precondition: isConstructor(parseInt) must return false'
);

var a = [];

a.constructor = {};
a.constructor[Symbol.species] = parseInt;

assert.throws(TypeError, function() {
a.splice();
});
}, 'a.splice() throws a TypeError exception');
8 changes: 8 additions & 0 deletions test/built-ins/RegExp/prototype/toString/S15.10.6.4_A6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
info: RegExp.prototype.toString has not prototype property
es5id: 15.10.6.4_A6
description: Checking RegExp.prototype.toString.prototype
includes: [isConstructor.js]
features: [Reflect.construct]
---*/
assert.sameValue(
RegExp.prototype.toString.prototype,
undefined,
'The value of RegExp.prototype.toString.prototype is expected to equal undefined'
);

assert.sameValue(
isConstructor(RegExp.prototype.toString),
false,
'isConstructor(RegExp.prototype.toString) must return false'
);
8 changes: 8 additions & 0 deletions test/built-ins/RegExp/prototype/toString/S15.10.6.4_A7.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
info: RegExp.prototype.toString can't be used as constructor
es5id: 15.10.6.4_A7
description: Checking if creating the RegExp.prototype.toString object fails
includes: [isConstructor.js]
features: [Reflect.construct]
---*/

var __FACTORY = RegExp.prototype.toString;
Expand All @@ -20,4 +22,10 @@ try {
);
}

assert.sameValue(
isConstructor(RegExp.prototype.toString),
false,
'isConstructor(RegExp.prototype.toString) must return false'
);

// TODO: Convert to assert.throws() format.

0 comments on commit 28b31c0

Please sign in to comment.