diff --git a/test/built-ins/RegExp/prototype/flags/coercion.js b/test/built-ins/RegExp/prototype/flags/coercion.js new file mode 100644 index 0000000000..2ab545a5c4 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/coercion.js @@ -0,0 +1,61 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of properties +info: > + get RegExp.prototype.flags + + [...] + 4. Let global be ToBoolean(? Get(R, "global")). + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + 14. Let sticky be ToBoolean(? Get(R, "sticky")). +features: [Symbol, regexp-dotall] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; +var flags = [ + ['g', 'global'], + ['i', 'ignoreCase'], + ['m', 'multiline'], + ['s', 'dotAll'], + ['u', 'unicode'], + ['y', 'sticky'], +]; + +flags.forEach(function(flag) { + var res = flag[0]; + var key = flag[1]; + var r = {}; + + r[key] = undefined; + assert.sameValue(get.call(r), '', key + ' = undefined'); + + r[key] = null; + assert.sameValue(get.call(r), '', key + ' = null'); + + r[key] = NaN; + assert.sameValue(get.call(r), '', key + ' = NaN'); + + r[key] = ''; + assert.sameValue(get.call(r), '', key + ' = ""'); + + r[key] = 'string'; + assert.sameValue(get.call(r), res, key + ' = "string"'); + + r[key] = 86; + assert.sameValue(get.call(r), res, key + ' = 86'); + + r[key] = Symbol(); + assert.sameValue(get.call(r), res, key + ' = Symbol()'); + + r[key] = []; + assert.sameValue(get.call(r), res, key + ' = []'); + + r[key] = {}; + assert.sameValue(get.call(r), res, key + ' = {}'); +}); diff --git a/test/built-ins/RegExp/prototype/flags/length.js b/test/built-ins/RegExp/prototype/flags/length.js index daec3fce37..e752326bcc 100644 --- a/test/built-ins/RegExp/prototype/flags/length.js +++ b/test/built-ins/RegExp/prototype/flags/length.js @@ -2,6 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- +esid: sec-get-regexp.prototype.flags es6id: 21.2.5.3 description: > get RegExp.prototype.flags.length is 0. @@ -22,10 +23,11 @@ info: > includes: [propertyHelper.js] ---*/ -var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags"); +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; -assert.sameValue(desc.get.length, 0); - -verifyNotEnumerable(desc.get, "length"); -verifyNotWritable(desc.get, "length"); -verifyConfigurable(desc.get, "length"); +verifyProperty(get, 'length', { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/RegExp/prototype/flags/name.js b/test/built-ins/RegExp/prototype/flags/name.js index cf9b212b7c..e7bb01aead 100644 --- a/test/built-ins/RegExp/prototype/flags/name.js +++ b/test/built-ins/RegExp/prototype/flags/name.js @@ -1,24 +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. + /*--- +esid: sec-get-regexp.prototype.flags es6id: 21.2.5.3 description: > - RegExp.prototype.flags name + get RegExp.prototype.flags.name is "get flags". info: > + get RegExp.prototype.flags + 17 ECMAScript Standard Built-in Objects Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string. + + 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] ---*/ -var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; -assert.sameValue( - descriptor.get.name, - 'get flags' -); - -verifyNotEnumerable(descriptor.get, 'name'); -verifyNotWritable(descriptor.get, 'name'); -verifyConfigurable(descriptor.get, 'name'); +verifyProperty(get, 'name', { + value: 'get flags', + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/RegExp/prototype/flags/order-gets.js b/test/built-ins/RegExp/prototype/flags/order-gets.js new file mode 100644 index 0000000000..2cebc3a7f6 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/order-gets.js @@ -0,0 +1,45 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Gets are performed in specified order +info: > + get RegExp.prototype.flags + + [...] + 4. Let global be ToBoolean(? Get(R, "global")). + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + 14. Let sticky be ToBoolean(? Get(R, "sticky")). +features: [regexp-dotall] +---*/ + +var calls = ''; +var re = { + get global() { + calls += 'g'; + }, + get ignoreCase() { + calls += 'i'; + }, + get multiline() { + calls += 'm'; + }, + get dotAll() { + calls += 's'; + }, + get unicode() { + calls += 'u'; + }, + get sticky() { + calls += 'y'; + }, +}; + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +assert.sameValue(get.call(re), ''); +assert.sameValue(calls, 'gimsuy'); diff --git a/test/built-ins/RegExp/prototype/flags/prop-desc.js b/test/built-ins/RegExp/prototype/flags/prop-desc.js new file mode 100644 index 0000000000..f8bbcd5e3a --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + get RegExp.prototype.flags property descriptor +info: > + get RegExp.prototype.flags + + RegExp.prototype.flags is an accessor property whose set accessor + function is undefined +includes: [propertyHelper.js] +---*/ + +var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); + +assert.sameValue(typeof d.get, 'function', 'typeof d.get'); +assert.sameValue(d.set, undefined, 'd.set'); + +verifyProperty(RegExp.prototype, 'flags', { + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/RegExp/prototype/flags/rethrow.js b/test/built-ins/RegExp/prototype/flags/rethrow.js new file mode 100644 index 0000000000..ec394a9e47 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/rethrow.js @@ -0,0 +1,68 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Rethrows exceptions raised in property gets +info: > + get RegExp.prototype.flags + + [...] + 4. Let global be ToBoolean(? Get(R, "global")). + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + 14. Let sticky be ToBoolean(? Get(R, "sticky")). +features: [regexp-dotall] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +assert.throws(Test262Error, function() { + get.call({ + get global() { + throw new Test262Error(); + }, + }); +}, 'global'); + +assert.throws(Test262Error, function() { + get.call({ + get ignoreCase() { + throw new Test262Error(); + }, + }); +}, 'ignoreCase'); + +assert.throws(Test262Error, function() { + get.call({ + get multiline() { + throw new Test262Error(); + }, + }); +}, 'multiline'); + +assert.throws(Test262Error, function() { + get.call({ + get dotAll() { + throw new Test262Error(); + }, + }); +}, 'dotAll'); + +assert.throws(Test262Error, function() { + get.call({ + get unicode() { + throw new Test262Error(); + }, + }); +}, 'unicode'); + +assert.throws(Test262Error, function() { + get.call({ + get sticky() { + throw new Test262Error(); + }, + }); +}, 'sticky'); diff --git a/test/built-ins/RegExp/prototype/flags/s.js b/test/built-ins/RegExp/prototype/flags/s.js deleted file mode 100644 index f70aa3a4ac..0000000000 --- a/test/built-ins/RegExp/prototype/flags/s.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2017 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - 's' entry's presence is determined by `s` flag -esid: sec-get-regexp.prototype.flags -info: > - 21.2.5.3 get RegExp.prototype.flags - - 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). - 11. If dotAll is true, append "s" as the last code unit of result. -features: [regexp-dotall] ----*/ - -var flags; - -flags = /./s.flags; -assert.sameValue(flags, 's'); - -let re = /./; -Object.defineProperty(re, 'dotAll', {value: true}); -assert.sameValue(re.flags, 's'); diff --git a/test/built-ins/RegExp/prototype/flags/this-val-non-obj.js b/test/built-ins/RegExp/prototype/flags/this-val-non-obj.js new file mode 100644 index 0000000000..2211ae013d --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/this-val-non-obj.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +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, 'flags').get; + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(4); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(false); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(Symbol()); +}, 'symbol'); diff --git a/test/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js b/test/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js new file mode 100644 index 0000000000..8ded3a96e8 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + Return "" 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. Let result be the empty String. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +assert.sameValue(get.call(RegExp.prototype), ''); diff --git a/test/built-ins/RegExp/prototype/flags/this-val-regexp.js b/test/built-ins/RegExp/prototype/flags/this-val-regexp.js new file mode 100644 index 0000000000..4606f6da94 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/this-val-regexp.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + RegExp.prototype.flags returns RegExp flags as a string +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [regexp-dotall] +---*/ + +assert.sameValue(/./.flags, '', 'no flags'); +assert.sameValue(/./g.flags, 'g', 'global'); +assert.sameValue(/./i.flags, 'i', 'ignoreCase'); +assert.sameValue(/./m.flags, 'm', 'multiline'); +assert.sameValue(/./s.flags, 's', 'dotAll'); +assert.sameValue(/./u.flags, 'u', 'unicode'); +assert.sameValue(/./y.flags, 'y', 'sticky'); diff --git a/test/built-ins/RegExp/prototype/flags/u-attr-err.js b/test/built-ins/RegExp/prototype/flags/u-attr-err.js deleted file mode 100644 index 28c489621d..0000000000 --- a/test/built-ins/RegExp/prototype/flags/u-attr-err.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Errors thrown when retrieving attribute -es6id: 21.2.5.3 -info: > - 21.2.5.3 get RegExp.prototype.flags - - [...] - 13. Let unicode be ToBoolean(Get(R, "unicode")). - 14. ReturnIfAbrupt(unicode). ----*/ - -var re = /./; - -Object.defineProperty(re, 'unicode', { - get: function() { - throw new Test262Error(); - } -}); - -assert.throws(Test262Error, function() { - re.flags; -}); diff --git a/test/built-ins/RegExp/prototype/flags/u-coercion.js b/test/built-ins/RegExp/prototype/flags/u-coercion.js deleted file mode 100644 index b07ae7e7ad..0000000000 --- a/test/built-ins/RegExp/prototype/flags/u-coercion.js +++ /dev/null @@ -1,55 +0,0 @@ -// 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 `unicode` property -es6id: 21.2.5.3 -info: > - 21.2.5.3 get RegExp.prototype.flags - - [...] - 13. Let unicode be ToBoolean(Get(R, "unicode")). - 14. ReturnIfAbrupt(unicode). - 15. If unicode is true, append "u" as the last code unit of result. -features: [Symbol] ----*/ - -var r = /./; -var flags; -Object.defineProperty(r, 'unicode', { writable: true }); - -r.unicode = undefined; -flags = r.flags; -assert.sameValue(flags.length, 0); - -r.unicode = null; -flags = r.flags; -assert.sameValue(flags.length, 0); - -r.unicode = NaN; -flags = r.flags; -assert.sameValue(flags.length, 0); - -r.unicode = 86; -flags = r.flags; -assert.sameValue(flags.length, 1); -assert.sameValue(flags[0], 'u'); - -r.unicode = ''; -flags = r.flags; -assert.sameValue(flags.length, 0); - -r.unicode = 'string'; -flags = r.flags; -assert.sameValue(flags.length, 1); -assert.sameValue(flags[0], 'u'); - -r.unicode = Symbol(); -flags = r.flags; -assert.sameValue(flags.length, 1); -assert.sameValue(flags[0], 'u'); - -r.unicode = {}; -flags = r.flags; -assert.sameValue(flags.length, 1); -assert.sameValue(flags[0], 'u'); diff --git a/test/built-ins/RegExp/prototype/flags/u.js b/test/built-ins/RegExp/prototype/flags/u.js deleted file mode 100644 index a0540256d6..0000000000 --- a/test/built-ins/RegExp/prototype/flags/u.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - 'u' entry's presence is determined by `u` flag -es6id: 21.2.5.3 -info: > - 21.2.5.3 get RegExp.prototype.flags - - [...] - 13. Let unicode be ToBoolean(Get(R, "unicode")). - 14. ReturnIfAbrupt(unicode). - 15. If unicode is true, append "u" as the last code unit of result. ----*/ - -var flags; - -flags = /./.flags; -assert.sameValue(flags.length, 0); - -flags = /./u.flags; -assert.sameValue(flags.length, 1); -assert.sameValue(flags[0], 'u'); diff --git a/test/built-ins/RegExp/prototype/flags/y-attr-err.js b/test/built-ins/RegExp/prototype/flags/y-attr-err.js deleted file mode 100644 index ee21a4d6c4..0000000000 --- a/test/built-ins/RegExp/prototype/flags/y-attr-err.js +++ /dev/null @@ -1,25 +0,0 @@ -// 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 if error is thrown when retrieving `sticky` attribute -es6id: 21.2.5.3 -info: > - 21.2.5.3 get RegExp.prototype.flags - - 16. Let sticky be ToBoolean(Get(R, "sticky")). - 17. ReturnIfAbrupt(sticky). ----*/ - -var re = /./; - -Object.defineProperty(re, 'sticky', { - get: function() { - throw new Test262Error(); - } -}); - -assert.throws(Test262Error, function() { - re.flags; -}); diff --git a/test/built-ins/RegExp/prototype/flags/y.js b/test/built-ins/RegExp/prototype/flags/y.js deleted file mode 100644 index 8e77589cb7..0000000000 --- a/test/built-ins/RegExp/prototype/flags/y.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2015 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - 'y' entry's presence is determined by `y` flag -es6id: 21.2.5.3 -info: > - 21.2.5.3 get RegExp.prototype.flags - - 16. Let sticky be ToBoolean(Get(R, "sticky")). - 17. ReturnIfAbrupt(sticky). - 18. If sticky is true, append "y" as the last code unit of result. ----*/ - -var flags; - -flags = /./.flags; -assert.sameValue(flags.length, 0); - -flags = /./y.flags; -assert.sameValue(flags.length, 1); -assert.sameValue(flags[0], 'y');