Skip to content
Snippets Groups Projects
Commit e1cd1e7f authored by Mike Pennisi's avatar Mike Pennisi
Browse files

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.
parent 9114f815
No related branches found
No related tags found
No related merge requests found
Showing
with 354 additions and 49 deletions
// 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;
});
// 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');
// 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');
// 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);
// 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;
});
// 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');
// 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');
// 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);
// 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;
});
// 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');
// 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');
// 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);
// 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;
});
// 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');
// 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');
// 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), '(?:)');
...@@ -17,4 +17,12 @@ var sticky = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get; ...@@ -17,4 +17,12 @@ var sticky = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
sticky.call({}); sticky.call({});
}); }, 'ordinary object');
assert.throws(TypeError, function() {
sticky.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
sticky.call(arguments);
}, 'arguments object');
// 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);
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