OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 var regExpSubject = LAST_SUBJECT(lastMatchInfo); | 326 var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
327 return SubString(regExpSubject, | 327 return SubString(regExpSubject, |
328 lastMatchInfo[CAPTURE0], | 328 lastMatchInfo[CAPTURE0], |
329 lastMatchInfo[CAPTURE1]); | 329 lastMatchInfo[CAPTURE1]); |
330 } | 330 } |
331 | 331 |
332 | 332 |
333 function RegExpGetLastParen() { | 333 function RegExpGetLastParen() { |
334 if (lastMatchInfoOverride) { | 334 if (lastMatchInfoOverride) { |
335 var override = lastMatchInfoOverride; | 335 var override = lastMatchInfoOverride; |
336 if (override.length <= 3) return ''; | 336 if (override.length <= 3) return ''; |
337 return override[override.length - 3]; | 337 return override[override.length - 3]; |
338 } | 338 } |
339 var length = NUMBER_OF_CAPTURES(lastMatchInfo); | 339 var length = NUMBER_OF_CAPTURES(lastMatchInfo); |
340 if (length <= 2) return ''; // There were no captures. | 340 if (length <= 2) return ''; // There were no captures. |
341 // We match the SpiderMonkey behavior: return the substring defined by the | 341 // We match the SpiderMonkey behavior: return the substring defined by the |
342 // last pair (after the first pair) of elements of the capture array even if | 342 // last pair (after the first pair) of elements of the capture array even if |
343 // it is empty. | 343 // it is empty. |
344 var regExpSubject = LAST_SUBJECT(lastMatchInfo); | 344 var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
345 var start = lastMatchInfo[CAPTURE(length - 2)]; | 345 var start = lastMatchInfo[CAPTURE(length - 2)]; |
346 var end = lastMatchInfo[CAPTURE(length - 1)]; | 346 var end = lastMatchInfo[CAPTURE(length - 1)]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 var lastMatchInfo = [ | 409 var lastMatchInfo = [ |
410 2, // REGEXP_NUMBER_OF_CAPTURES | 410 2, // REGEXP_NUMBER_OF_CAPTURES |
411 "", // Last subject. | 411 "", // Last subject. |
412 void 0, // Last input - settable with RegExpSetInput. | 412 void 0, // Last input - settable with RegExpSetInput. |
413 0, // REGEXP_FIRST_CAPTURE + 0 | 413 0, // REGEXP_FIRST_CAPTURE + 0 |
414 0, // REGEXP_FIRST_CAPTURE + 1 | 414 0, // REGEXP_FIRST_CAPTURE + 1 |
415 ]; | 415 ]; |
416 | 416 |
417 // Override last match info with an array of actual substrings. | 417 // Override last match info with an array of actual substrings. |
418 // Used internally by replace regexp with function. | 418 // Used internally by replace regexp with function. |
419 // The array has the format of an "apply" argument for a replacement | 419 // The array has the format of an "apply" argument for a replacement |
420 // function. | 420 // function. |
421 var lastMatchInfoOverride = null; | 421 var lastMatchInfoOverride = null; |
422 | 422 |
423 // ------------------------------------------------------------------- | 423 // ------------------------------------------------------------------- |
424 | 424 |
425 function SetupRegExp() { | 425 function SetupRegExp() { |
426 %FunctionSetInstanceClassName($RegExp, 'RegExp'); | 426 %FunctionSetInstanceClassName($RegExp, 'RegExp'); |
427 %FunctionSetPrototype($RegExp, new $Object()); | 427 %FunctionSetPrototype($RegExp, new $Object()); |
428 %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); | 428 %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); |
429 %SetCode($RegExp, RegExpConstructor); | 429 %SetCode($RegExp, RegExpConstructor); |
430 | 430 |
431 InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( | 431 InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( |
432 "exec", RegExpExec, | 432 "exec", RegExpExec, |
433 "test", RegExpTest, | 433 "test", RegExpTest, |
434 "toString", RegExpToString, | 434 "toString", RegExpToString, |
435 "compile", CompileRegExp | 435 "compile", CompileRegExp |
436 )); | 436 )); |
437 | 437 |
438 // The length of compile is 1 in SpiderMonkey. | 438 // The length of compile is 1 in SpiderMonkey. |
439 %FunctionSetLength($RegExp.prototype.compile, 1); | 439 %FunctionSetLength($RegExp.prototype.compile, 1); |
440 | 440 |
441 // The properties input, $input, and $_ are aliases for each other. When this | 441 // The properties input, $input, and $_ are aliases for each other. When this |
442 // value is set the value it is set to is coerced to a string. | 442 // value is set the value it is set to is coerced to a string. |
443 // Getter and setter for the input. | 443 // Getter and setter for the input. |
444 function RegExpGetInput() { | 444 function RegExpGetInput() { |
445 var regExpInput = LAST_INPUT(lastMatchInfo); | 445 var regExpInput = LAST_INPUT(lastMatchInfo); |
446 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; | 446 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; |
447 } | 447 } |
448 function RegExpSetInput(string) { | 448 function RegExpSetInput(string) { |
449 regExpCache.type = 'none'; | 449 regExpCache.type = 'none'; |
450 LAST_INPUT(lastMatchInfo) = ToString(string); | 450 LAST_INPUT(lastMatchInfo) = ToString(string); |
451 }; | 451 }; |
452 | 452 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 497 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
498 | 498 |
499 for (var i = 1; i < 10; ++i) { | 499 for (var i = 1; i < 10; ++i) { |
500 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); | 500 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); |
501 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 501 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
502 } | 502 } |
503 } | 503 } |
504 | 504 |
505 | 505 |
506 SetupRegExp(); | 506 SetupRegExp(); |
OLD | NEW |