Apply feedback for RegExp.prototype.flags (#1196)

* Apply feedback for RegExp.prototype.flags

Ref #1149
This commit is contained in:
Leo Balter 2017-08-23 15:03:28 -04:00 committed by GitHub
parent 9875641a4c
commit f1d7a67e11
12 changed files with 304 additions and 72 deletions

View File

@ -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: Boolean coercion of the dotAll property
info: >
get RegExp.prototype.flags
...
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
...
features: [Symbol, regexp-dotall]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.dotAll = undefined;
assert.sameValue(get.call(r), "", "dotAll: undefined");
r.dotAll = null;
assert.sameValue(get.call(r), "", "dotAll: null");
r.dotAll = NaN;
assert.sameValue(get.call(r), "", "dotAll: NaN");
r.dotAll = "";
assert.sameValue(get.call(r), "", "dotAll: the empty string");
r.dotAll = "string";
assert.sameValue(get.call(r), "s", "dotAll: string");
r.dotAll = 86;
assert.sameValue(get.call(r), "s", "dotAll: 86");
r.dotAll = Symbol();
assert.sameValue(get.call(r), "s", "dotAll: Symbol()");
r.dotAll = [];
assert.sameValue(get.call(r), "s", "dotAll: []");
r.dotAll = {};
assert.sameValue(get.call(r), "s", "dotAll: {}");

View File

@ -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: Boolean coercion of the global property
info: >
get RegExp.prototype.flags
...
4. Let global be ToBoolean(? Get(R, "global")).
...
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.global = undefined;
assert.sameValue(get.call(r), "", "global: undefined");
r.global = null;
assert.sameValue(get.call(r), "", "global: null");
r.global = NaN;
assert.sameValue(get.call(r), "", "global: NaN");
r.global = "";
assert.sameValue(get.call(r), "", "global: the empty string");
r.global = "string";
assert.sameValue(get.call(r), "g", "global: string");
r.global = 86;
assert.sameValue(get.call(r), "g", "global: 86");
r.global = Symbol();
assert.sameValue(get.call(r), "g", "global: Symbol()");
r.global = [];
assert.sameValue(get.call(r), "g", "global: []");
r.global = {};
assert.sameValue(get.call(r), "g", "global: {}");

View File

@ -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: Boolean coercion of the ignoreCase property
info: >
get RegExp.prototype.flags
...
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
...
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.ignoreCase = undefined;
assert.sameValue(get.call(r), "", "ignoreCase: undefined");
r.ignoreCase = null;
assert.sameValue(get.call(r), "", "ignoreCase: null");
r.ignoreCase = NaN;
assert.sameValue(get.call(r), "", "ignoreCase: NaN");
r.ignoreCase = "";
assert.sameValue(get.call(r), "", "ignoreCase: the empty string");
r.ignoreCase = "string";
assert.sameValue(get.call(r), "i", "ignoreCase: string");
r.ignoreCase = 86;
assert.sameValue(get.call(r), "i", "ignoreCase: 86");
r.ignoreCase = Symbol();
assert.sameValue(get.call(r), "i", "ignoreCase: Symbol()");
r.ignoreCase = [];
assert.sameValue(get.call(r), "i", "ignoreCase: []");
r.ignoreCase = {};
assert.sameValue(get.call(r), "i", "ignoreCase: {}");

View File

@ -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: Boolean coercion of the multiline property
info: >
get RegExp.prototype.flags
...
8. Let multiline be ToBoolean(? Get(R, "multiline")).
...
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.multiline = undefined;
assert.sameValue(get.call(r), "", "multiline: undefined");
r.multiline = null;
assert.sameValue(get.call(r), "", "multiline: null");
r.multiline = NaN;
assert.sameValue(get.call(r), "", "multiline: NaN");
r.multiline = "";
assert.sameValue(get.call(r), "", "multiline: the empty string");
r.multiline = "string";
assert.sameValue(get.call(r), "m", "multiline: string");
r.multiline = 86;
assert.sameValue(get.call(r), "m", "multiline: 86");
r.multiline = Symbol();
assert.sameValue(get.call(r), "m", "multiline: Symbol()");
r.multiline = [];
assert.sameValue(get.call(r), "m", "multiline: []");
r.multiline = {};
assert.sameValue(get.call(r), "m", "multiline: {}");

View File

@ -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: Boolean coercion of the sticky property
info: >
get RegExp.prototype.flags
...
14. Let sticky be ToBoolean(? Get(R, "sticky")).
...
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.sticky = undefined;
assert.sameValue(get.call(r), "", "sticky: undefined");
r.sticky = null;
assert.sameValue(get.call(r), "", "sticky: null");
r.sticky = NaN;
assert.sameValue(get.call(r), "", "sticky: NaN");
r.sticky = "";
assert.sameValue(get.call(r), "", "sticky: the empty string");
r.sticky = "string";
assert.sameValue(get.call(r), "y", "sticky: string");
r.sticky = 86;
assert.sameValue(get.call(r), "y", "sticky: 86");
r.sticky = Symbol();
assert.sameValue(get.call(r), "y", "sticky: Symbol()");
r.sticky = [];
assert.sameValue(get.call(r), "y", "sticky: []");
r.sticky = {};
assert.sameValue(get.call(r), "y", "sticky: {}");

View File

@ -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: Boolean coercion of the unicode property
info: >
get RegExp.prototype.flags
...
12. Let unicode be ToBoolean(? Get(R, "unicode")).
...
features: [Symbol]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.unicode = undefined;
assert.sameValue(get.call(r), "", "unicode: undefined");
r.unicode = null;
assert.sameValue(get.call(r), "", "unicode: null");
r.unicode = NaN;
assert.sameValue(get.call(r), "", "unicode: NaN");
r.unicode = "";
assert.sameValue(get.call(r), "", "unicode: the empty string");
r.unicode = "string";
assert.sameValue(get.call(r), "u", "unicode: string");
r.unicode = 86;
assert.sameValue(get.call(r), "u", "unicode: 86");
r.unicode = Symbol();
assert.sameValue(get.call(r), "u", "unicode: Symbol()");
r.unicode = [];
assert.sameValue(get.call(r), "u", "unicode: []");
r.unicode = {};
assert.sameValue(get.call(r), "u", "unicode: {}");

View File

@ -1,61 +0,0 @@
// 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 + ' = {}');
});

