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

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

Issue 1428203003: Use in-object fields instead of private symbols for regexp slots. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: using IS_REGEXP check 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var FLAG_harmony_tolength; 12 var FLAG_harmony_tolength;
13 var GlobalObject = global.Object; 13 var GlobalObject = global.Object;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var InternalPackedArray = utils.InternalPackedArray; 15 var InternalPackedArray = utils.InternalPackedArray;
16 var MakeTypeError; 16 var MakeTypeError;
17 var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
18 var regExpSourceSymbol = utils.ImportNow("regexp_source_symbol");
19 17
20 utils.ImportFromExperimental(function(from) { 18 utils.ImportFromExperimental(function(from) {
21 FLAG_harmony_tolength = from.FLAG_harmony_tolength; 19 FLAG_harmony_tolength = from.FLAG_harmony_tolength;
22 }); 20 });
23 21
24 utils.Import(function(from) { 22 utils.Import(function(from) {
25 MakeTypeError = from.MakeTypeError; 23 MakeTypeError = from.MakeTypeError;
26 }); 24 });
27 25
28 // ------------------------------------------------------------------- 26 // -------------------------------------------------------------------
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 var matchEnd = RegExpLastMatchInfo[CAPTURE(index + 1)]; 325 var matchEnd = RegExpLastMatchInfo[CAPTURE(index + 1)];
328 if (matchStart == -1 || matchEnd == -1) return ''; 326 if (matchStart == -1 || matchEnd == -1) return '';
329 return %_SubString(LAST_SUBJECT(RegExpLastMatchInfo), matchStart, matchEnd); 327 return %_SubString(LAST_SUBJECT(RegExpLastMatchInfo), matchStart, matchEnd);
330 }; 328 };
331 } 329 }
332 330
333 331
334 // ES6 21.2.5.4, 21.2.5.5, 21.2.5.7, 21.2.5.12, 21.2.5.15. 332 // ES6 21.2.5.4, 21.2.5.5, 21.2.5.7, 21.2.5.12, 21.2.5.15.
335 function GetRegExpFlagGetter(name, mask) { 333 function GetRegExpFlagGetter(name, mask) {
336 var getter = function() { 334 var getter = function() {
337 if (!IS_SPEC_OBJECT(this)) { 335 if (!IS_REGEXP(this)) {
338 throw MakeTypeError(kRegExpNonObject, name, TO_STRING(this)); 336 throw MakeTypeError(kRegExpNonObject, name, TO_STRING(this));
339 } 337 }
340 var flags = this[regExpFlagsSymbol]; 338 return !!(%_RegExpFlags(this) & mask);
341 if (IS_UNDEFINED(flags)) {
342 throw MakeTypeError(kRegExpNonRegExp, TO_STRING(this));
343 }
344 return !!(flags & mask);
345 }; 339 };
346 %FunctionSetName(getter, name); 340 %FunctionSetName(getter, name);
347 %SetNativeFlag(getter); 341 %SetNativeFlag(getter);
348 return getter; 342 return getter;
349 } 343 }
350 344
351 345
352 // ES6 21.2.5.10. 346 // ES6 21.2.5.10.
353 function RegExpGetSource() { 347 function RegExpGetSource() {
354 if (!IS_SPEC_OBJECT(this)) { 348 if (!IS_REGEXP(this)) {
355 throw MakeTypeError(kRegExpNonObject, "RegExp.prototype.source", 349 throw MakeTypeError(kRegExpNonObject, "RegExp.prototype.source",
356 TO_STRING(this)); 350 TO_STRING(this));
357 } 351 }
358 var source = this[regExpSourceSymbol]; 352 return %RegExpSource(this);
359 if (IS_UNDEFINED(source)) {
360 throw MakeTypeError(kRegExpNonRegExp, TO_STRING(this));
361 }
362 return source;
363 } 353 }
364 354
365 %SetNativeFlag(RegExpGetSource); 355 %SetNativeFlag(RegExpGetSource);
366 356
367 // ------------------------------------------------------------------- 357 // -------------------------------------------------------------------
368 358
369 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); 359 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp');
370 %FunctionSetPrototype(GlobalRegExp, new GlobalObject()); 360 %FunctionSetPrototype(GlobalRegExp, new GlobalObject());
371 %AddNamedProperty( 361 %AddNamedProperty(
372 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); 362 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 455
466 utils.Export(function(to) { 456 utils.Export(function(to) {
467 to.GetRegExpFlagGetter = GetRegExpFlagGetter; 457 to.GetRegExpFlagGetter = GetRegExpFlagGetter;
468 to.RegExpExec = DoRegExpExec; 458 to.RegExpExec = DoRegExpExec;
469 to.RegExpExecNoTests = RegExpExecNoTests; 459 to.RegExpExecNoTests = RegExpExecNoTests;
470 to.RegExpLastMatchInfo = RegExpLastMatchInfo; 460 to.RegExpLastMatchInfo = RegExpLastMatchInfo;
471 to.RegExpTest = RegExpTest; 461 to.RegExpTest = RegExpTest;
472 }); 462 });
473 463
474 }) 464 })
OLDNEW
« src/crankshaft/hydrogen-instructions.h ('K') | « src/js/macros.py ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698