| OLD | NEW |
| 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 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // ES#sec-regexpinitialize | 65 // ES#sec-regexpinitialize |
| 66 // Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) | 66 // Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) |
| 67 function RegExpInitialize(object, pattern, flags) { | 67 function RegExpInitialize(object, pattern, flags) { |
| 68 pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern); | 68 pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern); |
| 69 flags = IS_UNDEFINED(flags) ? '' : TO_STRING(flags); | 69 flags = IS_UNDEFINED(flags) ? '' : TO_STRING(flags); |
| 70 %RegExpInitializeAndCompile(object, pattern, flags); | 70 %RegExpInitializeAndCompile(object, pattern, flags); |
| 71 return object; | 71 return object; |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 function PatternFlags(pattern) { | |
| 76 return (REGEXP_GLOBAL(pattern) ? 'g' : '') + | |
| 77 (REGEXP_IGNORE_CASE(pattern) ? 'i' : '') + | |
| 78 (REGEXP_MULTILINE(pattern) ? 'm' : '') + | |
| 79 (REGEXP_UNICODE(pattern) ? 'u' : '') + | |
| 80 (REGEXP_STICKY(pattern) ? 'y' : ''); | |
| 81 } | |
| 82 | |
| 83 | |
| 84 // ES#sec-regexp.prototype.compile RegExp.prototype.compile (pattern, flags) | |
| 85 function RegExpCompileJS(pattern, flags) { | |
| 86 if (!IS_REGEXP(this)) { | |
| 87 throw %make_type_error(kIncompatibleMethodReceiver, | |
| 88 "RegExp.prototype.compile", this); | |
| 89 } | |
| 90 | |
| 91 if (IS_REGEXP(pattern)) { | |
| 92 if (!IS_UNDEFINED(flags)) throw %make_type_error(kRegExpFlags); | |
| 93 | |
| 94 flags = PatternFlags(pattern); | |
| 95 pattern = REGEXP_SOURCE(pattern); | |
| 96 } | |
| 97 | |
| 98 RegExpInitialize(this, pattern, flags); | |
| 99 | |
| 100 // Return undefined for compatibility with JSC. | |
| 101 // See http://crbug.com/585775 for web compat details. | |
| 102 } | |
| 103 | |
| 104 | |
| 105 function DoRegExpExec(regexp, string, index) { | 75 function DoRegExpExec(regexp, string, index) { |
| 106 return %_RegExpExec(regexp, string, index, RegExpLastMatchInfo); | 76 return %_RegExpExec(regexp, string, index, RegExpLastMatchInfo); |
| 107 } | 77 } |
| 108 | 78 |
| 109 | 79 |
| 110 // This is kind of performance sensitive, so we want to avoid unnecessary | 80 // This is kind of performance sensitive, so we want to avoid unnecessary |
| 111 // type checks on inputs. But we also don't want to inline it several times | 81 // type checks on inputs. But we also don't want to inline it several times |
| 112 // manually, so we use a macro :-) | 82 // manually, so we use a macro :-) |
| 113 macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) | 83 macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) |
| 114 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; | 84 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 throw %make_type_error(kIncompatibleMethodReceiver, | 129 throw %make_type_error(kIncompatibleMethodReceiver, |
| 160 'RegExp.prototype.test', this); | 130 'RegExp.prototype.test', this); |
| 161 } | 131 } |
| 162 string = TO_STRING(string); | 132 string = TO_STRING(string); |
| 163 var match = RegExpSubclassExec(this, string); | 133 var match = RegExpSubclassExec(this, string); |
| 164 return !IS_NULL(match); | 134 return !IS_NULL(match); |
| 165 } | 135 } |
| 166 %FunctionRemovePrototype(RegExpSubclassTest); | 136 %FunctionRemovePrototype(RegExpSubclassTest); |
| 167 | 137 |
| 168 | 138 |
| 169 function RegExpToString() { | |
| 170 if (!IS_RECEIVER(this)) { | |
| 171 throw %make_type_error( | |
| 172 kIncompatibleMethodReceiver, 'RegExp.prototype.toString', this); | |
| 173 } | |
| 174 if (this === GlobalRegExpPrototype) { | |
| 175 %IncrementUseCounter(kRegExpPrototypeToString); | |
| 176 } | |
| 177 return '/' + TO_STRING(this.source) + '/' + TO_STRING(this.flags); | |
| 178 } | |
| 179 | |
| 180 | |
| 181 function AtSurrogatePair(subject, index) { | 139 function AtSurrogatePair(subject, index) { |
| 182 if (index + 1 >= subject.length) return false; | 140 if (index + 1 >= subject.length) return false; |
| 183 var first = %_StringCharCodeAt(subject, index); | 141 var first = %_StringCharCodeAt(subject, index); |
| 184 if (first < 0xD800 || first > 0xDBFF) return false; | 142 if (first < 0xD800 || first > 0xDBFF) return false; |
| 185 var second = %_StringCharCodeAt(subject, index + 1); | 143 var second = %_StringCharCodeAt(subject, index + 1); |
| 186 return second >= 0xDC00 && second <= 0xDFFF; | 144 return second >= 0xDC00 && second <= 0xDFFF; |
| 187 } | 145 } |
| 188 | 146 |
| 189 | 147 |
| 190 // Fast path implementation of RegExp.prototype[Symbol.split] which | 148 // Fast path implementation of RegExp.prototype[Symbol.split] which |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 if (IS_NULL(result)) return -1; | 732 if (IS_NULL(result)) return -1; |
| 775 return result.index; | 733 return result.index; |
| 776 } | 734 } |
| 777 %FunctionRemovePrototype(RegExpSubclassSearch); | 735 %FunctionRemovePrototype(RegExpSubclassSearch); |
| 778 | 736 |
| 779 | 737 |
| 780 // ------------------------------------------------------------------- | 738 // ------------------------------------------------------------------- |
| 781 | 739 |
| 782 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ | 740 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
| 783 "test", RegExpSubclassTest, | 741 "test", RegExpSubclassTest, |
| 784 "toString", RegExpToString, | |
| 785 "compile", RegExpCompileJS, | |
| 786 matchSymbol, RegExpSubclassMatch, | 742 matchSymbol, RegExpSubclassMatch, |
| 787 replaceSymbol, RegExpSubclassReplace, | 743 replaceSymbol, RegExpSubclassReplace, |
| 788 searchSymbol, RegExpSubclassSearch, | 744 searchSymbol, RegExpSubclassSearch, |
| 789 splitSymbol, RegExpSubclassSplit, | 745 splitSymbol, RegExpSubclassSplit, |
| 790 ]); | 746 ]); |
| 791 | 747 |
| 792 %InstallToContext(["regexp_last_match_info", RegExpLastMatchInfo]); | 748 %InstallToContext(["regexp_last_match_info", RegExpLastMatchInfo]); |
| 793 | 749 |
| 794 // ------------------------------------------------------------------- | 750 // ------------------------------------------------------------------- |
| 795 // Internal | 751 // Internal |
| (...skipping 26 matching lines...) Expand all Loading... |
| 822 to.GetSubstitution = GetSubstitution; | 778 to.GetSubstitution = GetSubstitution; |
| 823 to.InternalRegExpMatch = InternalRegExpMatch; | 779 to.InternalRegExpMatch = InternalRegExpMatch; |
| 824 to.InternalRegExpReplace = InternalRegExpReplace; | 780 to.InternalRegExpReplace = InternalRegExpReplace; |
| 825 to.IsRegExp = IsRegExp; | 781 to.IsRegExp = IsRegExp; |
| 826 to.RegExpExec = DoRegExpExec; | 782 to.RegExpExec = DoRegExpExec; |
| 827 to.RegExpInitialize = RegExpInitialize; | 783 to.RegExpInitialize = RegExpInitialize; |
| 828 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 784 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 829 }); | 785 }); |
| 830 | 786 |
| 831 }) | 787 }) |
| OLD | NEW |