Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: src/js/harmony-regexp.js

Issue 1419823010: Implement flag and source getters on RegExp.prototype. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@rproto
Patch Set: new webkit expectations Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var MakeTypeError; 15 var MakeTypeError;
16 var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
16 17
17 utils.Import(function(from) { 18 utils.Import(function(from) {
18 MakeTypeError = from.MakeTypeError; 19 MakeTypeError = from.MakeTypeError;
19 }); 20 });
20 21
21 // ------------------------------------------------------------------- 22 // -------------------------------------------------------------------
22 23
23 // ES6 draft 12-06-13, section 21.2.5.3 24 // ES6 draft 12-06-13, section 21.2.5.3
24 // + https://bugs.ecmascript.org/show_bug.cgi?id=3423 25 // + https://bugs.ecmascript.org/show_bug.cgi?id=3423
25 function RegExpGetFlags() { 26 function RegExpGetFlags() {
26 if (!IS_SPEC_OBJECT(this)) { 27 if (!IS_SPEC_OBJECT(this)) {
27 throw MakeTypeError(kFlagsGetterNonObject, TO_STRING(this)); 28 throw MakeTypeError(
29 kRegExpNonObject, "RegExp.prototype.flags", TO_STRING(this));
28 } 30 }
29 var result = ''; 31 var result = '';
30 if (this.global) result += 'g'; 32 if (this.global) result += 'g';
31 if (this.ignoreCase) result += 'i'; 33 if (this.ignoreCase) result += 'i';
32 if (this.multiline) result += 'm'; 34 if (this.multiline) result += 'm';
33 if (this.unicode) result += 'u'; 35 if (this.unicode) result += 'u';
34 if (this.sticky) result += 'y'; 36 if (this.sticky) result += 'y';
35 return result; 37 return result;
36 } 38 }
37 39 %FunctionSetName(RegExpGetFlags, "RegExp.prototype.flags");
38 %DefineAccessorPropertyUnchecked(GlobalRegExp.prototype, 'flags',
39 RegExpGetFlags, null, DONT_ENUM);
40 %SetNativeFlag(RegExpGetFlags); 40 %SetNativeFlag(RegExpGetFlags);
41 41
42
43 // ES6 21.2.5.12.
44 function RegExpGetSticky() {
45 if (!IS_REGEXP(this)) {
46 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky");
47 }
48 return !!REGEXP_STICKY(this);
49 }
50 %FunctionSetName(RegExpGetSticky, "RegExp.prototype.sticky");
51 %SetNativeFlag(RegExpGetSticky);
52
53
54 // ES6 21.2.5.15.
55 function RegExpGetUnicode() {
56 if (!IS_REGEXP(this)) {
57 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.unicode");
58 }
59 return !!REGEXP_UNICODE(this);
60 }
61 %FunctionSetName(RegExpGetUnicode, "RegExp.prototype.unicode");
62 %SetNativeFlag(RegExpGetUnicode);
63
64 %DefineGetterPropertyUnchecked(GlobalRegExp.prototype, 'flags',
65 RegExpGetFlags, DONT_ENUM);
66
67 %DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "sticky",
68 RegExpGetSticky, DONT_ENUM);
69
70 %DefineGetterPropertyUnchecked(GlobalRegExp.prototype, "unicode",
71 RegExpGetUnicode, DONT_ENUM);
42 }) 72 })
OLDNEW
« src/bootstrapper.cc ('K') | « src/heap/heap.h ('k') | src/js/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698