View File

@ -41,5 +41,5 @@ var re = {
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
assert.sameValue(get.call(re), '');
get.call(re);
assert.sameValue(calls, 'gimsuy');

View File

@ -25,7 +25,7 @@ assert.throws(Test262Error, function() {
throw new Test262Error();
},
});
}, 'global');
}, 'Let global be ToBoolean(? Get(R, "global"))');
assert.throws(Test262Error, function() {
get.call({
@ -33,7 +33,7 @@ assert.throws(Test262Error, function() {
throw new Test262Error();
},
});
}, 'ignoreCase');
}, 'Let ignoreCase be ToBoolean(? Get(R, "ignoreCase"))');
assert.throws(Test262Error, function() {
get.call({
@ -41,7 +41,7 @@ assert.throws(Test262Error, function() {
throw new Test262Error();
},
});
}, 'multiline');
}, 'Let multiline be ToBoolean(? Get(R, "multiline"))');
assert.throws(Test262Error, function() {
get.call({
@ -49,7 +49,7 @@ assert.throws(Test262Error, function() {
throw new Test262Error();
},
});
}, 'dotAll');
}, 'Let dotAll be ToBoolean(? Get(R, "dotAll"))');
assert.throws(Test262Error, function() {
get.call({
@ -57,7 +57,7 @@ assert.throws(Test262Error, function() {
throw new Test262Error();
},
});
}, 'unicode');
}, 'Let unicode be ToBoolean(? Get(R, "unicode"))');
assert.throws(Test262Error, function() {
get.call({
@ -65,4 +65,4 @@ assert.throws(Test262Error, function() {
throw new Test262Error();
},
});
}, 'sticky');
}, 'Let sticky be ToBoolean(? Get(R, "sticky"))');

View File

@ -6,9 +6,20 @@ 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.
4. Let global be ToBoolean(? Get(R, "global")).
5. If global is true, append "g" as the last code unit of result.
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
7. If ignoreCase is true, append "i" as the last code unit of result.
8. Let multiline be ToBoolean(? Get(R, "multiline")).
9. If multiline is true, append "m" as the last code unit of result.
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
11. If dotAll is true, append "s" as the last code unit of result.
12. Let unicode be ToBoolean(? Get(R, "unicode")).
13. If unicode is true, append "u" as the last code unit of result.
14. Let sticky be ToBoolean(? Get(R, "sticky")).
15. If sticky is true, append "y" as the last code unit of result.
16. Return result.
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;

View File

@ -6,8 +6,20 @@ 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.
3. Let result be the empty String.
4. Let global be ToBoolean(? Get(R, "global")).
5. If global is true, append "g" as the last code unit of result.
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
7. If ignoreCase is true, append "i" as the last code unit of result.
8. Let multiline be ToBoolean(? Get(R, "multiline")).
9. If multiline is true, append "m" as the last code unit of result.
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
11. If dotAll is true, append "s" as the last code unit of result.
12. Let unicode be ToBoolean(? Get(R, "unicode")).
13. If unicode is true, append "u" as the last code unit of result.
14. Let sticky be ToBoolean(? Get(R, "sticky")).
15. If sticky is true, append "y" as the last code unit of result.
16. Return result.
features: [regexp-dotall]
---*/