| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/ast.h" | 7 #include "src/ast.h" |
| 8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 9 #include "src/compilation-cache.h" | 9 #include "src/compilation-cache.h" |
| 10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 MaybeHandle<Object> RegExpImpl::CreateRegExpLiteral( | 51 MaybeHandle<Object> RegExpImpl::CreateRegExpLiteral( |
| 52 Handle<JSFunction> constructor, | 52 Handle<JSFunction> constructor, |
| 53 Handle<String> pattern, | 53 Handle<String> pattern, |
| 54 Handle<String> flags) { | 54 Handle<String> flags) { |
| 55 // Call the construct code with 2 arguments. | 55 // Call the construct code with 2 arguments. |
| 56 Handle<Object> argv[] = { pattern, flags }; | 56 Handle<Object> argv[] = { pattern, flags }; |
| 57 return Execution::New(constructor, arraysize(argv), argv); | 57 return Execution::New(constructor, arraysize(argv), argv); |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 static JSRegExp::Flags RegExpFlagsFromString(Handle<String> str) { | |
| 62 int flags = JSRegExp::NONE; | |
| 63 for (int i = 0; i < str->length(); i++) { | |
| 64 switch (str->Get(i)) { | |
| 65 case 'i': | |
| 66 flags |= JSRegExp::IGNORE_CASE; | |
| 67 break; | |
| 68 case 'g': | |
| 69 flags |= JSRegExp::GLOBAL; | |
| 70 break; | |
| 71 case 'm': | |
| 72 flags |= JSRegExp::MULTILINE; | |
| 73 break; | |
| 74 case 'y': | |
| 75 if (FLAG_harmony_regexps) flags |= JSRegExp::STICKY; | |
| 76 break; | |
| 77 } | |
| 78 } | |
| 79 return JSRegExp::Flags(flags); | |
| 80 } | |
| 81 | |
| 82 | |
| 83 MUST_USE_RESULT | 61 MUST_USE_RESULT |
| 84 static inline MaybeHandle<Object> ThrowRegExpException( | 62 static inline MaybeHandle<Object> ThrowRegExpException( |
| 85 Handle<JSRegExp> re, | 63 Handle<JSRegExp> re, |
| 86 Handle<String> pattern, | 64 Handle<String> pattern, |
| 87 Handle<String> error_text, | 65 Handle<String> error_text, |
| 88 const char* message) { | 66 const char* message) { |
| 89 Isolate* isolate = re->GetIsolate(); | 67 Isolate* isolate = re->GetIsolate(); |
| 90 Factory* factory = isolate->factory(); | 68 Factory* factory = isolate->factory(); |
| 91 Handle<FixedArray> elements = factory->NewFixedArray(2); | 69 Handle<FixedArray> elements = factory->NewFixedArray(2); |
| 92 elements->set(0, *pattern); | 70 elements->set(0, *pattern); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 127 } |
| 150 return true; | 128 return true; |
| 151 } | 129 } |
| 152 | 130 |
| 153 | 131 |
| 154 // Generic RegExp methods. Dispatches to implementation specific methods. | 132 // Generic RegExp methods. Dispatches to implementation specific methods. |
| 155 | 133 |
| 156 | 134 |
| 157 MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, | 135 MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, |
| 158 Handle<String> pattern, | 136 Handle<String> pattern, |
| 159 Handle<String> flag_str) { | 137 JSRegExp::Flags flags) { |
| 160 Isolate* isolate = re->GetIsolate(); | 138 Isolate* isolate = re->GetIsolate(); |
| 161 Zone zone(isolate); | 139 Zone zone(isolate); |
| 162 JSRegExp::Flags flags = RegExpFlagsFromString(flag_str); | |
| 163 CompilationCache* compilation_cache = isolate->compilation_cache(); | 140 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 164 MaybeHandle<FixedArray> maybe_cached = | 141 MaybeHandle<FixedArray> maybe_cached = |
| 165 compilation_cache->LookupRegExp(pattern, flags); | 142 compilation_cache->LookupRegExp(pattern, flags); |
| 166 Handle<FixedArray> cached; | 143 Handle<FixedArray> cached; |
| 167 bool in_cache = maybe_cached.ToHandle(&cached); | 144 bool in_cache = maybe_cached.ToHandle(&cached); |
| 168 LOG(isolate, RegExpCompileEvent(re, in_cache)); | 145 LOG(isolate, RegExpCompileEvent(re, in_cache)); |
| 169 | 146 |
| 170 Handle<Object> result; | 147 Handle<Object> result; |
| 171 if (in_cache) { | 148 if (in_cache) { |
| 172 re->set_data(*cached); | 149 re->set_data(*cached); |
| (...skipping 5987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6160 } | 6137 } |
| 6161 | 6138 |
| 6162 return compiler.Assemble(¯o_assembler, | 6139 return compiler.Assemble(¯o_assembler, |
| 6163 node, | 6140 node, |
| 6164 data->capture_count, | 6141 data->capture_count, |
| 6165 pattern); | 6142 pattern); |
| 6166 } | 6143 } |
| 6167 | 6144 |
| 6168 | 6145 |
| 6169 }} // namespace v8::internal | 6146 }} // namespace v8::internal |
| OLD | NEW |