mirror of https://github.com/tc39/test262.git
Improve tests for RegExp `lastIndex` property
The prior version of this test asserted only the property's configurability. It was also limited to the RegExp object as returned from the RegExp constructor. Extend the test to verify all values of the property descriptor. Duplicate these assertions in a separate file dedicated to the RegExp object as created from a RegExp literal.
This commit is contained in:
parent
1d0dbc5726
commit
4e781091f8
|
@ -0,0 +1,33 @@
|
|||
// 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-regexp-pattern-flags
|
||||
es6id: 21.2.3.1
|
||||
description: Initial state of the `lastIndex` property
|
||||
info: |
|
||||
[...]
|
||||
7. Let O be ? RegExpAlloc(newTarget).
|
||||
8. Return ? RegExpInitialize(O, P, F).
|
||||
|
||||
21.2.3.2.2 Runtime Semantics: RegExpInitialize
|
||||
|
||||
[...]
|
||||
12. Perform ? Set(obj, "lastIndex", 0, true).
|
||||
[...]
|
||||
|
||||
21.2.3.2.1 Runtime Semantics: RegExpAlloc
|
||||
|
||||
[...]
|
||||
2. Perform ! DefinePropertyOrThrow(obj, "lastIndex", PropertyDescriptor
|
||||
{[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
|
||||
[...]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var re = new RegExp('');
|
||||
|
||||
assert.sameValue(re.lastIndex, 0);
|
||||
|
||||
verifyNotEnumerable(re, 'lastIndex');
|
||||
verifyWritable(re, 'lastIndex');
|
||||
verifyNotConfigurable(re, 'lastIndex');
|
|
@ -1,32 +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 RegExp instance lastIndex property has the attribute DontEnum
|
||||
es5id: 15.10.7.5_A8
|
||||
description: >
|
||||
Checking if enumerating the lastIndex property of RegExp instance
|
||||
fails
|
||||
---*/
|
||||
|
||||
var __re = new RegExp("A?B");
|
||||
|
||||
//CHECK#0
|
||||
if (__re.hasOwnProperty('lastIndex') !== true) {
|
||||
$ERROR('#0: __re = new RegExp("A?B"); __re.hasOwnProperty(\'lastIndex\') === true');
|
||||
}
|
||||
|
||||
//CHECK#1
|
||||
if (__re.propertyIsEnumerable('lastIndex') !== false) {
|
||||
$ERROR('#1: __re = new RegExp("A?B"); __re.propertyIsEnumerable(\'lastIndex\') === false');
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
var count = 0
|
||||
for (var p in __re){
|
||||
if (p==="lastIndex") count++
|
||||
}
|
||||
|
||||
if (count !== 0) {
|
||||
$ERROR('#2: count = 0; __re = new RegExp("A?B"); for (p in __re){ if (p==="lastIndex") count++; } count === 0. Actual: ' + (count));
|
||||
}
|
|
@ -1,33 +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 RegExp instance lastIndex property has the attribute DontDelete
|
||||
es5id: 15.10.7.5_A9
|
||||
description: Checking if deleting the lastIndex property fails
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var __re = new RegExp;
|
||||
|
||||
//CHECK#0
|
||||
if (__re.hasOwnProperty('lastIndex') !== true) {
|
||||
$ERROR('#0: __re = new RegExp; __re.hasOwnProperty(\'lastIndex\') === true');
|
||||
}
|
||||
|
||||
verifyNotConfigurable(__re, "lastIndex");
|
||||
|
||||
//CHECK#1
|
||||
try {
|
||||
if ((delete __re.lastIndex) !== false) {
|
||||
$ERROR('#1: __re = new RegExp; (delete __re.lastIndex) === false');
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof Test262Error) throw e;
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
//CHECK#2
|
||||
if (__re.hasOwnProperty('lastIndex') !== true) {
|
||||
$ERROR('#2: __re = new RegExp;delete __re.lastIndex === true; __re.hasOwnProperty(\'lastIndex\') === true');
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
// 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-regular-expression-literals-runtime-semantics-evaluation
|
||||
es6id: 12.2.8.2
|
||||
description: Initial state of the `lastIndex` property
|
||||
info: |
|
||||
[...]
|
||||
3. Return RegExpCreate(pattern, flags).
|
||||
|
||||
21.2.3.2.3 Runtime Semantics: RegExpCreate
|
||||
|
||||
1. Let obj be ? RegExpAlloc(%RegExp%).
|
||||
2. Return ? RegExpInitialize(obj, P, F).
|
||||
|
||||
21.2.3.2.2 Runtime Semantics: RegExpInitialize
|
||||
|
||||
[...]
|
||||
12. Perform ? Set(obj, "lastIndex", 0, true).
|
||||
[...]
|
||||
|
||||
21.2.3.2.1 Runtime Semantics: RegExpAlloc
|
||||
|
||||
[...]
|
||||
2. Perform ! DefinePropertyOrThrow(obj, "lastIndex", PropertyDescriptor
|
||||
{[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}).
|
||||
[...]
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
var re = /./;
|
||||
|
||||
assert.sameValue(re.lastIndex, 0);
|
||||
|
||||
verifyNotEnumerable(re, 'lastIndex');
|
||||
verifyWritable(re, 'lastIndex');
|
||||
verifyNotConfigurable(re, 'lastIndex');
|
Loading…
Reference in New Issue