Update and tests for %RegExpPrototype% methods

A recent web-compatability change to ECMA262 modified the semantics of
the accessor methods on the %RegExpPrototype% intrinsic--the "get"
accessors now include steps dedicated to the case where the "this" value
is the %RegExpPrototype% object itself.

Remove the tests that have been invalidated by this change, introduce
tests asserting the new behavior, and extend coverage for other possible
"this" values.
This commit is contained in:
Mike Pennisi 2016-06-28 17:29:33 -04:00
parent 9114f815a0
commit e1cd1e7f85
24 changed files with 380 additions and 50 deletions

View File

@ -1,12 +0,0 @@
// Copyright (c) 2012 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.10.7.2-1
description: RegExp.prototype.global is a non-generic accessor property
---*/
assert.throws(TypeError, function() {
RegExp.prototype.global;
});

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-get-regexp.prototype.global
es6id: 21.2.5.4
description: A TypeError is thrown when the "this" value is an invalid Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
b. Otherwise, throw a TypeError exception.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get;
assert.throws(TypeError, function() {
get.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
get.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
get.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,38 @@
// 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-get-regexp.prototype.global
es6id: 21.2.5.4
description: A TypeError is thrown when the "this" value is not an Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get;
var symbol = Symbol();
assert.throws(TypeError, function() {
get.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
get.call(null);
}, 'null');
assert.throws(TypeError, function() {
get.call(3);
}, 'number');
assert.throws(TypeError, function() {
get.call('string');
}, 'string');
assert.throws(TypeError, function() {
get.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
get.call(symbol);
}, 'symbol');

View File

@ -0,0 +1,17 @@
// 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-get-regexp.prototype.global
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get;
assert.sameValue(get.call(RegExp.prototype), undefined);

View File

@ -1,12 +0,0 @@
// Copyright (c) 2012 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.10.7.3-1
description: RegExp.prototype.ignoreCase is a non-generic accessor property
---*/
assert.throws(TypeError, function() {
RegExp.prototype.ignoreCase;
});

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-get-regexp.prototype.ignorecase
es6id: 21.2.5.5
description: A TypeError is thrown when the "this" value is an invalid Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
b. Otherwise, throw a TypeError exception.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get;
assert.throws(TypeError, function() {
get.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
get.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
get.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,38 @@
// 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-get-regexp.prototype.ignorecase
es6id: 21.2.5.5
description: A TypeError is thrown when the "this" value is not an Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get;
var symbol = Symbol();
assert.throws(TypeError, function() {
get.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
get.call(null);
}, 'null');
assert.throws(TypeError, function() {
get.call(3);
}, 'number');
assert.throws(TypeError, function() {
get.call('string');
}, 'string');
assert.throws(TypeError, function() {
get.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
get.call(symbol);
}, 'symbol');

View File

@ -0,0 +1,17 @@
// 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-get-regexp.prototype.ignorecase
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get;
assert.sameValue(get.call(RegExp.prototype), undefined);

View File

@ -1,12 +0,0 @@
// Copyright (c) 2012 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.10.7.4-1
description: RegExp.prototype.multiline is a non-generic accessor property
---*/
assert.throws(TypeError, function() {
RegExp.prototype.multiline;
});

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-get-regexp.prototype.multiline
es6id: 21.2.5.7
description: A TypeError is thrown when the "this" value is an invalid Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
b. Otherwise, throw a TypeError exception.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get;
assert.throws(TypeError, function() {
get.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
get.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
get.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,38 @@
// 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-get-regexp.prototype.multiline
es6id: 21.2.5.7
description: A TypeError is thrown when the "this" value is not an Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get;
var symbol = Symbol();
assert.throws(TypeError, function() {
get.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
get.call(null);
}, 'null');
assert.throws(TypeError, function() {
get.call(3);
}, 'number');
assert.throws(TypeError, function() {
get.call('string');
}, 'string');
assert.throws(TypeError, function() {
get.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
get.call(symbol);
}, 'symbol');

View File

@ -0,0 +1,17 @@
// 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-get-regexp.prototype.multiline
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get;
assert.sameValue(get.call(RegExp.prototype), undefined);

View File

@ -1,12 +0,0 @@
// Copyright (c) 2012 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 15.10.7.1-1
description: RegExp.prototype.source is a non-generic accessor property
---*/
assert.throws(TypeError, function() {
RegExp.prototype.source;
});

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-get-regexp.prototype.source
es6id: 21.2.5.10
description: A TypeError is thrown when the "this" value is an invalid Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)".
b. Otherwise, throw a TypeError exception.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get;
assert.throws(TypeError, function() {
get.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
get.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
get.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,38 @@
// 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-get-regexp.prototype.source
es6id: 21.2.5.10
description: A TypeError is thrown when the "this" value is not an Object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get;
var symbol = Symbol();
assert.throws(TypeError, function() {
get.call(undefined);
}, 'undefined');
assert.throws(TypeError, function() {
get.call(null);
}, 'null');
assert.throws(TypeError, function() {
get.call(3);
}, 'number');
assert.throws(TypeError, function() {
get.call('string');
}, 'string');
assert.throws(TypeError, function() {
get.call(true);
}, 'boolean');
assert.throws(TypeError, function() {
get.call(symbol);
}, 'symbol');

View File

@ -0,0 +1,17 @@
// 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-get-regexp.prototype.source
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)".
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get;
assert.sameValue(get.call(RegExp.prototype), '(?:)');

View File

@ -17,4 +17,12 @@ var sticky = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get;
assert.throws(TypeError, function() {
sticky.call({});
});
}, 'ordinary object');
assert.throws(TypeError, function() {
sticky.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
sticky.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,17 @@
// 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-get-regexp.prototype.sticky
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get;
assert.sameValue(get.call(RegExp.prototype), undefined);

View File

@ -17,4 +17,12 @@ var unicode = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get;
assert.throws(TypeError, function() {
unicode.call({});
});
}, 'ordinary object');
assert.throws(TypeError, function() {
unicode.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
unicode.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,17 @@
// 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-get-regexp.prototype.unicode
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get;
assert.sameValue(get.call(RegExp.prototype), undefined);