mirror of https://github.com/tc39/test262.git
commit
df1d78d10f
|
@ -0,0 +1,67 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Initialization from a RegExp-like object (with flag overrides)
|
||||
es6id: 21.2.3.1
|
||||
info: >
|
||||
1. Let patternIsRegExp be IsRegExp(pattern).
|
||||
[...]
|
||||
6. Else if patternIsRegExp is true, then
|
||||
a. Let P be Get(pattern, "source").
|
||||
b. ReturnIfAbrupt(P).
|
||||
c. If flags is undefined, then
|
||||
[...]
|
||||
d. Else, let F be flags.
|
||||
[...]
|
||||
10. Return RegExpInitialize(O, P, F).
|
||||
features: [Symbol, Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
source: 'source text'
|
||||
};
|
||||
var result;
|
||||
|
||||
Object.defineProperty(obj, 'flags', {
|
||||
get: function() {
|
||||
$ERROR('The `flags` property value should not be referenced.');
|
||||
}
|
||||
});
|
||||
|
||||
obj[Symbol.match] = true;
|
||||
result = new RegExp(obj, 'g');
|
||||
assert.sameValue(
|
||||
result.source, 'source text', '@@match specified as a primitive boolean'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.flags, 'g', '@@match specified as a primitive boolean'
|
||||
);
|
||||
|
||||
obj[Symbol.match] = 'string';
|
||||
result = new RegExp(obj, 'g');
|
||||
assert.sameValue(
|
||||
result.source, 'source text', '@@match specified as a primitive string'
|
||||
);
|
||||
assert.sameValue(result.flags, 'g', '@@match specified as a primitive string');
|
||||
|
||||
obj[Symbol.match] = [];
|
||||
result = new RegExp(obj, 'g');
|
||||
assert.sameValue(
|
||||
result.source, 'source text', '@@match specified as an array'
|
||||
);
|
||||
assert.sameValue(result.flags, 'g', '@@match specified as an array');
|
||||
|
||||
obj[Symbol.match] = Symbol();
|
||||
result = new RegExp(obj, 'g');
|
||||
assert.sameValue(
|
||||
result.source, 'source text', '@@match specified as a Symbol'
|
||||
);
|
||||
assert.sameValue(result.flags, 'g', '@@match specified as a Symbol');
|
||||
|
||||
obj[Symbol.match] = 86;
|
||||
result = new RegExp(obj, 'g');
|
||||
assert.sameValue(
|
||||
result.source, 'source text', '@@match specified as a primitive number'
|
||||
);
|
||||
assert.sameValue(result.flags, 'g', '@@match specified as a primitive number');
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when accessing `constructor` property of RegExp-like objects
|
||||
es6id: 21.2.3.1
|
||||
info: >
|
||||
1. Let patternIsRegExp be IsRegExp(pattern).
|
||||
[...]
|
||||
3. If NewTarget is not undefined, let newTarget be NewTarget.
|
||||
4. Else,
|
||||
a. Let newTarget be the active function object.
|
||||
b. If patternIsRegExp is true and flags is undefined, then
|
||||
i. Let patternConstructor be Get(pattern, "constructor").
|
||||
ii. ReturnIfAbrupt(patternConstructor).
|
||||
iii. If SameValue(newTarget, patternConstructor) is true, return
|
||||
pattern.
|
||||
features: [Symbol, Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = Object.defineProperty({}, 'constructor', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
obj[Symbol.match] = true;
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = 'string';
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = [];
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = Symbol()
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = 86;
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp(obj);
|
||||
});
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown from `flags` property of a RegExp-like object
|
||||
es6id: 21.2.3.1
|
||||
info: >
|
||||
1. Let patternIsRegExp be IsRegExp(pattern).
|
||||
[...]
|
||||
6. Else if patternIsRegExp is true, then
|
||||
[...]
|
||||
c. If flags is undefined, then
|
||||
i. Let F be Get(pattern, "flags").
|
||||
ii. ReturnIfAbrupt(F).
|
||||
features: [Symbol, Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, 'flags', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
obj[Symbol.match] = true;
|
||||
assert.throws(Test262Error, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = 'string';
|
||||
assert.throws(Test262Error, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = [];
|
||||
assert.throws(Test262Error, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = Symbol();
|
||||
assert.throws(Test262Error, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = 86;
|
||||
assert.throws(Test262Error, function() {
|
||||
new RegExp(obj);
|
||||
});
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown from `source` property of a RegExp-like object
|
||||
es6id: 21.2.3.1
|
||||
info: >
|
||||
1. Let patternIsRegExp be IsRegExp(pattern).
|
||||
[...]
|
||||
6. Else if patternIsRegExp is true, then
|
||||
a. Let P be Get(pattern, "source").
|
||||
b. ReturnIfAbrupt(P).
|
||||
features: [Symbol, Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {};
|
||||
function CustomError() {}
|
||||
Object.defineProperty(obj, 'source', {
|
||||
get: function() {
|
||||
throw new CustomError();
|
||||
}
|
||||
});
|
||||
Object.defineProperty(obj, 'flags', {
|
||||
get: function() {
|
||||
$ERROR('the `flags` property should not be referenced before `source`');
|
||||
}
|
||||
});
|
||||
|
||||
obj[Symbol.match] = true;
|
||||
assert.throws(CustomError, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = 'string';
|
||||
assert.throws(CustomError, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = [];
|
||||
assert.throws(CustomError, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = Symbol();
|
||||
assert.throws(CustomError, function() {
|
||||
new RegExp(obj);
|
||||
});
|
||||
|
||||
obj[Symbol.match] = 86;
|
||||
assert.throws(CustomError, function() {
|
||||
new RegExp(obj);
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Skipping construction from RegExp-like objects
|
||||
es6id: 21.2.3.1
|
||||
info: >
|
||||
1. Let patternIsRegExp be IsRegExp(pattern).
|
||||
[...]
|
||||
3. If NewTarget is not undefined, let newTarget be NewTarget.
|
||||
4. Else,
|
||||
a. Let newTarget be the active function object.
|
||||
b. If patternIsRegExp is true and flags is undefined, then
|
||||
i. Let patternConstructor be Get(pattern, "constructor").
|
||||
ii. ReturnIfAbrupt(patternConstructor).
|
||||
iii. If SameValue(newTarget, patternConstructor) is true, return
|
||||
pattern.
|
||||
features: [Symbol, Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
constructor: RegExp
|
||||
};
|
||||
|
||||
obj[Symbol.match] = true;
|
||||
assert.sameValue(RegExp(obj), obj);
|
||||
|
||||
obj[Symbol.match] = 'string';
|
||||
assert.sameValue(RegExp(obj), obj);
|
||||
|
||||
obj[Symbol.match] = [];
|
||||
assert.sameValue(RegExp(obj), obj);
|
||||
|
||||
obj[Symbol.match] = Symbol();
|
||||
assert.sameValue(RegExp(obj), obj);
|
||||
|
||||
obj[Symbol.match] = 86;
|
||||
assert.sameValue(RegExp(obj), obj);
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Initialization from a RegExp-like object
|
||||
es6id: 21.2.3.1
|
||||
info: >
|
||||
1. Let patternIsRegExp be IsRegExp(pattern).
|
||||
[...]
|
||||
6. Else if patternIsRegExp is true, then
|
||||
a. Let P be Get(pattern, "source").
|
||||
b. ReturnIfAbrupt(P).
|
||||
c. If flags is undefined, then
|
||||
i. Let F be Get(pattern, "flags").
|
||||
ii. ReturnIfAbrupt(F).
|
||||
d. Else, let F be flags.
|
||||
[...]
|
||||
10. Return RegExpInitialize(O, P, F).
|
||||
features: [Symbol, Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
source: 'source text',
|
||||
flags: 'i'
|
||||
};
|
||||
var result;
|
||||
|
||||
obj[Symbol.match] = true;
|
||||
result = new RegExp(obj);
|
||||
assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
|
||||
assert.sameValue(result.source, 'source text');
|
||||
assert.sameValue(result.flags, 'i');
|
||||
|
||||
obj[Symbol.match] = 'string';
|
||||
result = new RegExp(obj);
|
||||
assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
|
||||
assert.sameValue(result.source, 'source text');
|
||||
assert.sameValue(result.flags, 'i');
|
||||
|
||||
obj[Symbol.match] = [];
|
||||
result = new RegExp(obj);
|
||||
assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
|
||||
assert.sameValue(result.source, 'source text');
|
||||
assert.sameValue(result.flags, 'i');
|
||||
|
||||
obj[Symbol.match] = Symbol();
|
||||
result = new RegExp(obj);
|
||||
assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
|
||||
assert.sameValue(result.source, 'source text');
|
||||
assert.sameValue(result.flags, 'i');
|
||||
|
||||
obj[Symbol.match] = 86;
|
||||
result = new RegExp(obj);
|
||||
assert.sameValue(Object.getPrototypeOf(result), RegExp.prototype);
|
||||
assert.sameValue(result.source, 'source text');
|
||||
assert.sameValue(result.flags, 'i');
|
|
@ -0,0 +1,97 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Type coercion of `global` property value
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
6. Let global be ToBoolean(Get(R, "global")).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var val, result;
|
||||
Object.defineProperty(r, 'global', {
|
||||
get: function() {
|
||||
return val;
|
||||
}
|
||||
});
|
||||
|
||||
val = false;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'a');
|
||||
|
||||
val = '';
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'a');
|
||||
|
||||
val = 0;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'a');
|
||||
|
||||
val = null;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'a');
|
||||
|
||||
val = undefined;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'a');
|
||||
|
||||
val = true;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 'a');
|
||||
assert.sameValue(result[1], 'b');
|
||||
|
||||
val = 'truthy';
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 'a');
|
||||
assert.sameValue(result[1], 'b');
|
||||
|
||||
val = 86;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 'a');
|
||||
assert.sameValue(result[1], 'b');
|
||||
|
||||
val = [];
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 'a');
|
||||
assert.sameValue(result[1], 'b');
|
||||
|
||||
val = Symbol.match;
|
||||
result = r[Symbol.match]('ab');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
assert.sameValue(result[0], 'a');
|
||||
assert.sameValue(result[1], 'b');
|
34
test/built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex-err.js
vendored
Normal file
34
test/built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when coercion of `lastIndex` attribute throws an error
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
4. Let lastIndex be ToLength(Get(R,"lastIndex")).
|
||||
5. ReturnIfAbrupt(lastIndex).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
r.lastIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Type coercion of `lastIndex` property value
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
4. Let lastIndex be ToLength(Get(R,"lastIndex")).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./y;
|
||||
var result;
|
||||
|
||||
r.lastIndex = '1.9';
|
||||
|
||||
result = r[Symbol.match]('abc');
|
||||
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'b');
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Type coercion of `sticky` property value
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
8. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
[...]
|
||||
18. If global is true or sticky is true,
|
||||
a. Let setStatus be Set(R, "lastIndex", e, true).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var val;
|
||||
Object.defineProperty(r, 'sticky', {
|
||||
get: function() {
|
||||
return val;
|
||||
}
|
||||
});
|
||||
|
||||
val = false;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 0, 'literal false');
|
||||
|
||||
val = '';
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 0, 'empty string');
|
||||
|
||||
val = 0;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 0, 'zero');
|
||||
|
||||
val = null;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 0, 'null');
|
||||
|
||||
val = undefined;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 0, 'undefined');
|
||||
|
||||
val = true;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 1, 'literal true');
|
||||
|
||||
r.lastIndex = 0;
|
||||
val = 'truthy';
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 1, 'non-empty string');
|
||||
|
||||
r.lastIndex = 0;
|
||||
val = 86;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 1, 'nonzero number');
|
||||
|
||||
r.lastIndex = 0;
|
||||
val = [];
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 1, 'array');
|
||||
|
||||
r.lastIndex = 0;
|
||||
val = Symbol.match;
|
||||
r[Symbol.match]('a');
|
||||
assert.sameValue(r.lastIndex, 1, 'symbol');
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Return value after a match failure
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
3. Let length be the number of code units in S.
|
||||
4. Let lastIndex be ToLength(Get(R,"lastIndex")).
|
||||
[...]
|
||||
14. Let matchSucceeded be false.
|
||||
15. Repeat, while matchSucceeded is false
|
||||
a. If lastIndex > length, then
|
||||
i. Let setStatus be Set(R, "lastIndex", 0, true).
|
||||
ii. ReturnIfAbrupt(setStatus).
|
||||
iii. Return null.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/;
|
||||
|
||||
assert.sameValue(r[Symbol.match]('b'), null);
|
40
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-set-lastindex-err.js
vendored
Normal file
40
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-set-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown while setting `lastIndex` after a match failure
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
3. Let length be the number of code units in S.
|
||||
4. Let lastIndex be ToLength(Get(R,"lastIndex")).
|
||||
[...]
|
||||
14. Let matchSucceeded be false.
|
||||
15. Repeat, while matchSucceeded is false
|
||||
a. If lastIndex > length, then
|
||||
i. Let setStatus be Set(R, "lastIndex", 0, true).
|
||||
ii. ReturnIfAbrupt(setStatus).
|
||||
iii. Return null.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/;
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('b');
|
||||
});
|
39
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-set-lastindex.js
vendored
Normal file
39
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-set-lastindex.js
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Setting `lastIndex` to `0` after a match failure
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
3. Let length be the number of code units in S.
|
||||
4. Let lastIndex be ToLength(Get(R,"lastIndex")).
|
||||
[...]
|
||||
14. Let matchSucceeded be false.
|
||||
15. Repeat, while matchSucceeded is false
|
||||
a. If lastIndex > length, then
|
||||
i. Let setStatus be Set(R, "lastIndex", 0, true).
|
||||
ii. ReturnIfAbrupt(setStatus).
|
||||
iii. Return null.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/;
|
||||
r.lastIndex = 3;
|
||||
|
||||
r[Symbol.match]('b');
|
||||
|
||||
assert.sameValue(r.lastIndex, 0);
|
35
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-return-val.js
vendored
Normal file
35
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-return-val.js
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Return value after a "sticky" match failure
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
8. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
[...]
|
||||
14. Let matchSucceeded be false.
|
||||
15. Repeat, while matchSucceeded is false
|
||||
[...]
|
||||
c. If r is failure, then
|
||||
i. If sticky is true, then
|
||||
1. Let setStatus be Set(R, "lastIndex", 0, true).
|
||||
2. ReturnIfAbrupt(setStatus).
|
||||
3. Return null.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
assert.sameValue(/a/y[Symbol.match]('ba'), null);
|
42
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex-err.js
vendored
Normal file
42
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown while setting `lastIndex` after a "sticky" match
|
||||
failure
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
8. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
[...]
|
||||
14. Let matchSucceeded be false.
|
||||
15. Repeat, while matchSucceeded is false
|
||||
[...]
|
||||
c. If r is failure, then
|
||||
i. If sticky is true, then
|
||||
1. Let setStatus be Set(R, "lastIndex", 0, true).
|
||||
2. ReturnIfAbrupt(setStatus).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/y;
|
||||
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('ba');
|
||||
});
|
38
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex.js
vendored
Normal file
38
test/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex.js
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Setting `lastIndex` to `0` after a "sticky" match failure
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
8. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
[...]
|
||||
14. Let matchSucceeded be false.
|
||||
15. Repeat, while matchSucceeded is false
|
||||
[...]
|
||||
c. If r is failure, then
|
||||
i. If sticky is true, then
|
||||
1. Let setStatus be Set(R, "lastIndex", 0, true).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/y;
|
||||
r.lastIndex = 1;
|
||||
|
||||
r[Symbol.match]('aba');
|
||||
|
||||
assert.sameValue(r.lastIndex, 0);
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when error thrown by accessing the `global` property
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
6. Let global be ToBoolean(Get(R, "global")).
|
||||
7. ReturnIfAbrupt(global).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var callCount = 0;
|
||||
Object.defineProperty(r, 'global', {
|
||||
get: function() {
|
||||
callCount += 1;
|
||||
|
||||
if (callCount > 1) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when error thrown by accessing the `sticky` property
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
8. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
9. ReturnIfAbrupt(sticky).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var shouldThrow = false;
|
||||
Object.defineProperty(r, 'sticky', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Extended unicode support is determined by internal slot (not `unicode`
|
||||
property)
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
12. Let flags be the value of R’s [[OriginalFlags]] internal slot.
|
||||
13. If flags contains "u", let fullUnicode be true, else let fullUnicode be
|
||||
false.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r;
|
||||
|
||||
r = /\udf06/;
|
||||
Object.defineProperty(r, 'unicode', { value: true });
|
||||
assert.notSameValue(r[Symbol.match]('\ud834\udf06'), null);
|
||||
|
||||
r = /\udf06/u;
|
||||
Object.defineProperty(r, 'unicode', { value: false });
|
||||
assert.sameValue(r[Symbol.match]('\ud834\udf06'), null);
|
43
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex-err.js
vendored
Normal file
43
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown while setting `lastIndex` after a "global" match
|
||||
success
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
18. If global is true or sticky is true,
|
||||
a. Let setStatus be Set(R, "lastIndex", e, true).
|
||||
b. ReturnIfAbrupt(setStatus).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /b/;
|
||||
var callCount = 0;
|
||||
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
Object.defineProperty(r, 'global', {
|
||||
get: function() {
|
||||
callCount += 1;
|
||||
return callCount > 1;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('abc');
|
||||
});
|
41
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex.js
vendored
Normal file
41
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex.js
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Setting `lastIndex` after a "global" match success
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
16. Let e be r's endIndex value.
|
||||
[...]
|
||||
18. If global is true or sticky is true,
|
||||
a. Let setStatus be Set(R, "lastIndex", e, true).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /b/;
|
||||
var callCount = 0;
|
||||
|
||||
Object.defineProperty(r, 'global', {
|
||||
get: function() {
|
||||
callCount += 1;
|
||||
return callCount > 1;
|
||||
}
|
||||
});
|
||||
|
||||
r[Symbol.match]('abc');
|
||||
|
||||
assert.sameValue(r.lastIndex, 2);
|
49
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val-groups.js
vendored
Normal file
49
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val-groups.js
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Return value after successful match with capturing groups
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
20. Let A be ArrayCreate(n + 1).
|
||||
[...]
|
||||
24. Perform CreateDataProperty(A, "index", matchIndex).
|
||||
25. Perform CreateDataProperty(A, "input", S).
|
||||
26. Let matchedSubstr be the matched substring (i.e. the portion of S
|
||||
between offset lastIndex inclusive and offset e exclusive).
|
||||
27. Perform CreateDataProperty(A, "0", matchedSubstr).
|
||||
28. For each integer i such that i > 0 and i ≤ n
|
||||
[...]
|
||||
d. Else, fullUnicode is false,
|
||||
i. Assert: captureI is a List of code units.
|
||||
ii. Let capturedValue be a string consisting of the code units of
|
||||
captureI.
|
||||
e. Perform CreateDataProperty(A, ToString(i) , capturedValue).
|
||||
[...]
|
||||
29. Return A.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var result = /b(.).(.)./[Symbol.match]('abcdefg');
|
||||
|
||||
assert(Array.isArray(result));
|
||||
assert.sameValue(result.index, 1);
|
||||
assert.sameValue(result.input, 'abcdefg');
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 'bcdef');
|
||||
assert.sameValue(result[1], 'c');
|
||||
assert.sameValue(result[2], 'e');
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Return value after successful match
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
20. Let A be ArrayCreate(n + 1).
|
||||
[...]
|
||||
24. Perform CreateDataProperty(A, "index", matchIndex).
|
||||
25. Perform CreateDataProperty(A, "input", S).
|
||||
26. Let matchedSubstr be the matched substring (i.e. the portion of S
|
||||
between offset lastIndex inclusive and offset e exclusive).
|
||||
27. Perform CreateDataProperty(A, "0", matchedSubstr).
|
||||
[...]
|
||||
29. Return A.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var result = /b./[Symbol.match]('abcd');
|
||||
|
||||
assert(Array.isArray(result));
|
||||
assert.sameValue(result.index, 1);
|
||||
assert.sameValue(result.input, 'abcd');
|
||||
assert.sameValue(result.length, 1);
|
||||
assert.sameValue(result[0], 'bc');
|
51
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-u-return-val-groups.js
vendored
Normal file
51
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-u-return-val-groups.js
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Return value after successful match with extended unicode capturing groups
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
20. Let A be ArrayCreate(n + 1).
|
||||
[...]
|
||||
24. Perform CreateDataProperty(A, "index", matchIndex).
|
||||
25. Perform CreateDataProperty(A, "input", S).
|
||||
26. Let matchedSubstr be the matched substring (i.e. the portion of S
|
||||
between offset lastIndex inclusive and offset e exclusive).
|
||||
27. Perform CreateDataProperty(A, "0", matchedSubstr).
|
||||
28. For each integer i such that i > 0 and i ≤ n
|
||||
[...]
|
||||
c. Else if fullUnicode is true,
|
||||
i. Assert: captureI is a List of code points.
|
||||
ii. Let capturedValue be a string whose code units are the
|
||||
UTF16Encoding (10.1.1) of the code points of captureI.
|
||||
[...]
|
||||
e. Perform CreateDataProperty(A, ToString(i) , capturedValue).
|
||||
[...]
|
||||
29. Return A.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var result = /b(.).(.)./u[Symbol.match]('ab\ud834\udf06defg');
|
||||
|
||||
assert(Array.isArray(result));
|
||||
assert.sameValue(result.index, 1);
|
||||
assert.sameValue(result.input, 'ab\ud834\udf06defg');
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 'b\ud834\udf06def');
|
||||
assert.sameValue(result[1], '\ud834\udf06');
|
||||
assert.sameValue(result[2], 'e');
|
36
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex-err.js
vendored
Normal file
36
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown while setting `lastIndex` after a "sticky" match
|
||||
success
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
18. If global is true or sticky is true,
|
||||
a. Let setStatus be Set(R, "lastIndex", e, true).
|
||||
b. ReturnIfAbrupt(setStatus).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/y;
|
||||
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('a');
|
||||
});
|
33
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex.js
vendored
Normal file
33
test/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex.js
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Setting `lastIndex` after a "sticky" match success
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
7. Return RegExpBuiltinExec(R, S).
|
||||
|
||||
21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S )
|
||||
|
||||
[...]
|
||||
16. Let e be r's endIndex value.
|
||||
[...]
|
||||
18. If global is true or sticky is true,
|
||||
a. Let setStatus be Set(R, "lastIndex", e, true).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/y;
|
||||
|
||||
r[Symbol.match]('a');
|
||||
|
||||
assert.sameValue(r.lastIndex, 1);
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error thrown during string coercion of first parameter
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
21.2.5.6 RegExp.prototype [ @@match ] ( string )
|
||||
|
||||
[...]
|
||||
3. Let S be ToString(string)
|
||||
4. ReturnIfAbrupt(S).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var str = {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
/./[Symbol.match](str);
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: String coercion of first parameter
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
21.2.5.6 RegExp.prototype [ @@match ] ( string )
|
||||
|
||||
[...]
|
||||
3. Let S be ToString(string)
|
||||
[...]
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
valueOf: function() {
|
||||
$ERROR('This method should not be invoked.');
|
||||
},
|
||||
toString: function() {
|
||||
return 'toString value';
|
||||
}
|
||||
};
|
||||
|
||||
assert.notSameValue(/toString value/[Symbol.match](obj), null);
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Boolean coercion of `global` property
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
21.2.5.6 RegExp.prototype [ @@match ] ( string )
|
||||
|
||||
[...]
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
[...]
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/;
|
||||
var result;
|
||||
Object.defineProperty(r, 'global', { writable: true });
|
||||
|
||||
r.global = undefined;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
|
||||
r.global = null;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
|
||||
r.global = true;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.notSameValue(result.length, 1);
|
||||
|
||||
r.global = false;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
|
||||
r.global = NaN;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
|
||||
r.global = 0;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
|
||||
r.global = '';
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 1);
|
||||
|
||||
r.global = 86;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
|
||||
r.global = Symbol.match;
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
||||
|
||||
r.global = {};
|
||||
result = r[Symbol.match]('aa');
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 2);
|
|
@ -17,7 +17,7 @@ info: >
|
|||
|
||||
[...]
|
||||
8. Let sticky be ToBoolean(Get(R, "sticky")).
|
||||
features: [Symbol, Symbol.match]
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /a/;
|
||||
|
@ -41,13 +41,13 @@ assert.notSameValue(r[Symbol.match]('ba'), null);
|
|||
r.sticky = 0;
|
||||
assert.notSameValue(r[Symbol.match]('ba'), null);
|
||||
|
||||
r.sticky = 86;
|
||||
assert.sameValue(r[Symbol.match]('ba'), null);
|
||||
|
||||
r.sticky = '';
|
||||
assert.notSameValue(r[Symbol.match]('ba'), null);
|
||||
|
||||
r.sticky = Symbol();
|
||||
r.sticky = 86;
|
||||
assert.sameValue(r[Symbol.match]('ba'), null);
|
||||
|
||||
r.sticky = Symbol.match;
|
||||
assert.sameValue(r[Symbol.match]('ba'), null);
|
||||
|
||||
r.sticky = {};
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when error is thrown by `exec` method
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
5. If IsCallable(exec) is true, then
|
||||
a. Let result be Call(exec, R, «S»).
|
||||
b. ReturnIfAbrupt(result).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
|
||||
r.exec = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Invocation of `exec` method
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
5. If IsCallable(exec) is true, then
|
||||
a. Let result be Call(exec, R, «S»).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var callCount = 0;
|
||||
var arg = {
|
||||
toString: function() {
|
||||
return 'string form';
|
||||
}
|
||||
};
|
||||
var thisValue, args;
|
||||
|
||||
r.exec = function() {
|
||||
thisValue = this;
|
||||
args = arguments;
|
||||
callCount += 1;
|
||||
return null;
|
||||
};
|
||||
|
||||
r[Symbol.match](arg);
|
||||
|
||||
assert.sameValue(callCount, 1);
|
||||
assert.sameValue(thisValue, r);
|
||||
assert.sameValue(args.length, 1);
|
||||
assert.sameValue(args[0], 'string form');
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when `exec` method returns value of invalid type
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
5. If IsCallable(exec) is true, then
|
||||
a. Let result be Call(exec, R, «S»).
|
||||
b. ReturnIfAbrupt(result).
|
||||
c. If Type(result) is neither Object or Null, throw a TypeError
|
||||
exception.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var retValue;
|
||||
r.exec = function() {
|
||||
return retValue;
|
||||
};
|
||||
|
||||
// Explicitly assert the method's presence to avoid false positives (i.e.
|
||||
// TypeErrors thrown by invoking an undefined reference).
|
||||
assert.sameValue(typeof r[Symbol.match], 'function');
|
||||
|
||||
retValue = undefined;
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
||||
|
||||
retValue = true;
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
||||
|
||||
retValue = 'string';
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
||||
|
||||
retValue = Symbol.match;
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
||||
|
||||
retValue = 86;
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when `exec` method returns value of valid type
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
5. If IsCallable(exec) is true, then
|
||||
a. Let result be Call(exec, R, «S»).
|
||||
b. ReturnIfAbrupt(result).
|
||||
c. If Type(result) is neither Object or Null, throw a TypeError
|
||||
exception.
|
||||
d. Return result.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
var retValue;
|
||||
r.exec = function() {
|
||||
return retValue;
|
||||
};
|
||||
|
||||
retValue = null;
|
||||
assert.sameValue(r[Symbol.match](''), retValue);
|
||||
|
||||
retValue = {};
|
||||
assert.sameValue(r[Symbol.match](''), retValue);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error is thrown while coercing `0` property of match result
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
1. Let matchStr be ToString(Get(result, "0")).
|
||||
2. ReturnIfAbrupt(matchStr).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./g;
|
||||
r.exec = function() {
|
||||
return {
|
||||
0: {
|
||||
toString: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when there is an error thrown while accessing the `exec` method of
|
||||
"global" instances
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
ii. ReturnIfAbrupt(result).
|
||||
|
||||
ES6 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
3. Let exec be Get(R, "exec").
|
||||
4. ReturnIfAbrupt(exec).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = { global: true };
|
||||
Object.defineProperty(r, 'exec', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp.prototype[Symbol.match].call(r, '');
|
||||
});
|
||||
|
||||
assert.sameValue(r.lastIndex, 0, 'Error thrown after setting `lastIndex`');
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error is thrown while accessing `0` property of match result
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
1. Let matchStr be ToString(Get(result, "0")).
|
||||
2. ReturnIfAbrupt(matchStr).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./g;
|
||||
var poisonedZero = {
|
||||
get 0() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
r.exec = function() {
|
||||
return poisonedZero;
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when `lastIndex` cannot be set on "global" instances
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
c. Let setStatus be Set(rx, "lastIndex", 0, true).
|
||||
d. ReturnIfAbrupt(setStatus).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./g;
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Initializing the value of `lastIndex` on "global" instances
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
c. Let setStatus be Set(rx, "lastIndex", 0, true).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./g;
|
||||
|
||||
r.lastIndex = 1;
|
||||
|
||||
assert.notSameValue(r[Symbol.match]('a'), null);
|
36
test/built-ins/RegExp/prototype/Symbol.match/g-match-empty-advance-lastindex.js
vendored
Normal file
36
test/built-ins/RegExp/prototype/Symbol.match/g-match-empty-advance-lastindex.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
lastIndex is explicitly advanced for zero-length matches for "global"
|
||||
instances
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
[...]
|
||||
5. If matchStr is the empty String, then
|
||||
[...]
|
||||
c. Let nextIndex be AdvanceStringIndex(S, thisIndex,
|
||||
fullUnicode).
|
||||
d. Let setStatus be Set(rx, "lastIndex", nextIndex, true).
|
||||
e. ReturnIfAbrupt(setStatus).
|
||||
6. Increment n.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var result = /(?:)/g[Symbol.match]('abc');
|
||||
|
||||
assert.notSameValue(result, null);
|
||||
assert.sameValue(result.length, 4);
|
||||
assert.sameValue(result[0], '');
|
||||
assert.sameValue(result[1], '');
|
||||
assert.sameValue(result[2], '');
|
||||
assert.sameValue(result[3], '');
|
50
test/built-ins/RegExp/prototype/Symbol.match/g-match-empty-coerce-lastindex-err.js
vendored
Normal file
50
test/built-ins/RegExp/prototype/Symbol.match/g-match-empty-coerce-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error is thrown while type coercing `lastIndex` of zero-width
|
||||
match
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
1. Let matchStr be ToString(Get(result, "0")).
|
||||
[...]
|
||||
5. If matchStr is the empty String, then
|
||||
a. Let thisIndex be ToLength(Get(rx, "lastIndex")).
|
||||
b. ReturnIfAbrupt(thisIndex).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./g;
|
||||
var nextMatch;
|
||||
|
||||
r.exec = function() {
|
||||
var thisMatch = nextMatch;
|
||||
if (thisMatch === null) {
|
||||
return null;
|
||||
}
|
||||
nextMatch = null;
|
||||
return {
|
||||
get 0() {
|
||||
r.lastIndex = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
return thisMatch;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
nextMatch = '';
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
47
test/built-ins/RegExp/prototype/Symbol.match/g-match-empty-set-lastindex-err.js
vendored
Normal file
47
test/built-ins/RegExp/prototype/Symbol.match/g-match-empty-set-lastindex-err.js
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error is thrown while setting `lastIndex` after a zero-width
|
||||
match
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
1. Let matchStr be ToString(Get(result, "0")).
|
||||
[...]
|
||||
5. If matchStr is the empty String, then
|
||||
[...]
|
||||
d. Let setStatus be Set(rx, "lastIndex", nextIndex, true).
|
||||
e. ReturnIfAbrupt(setStatus).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var exec = function() {
|
||||
var thisMatch = nextMatch;
|
||||
if (thisMatch === null) {
|
||||
return null;
|
||||
}
|
||||
nextMatch = null;
|
||||
return {
|
||||
get 0() {
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
return thisMatch;
|
||||
}
|
||||
};
|
||||
};
|
||||
var r, nextMatch;
|
||||
|
||||
r = /./g;
|
||||
r.exec = exec;
|
||||
nextMatch = '';
|
||||
assert.throws(TypeError, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2015 Mike Pennisi. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
The `lastIndex` property is not coerced for a non-empty string match
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
1. Let matchStr be ToString(Get(result, "0")).
|
||||
[...]
|
||||
5. If matchStr is the empty String, then
|
||||
a. Let thisIndex be ToLength(Get(rx, "lastIndex")).
|
||||
b. ReturnIfAbrupt(thisIndex).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./g;
|
||||
var nextMatch;
|
||||
|
||||
r.exec = function() {
|
||||
var thisMatch = nextMatch;
|
||||
if (thisMatch === null) {
|
||||
return null;
|
||||
}
|
||||
nextMatch = null;
|
||||
return {
|
||||
get 0() {
|
||||
r.lastIndex = {
|
||||
valueOf: function() {
|
||||
$ERROR('This function should not be invoked.');
|
||||
}
|
||||
};
|
||||
return thisMatch;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
nextMatch = 'a non-empty string';
|
||||
r[Symbol.match]('');
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2015 Mike Pennisi. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: The `lastIndex` is not set after a non-zero-width match
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
[...]
|
||||
iv. Else result is not null,
|
||||
1. Let matchStr be ToString(Get(result, "0")).
|
||||
[...]
|
||||
5. If matchStr is the empty String, then
|
||||
[...]
|
||||
d. Let setStatus be Set(rx, "lastIndex", nextIndex, true).
|
||||
e. ReturnIfAbrupt(setStatus).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var exec = function() {
|
||||
var thisMatch = nextMatch;
|
||||
if (thisMatch === null) {
|
||||
return null;
|
||||
}
|
||||
nextMatch = null;
|
||||
return {
|
||||
get 0() {
|
||||
Object.defineProperty(r, 'lastIndex', { writable: false });
|
||||
return thisMatch;
|
||||
}
|
||||
};
|
||||
};
|
||||
var r, nextMatch;
|
||||
|
||||
r = /./g;
|
||||
r.exec = exec;
|
||||
nextMatch = 'a non-empty string';
|
||||
r[Symbol.match]('');
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Return value when matches occur with the `global` flag
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
e. Let A be ArrayCreate(0).
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
ii. ReturnIfAbrupt(result).
|
||||
iii. If result is null, then
|
||||
1. If n=0, return null.
|
||||
2. Else, return A.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var result = /.(.)./g[Symbol.match]('abcdefghi');
|
||||
|
||||
assert(Array.isArray(result));
|
||||
|
||||
assert.sameValue(
|
||||
Object.hasOwnProperty.call(result, 'index'),
|
||||
false,
|
||||
'Does not define an `index` "own" property'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.index, undefined, 'Does not define an `index` property'
|
||||
);
|
||||
assert.sameValue(
|
||||
Object.hasOwnProperty.call(result, 'input'),
|
||||
false,
|
||||
'Does not define an `input` "own" property'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.input, undefined, 'Does not define an `input` property'
|
||||
);
|
||||
|
||||
assert.sameValue(result.length, 3);
|
||||
assert.sameValue(result[0], 'abc');
|
||||
assert.sameValue(result[1], 'def');
|
||||
assert.sameValue(result[2], 'ghi');
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Return value when no matches occur with the `global` flag
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
[...]
|
||||
8. Else global is true,
|
||||
[...]
|
||||
g. Repeat,
|
||||
i. Let result be RegExpExec(rx, S).
|
||||
ii. ReturnIfAbrupt(result).
|
||||
iii. If result is null, then
|
||||
1. If n=0, return null.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
assert.sameValue(/a/g[Symbol.match]('b'), null);
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when error is thrown while accessing `exec` property
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
3. Let exec be Get(R, "exec").
|
||||
4. ReturnIfAbrupt(exec).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var r = /./;
|
||||
|
||||
Object.defineProperty(r, 'exec', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
r[Symbol.match]('');
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when error is thrown during retrieval of `global` property
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
5. Let global be ToBoolean(Get(rx, "global")).
|
||||
6. ReturnIfAbrupt(global).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
get global() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
RegExp.prototype[Symbol.match].call(obj);
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.2.5.6
|
||||
description: RegExp.prototype[Symbol.match] `length` property
|
||||
info: >
|
||||
ES6 Section 17:
|
||||
Every built-in Function object, including constructors, has a length
|
||||
property whose value is an integer. Unless otherwise specified, this value
|
||||
is equal to the largest number of named arguments shown in the subclause
|
||||
headings for the function description, including optional parameters.
|
||||
|
||||
[...]
|
||||
|
||||
Unless otherwise specified, the length property of a built-in Function
|
||||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(RegExp.prototype[Symbol.match].length, 1);
|
||||
|
||||
verifyNotEnumerable(RegExp.prototype[Symbol.match], 'length');
|
||||
verifyNotWritable(RegExp.prototype[Symbol.match], 'length');
|
||||
verifyConfigurable(RegExp.prototype[Symbol.match], 'length');
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 21.2.5.6
|
||||
description: RegExp.prototype[Symbol.match] `name` property
|
||||
info: >
|
||||
The value of the name property of this function is "[Symbol.match]".
|
||||
|
||||
ES6 Section 17:
|
||||
|
||||
[...]
|
||||
|
||||
Unless otherwise specified, the name property of a built-in Function
|
||||
object, if it exists, has the attributes { [[Writable]]: false,
|
||||
[[Enumerable]]: false, [[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(RegExp.prototype[Symbol.match].name, '[Symbol.match]');
|
||||
|
||||
verifyNotEnumerable(RegExp.prototype[Symbol.match], 'name');
|
||||
verifyNotWritable(RegExp.prototype[Symbol.match], 'name');
|
||||
verifyConfigurable(RegExp.prototype[Symbol.match], 'name');
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
es6id: 21.2.5.6
|
||||
description: RegExp.prototype[Symbol.match] property descriptor
|
||||
info: >
|
||||
ES6 Section 17
|
||||
|
||||
Every other data property described in clauses 18 through 26 and in Annex
|
||||
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
|
||||
[[Configurable]]: true } unless otherwise specified.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
verifyNotEnumerable(RegExp.prototype, Symbol.match);
|
||||
verifyWritable(RegExp.prototype, Symbol.match);
|
||||
verifyConfigurable(RegExp.prototype, Symbol.match);
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: The `this` value must be an object
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
1. Let rx be the this value.
|
||||
2. If Type(rx) is not Object, throw a TypeError exception.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call(undefined);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call(null);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call(true);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call('string');
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call(Symbol.match);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call(86);
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Behavior when invoked on an object without a a [[RegExpMatcher]] internal
|
||||
slot
|
||||
es6id: 21.2.5.6
|
||||
info: >
|
||||
[...]
|
||||
7. If global is false, then
|
||||
a. Return RegExpExec(rx, S).
|
||||
|
||||
21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S )
|
||||
|
||||
[...]
|
||||
5. If IsCallable(exec) is true, then
|
||||
[...]
|
||||
d. Return result.
|
||||
6. If R does not have a [[RegExpMatcher]] internal slot, throw a TypeError
|
||||
exception.
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var objWithExec = {
|
||||
exec: function() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
var objWithoutExec = {};
|
||||
|
||||
RegExp.prototype[Symbol.match].call(objWithExec);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
RegExp.prototype[Symbol.match].call(objWithoutExec);
|
||||
});
|
|
@ -1,31 +0,0 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
info: The String.prototype.match.length property has the attribute ReadOnly
|
||||
es5id: 15.5.4.10_A10
|
||||
description: >
|
||||
Checking if varying the String.prototype.match.length property
|
||||
fails
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//CHECK#1
|
||||
if (!(String.prototype.match.hasOwnProperty('length'))) {
|
||||
$ERROR('#1: String.prototype.match.hasOwnProperty(\'length\') return true. Actual: '+String.prototype.match.hasOwnProperty('length'));
|
||||
}
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var __obj = String.prototype.match.length;
|
||||
|
||||
verifyNotWritable(String.prototype.match, "length", null, function(){return "shifted";});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//CHECK#2
|
||||
if (String.prototype.match.length !== __obj) {
|
||||
$ERROR('#2: __obj = String.prototype.match.length; String.prototype.match.length = function(){return "shifted";}; String.prototype.match.length === __obj. Actual: '+String.prototype.match.length );
|
||||
}
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Behavior when error is thrown accessing @@match property
|
||||
es6id: 21.1.3.11
|
||||
info: >
|
||||
[...]
|
||||
3. If regexp is neither undefined nor null, then
|
||||
a. Let matcher be GetMethod(regexp, @@match).
|
||||
b. ReturnIfAbrupt(matcher).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {};
|
||||
Object.defineProperty(obj, Symbol.match, {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
''.match(obj);
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Invocation of @@match property of user-supplied objects
|
||||
es6id: 21.1.3.11
|
||||
info: >
|
||||
[...]
|
||||
3. If regexp is neither undefined nor null, then
|
||||
a. Let matcher be GetMethod(regexp, @@match).
|
||||
b. ReturnIfAbrupt(matcher).
|
||||
c. If matcher is not undefined, then
|
||||
i. Return Call(matcher, regexp, «O»).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var obj = {};
|
||||
var returnVal = {};
|
||||
var callCount = 0;
|
||||
var thisVal, args;
|
||||
|
||||
obj[Symbol.match] = function() {
|
||||
callCount += 1;
|
||||
thisVal = this;
|
||||
args = arguments;
|
||||
return returnVal;
|
||||
};
|
||||
|
||||
assert.sameValue(''.match(obj), returnVal);
|
||||
assert.sameValue(callCount, 1, 'Invokes the method exactly once');
|
||||
assert.sameValue(thisVal, obj);
|
||||
assert.notSameValue(args, undefined);
|
||||
assert.sameValue(args.length, 1);
|
||||
assert.sameValue(args[0], '');
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: Invocation of @@match property of internally-created RegExps
|
||||
es6id: 21.1.3.11
|
||||
info: >
|
||||
[...]
|
||||
6. Let rx be RegExpCreate(regexp, undefined) (see 21.2.3.2.3).
|
||||
7. ReturnIfAbrupt(rx).
|
||||
8. Return Invoke(rx, @@match, «S»).
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
var originalMatch = RegExp.prototype[Symbol.match];
|
||||
var returnVal = {};
|
||||
var result, thisVal, args;
|
||||
|
||||
RegExp.prototype[Symbol.match] = function() {
|
||||
thisVal = this;
|
||||
args = arguments;
|
||||
return returnVal;
|
||||
};
|
||||
|
||||
try {
|
||||
result = 'target'.match('string source');
|
||||
|
||||
assert(thisVal instanceof RegExp);
|
||||
assert.sameValue(thisVal.source, 'string source');
|
||||
assert.sameValue(thisVal.flags, '');
|
||||
assert.sameValue(thisVal.lastIndex, 0);
|
||||
assert.sameValue(args.length, 1);
|
||||
assert.sameValue(args[0], 'target');
|
||||
assert.sameValue(result, returnVal);
|
||||
} finally {
|
||||
RegExp.prototype[Symbol.match] = originalMatch;
|
||||
}
|
|
@ -4,7 +4,21 @@
|
|||
/*---
|
||||
info: The length property of the match method is 1
|
||||
es5id: 15.5.4.10_A11
|
||||
es6id: 21.1.3.11
|
||||
description: Checking String.prototype.match.length
|
||||
info: >
|
||||
ES6 Section 17:
|
||||
Every built-in Function object, including constructors, has a length
|
||||
property whose value is an integer. Unless otherwise specified, this value
|
||||
is equal to the largest number of named arguments shown in the subclause
|
||||
headings for the function description, including optional parameters.
|
||||
|
||||
[...]
|
||||
|
||||
Unless otherwise specified, the length property of a built-in Function
|
||||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
|
||||
[[Configurable]]: true }.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -22,3 +36,7 @@ if (String.prototype.match.length !== 1) {
|
|||
}
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
verifyNotEnumerable(String.prototype.match, 'length');
|
||||
verifyNotWritable(String.prototype.match, 'length');
|
||||
verifyConfigurable(String.prototype.match, 'length');
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 19.4.2.6
|
||||
description: >
|
||||
`Symbol.match` property descriptor
|
||||
info: >
|
||||
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
|
||||
false, [[Configurable]]: false }.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Symbol.match]
|
||||
---*/
|
||||
|
||||
assert.sameValue(typeof Symbol.match, 'symbol');
|
||||
verifyNotEnumerable(Symbol, 'match');
|
||||
verifyNotWritable(Symbol, 'match');
|
||||
verifyNotConfigurable(Symbol, 'match');
|
Loading…
Reference in New Issue