| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "platform/v8_inspector/V8Regex.h" | 5 #include "platform/v8_inspector/V8Regex.h" |
| 6 | 6 |
| 7 #include "platform/v8_inspector/V8Compat.h" | 7 #include "platform/v8_inspector/V8Compat.h" |
| 8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8InspectorImpl.h" |
| 9 #include "platform/v8_inspector/V8StringUtil.h" | 9 #include "platform/v8_inspector/V8StringUtil.h" |
| 10 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 10 #include "platform/v8_inspector/public/V8InspectorClient.h" |
| 11 | 11 |
| 12 #include <limits.h> | 12 #include <limits.h> |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 V8Regex::V8Regex(V8DebuggerImpl* debugger, const String16& pattern, bool caseSen
sitive, bool multiline) | 16 V8Regex::V8Regex(V8InspectorImpl* inspector, const String16& pattern, bool caseS
ensitive, bool multiline) |
| 17 : m_debugger(debugger) | 17 : m_inspector(inspector) |
| 18 { | 18 { |
| 19 v8::Isolate* isolate = m_debugger->isolate(); | 19 v8::Isolate* isolate = m_inspector->isolate(); |
| 20 v8::HandleScope handleScope(isolate); | 20 v8::HandleScope handleScope(isolate); |
| 21 v8::Local<v8::Context> context = m_debugger->regexContext(); | 21 v8::Local<v8::Context> context = m_inspector->regexContext(); |
| 22 v8::Context::Scope contextScope(context); | 22 v8::Context::Scope contextScope(context); |
| 23 v8::TryCatch tryCatch(isolate); | 23 v8::TryCatch tryCatch(isolate); |
| 24 | 24 |
| 25 unsigned flags = v8::RegExp::kNone; | 25 unsigned flags = v8::RegExp::kNone; |
| 26 if (!caseSensitive) | 26 if (!caseSensitive) |
| 27 flags |= v8::RegExp::kIgnoreCase; | 27 flags |= v8::RegExp::kIgnoreCase; |
| 28 if (multiline) | 28 if (multiline) |
| 29 flags |= v8::RegExp::kMultiline; | 29 flags |= v8::RegExp::kMultiline; |
| 30 | 30 |
| 31 v8::Local<v8::RegExp> regex; | 31 v8::Local<v8::RegExp> regex; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 42 if (matchLength) | 42 if (matchLength) |
| 43 *matchLength = 0; | 43 *matchLength = 0; |
| 44 | 44 |
| 45 if (m_regex.IsEmpty() || string.isEmpty()) | 45 if (m_regex.IsEmpty() || string.isEmpty()) |
| 46 return -1; | 46 return -1; |
| 47 | 47 |
| 48 // v8 strings are limited to int. | 48 // v8 strings are limited to int. |
| 49 if (string.length() > INT_MAX) | 49 if (string.length() > INT_MAX) |
| 50 return -1; | 50 return -1; |
| 51 | 51 |
| 52 v8::Isolate* isolate = m_debugger->isolate(); | 52 v8::Isolate* isolate = m_inspector->isolate(); |
| 53 v8::HandleScope handleScope(isolate); | 53 v8::HandleScope handleScope(isolate); |
| 54 v8::Local<v8::Context> context = m_debugger->regexContext(); | 54 v8::Local<v8::Context> context = m_inspector->regexContext(); |
| 55 v8::MicrotasksScope microtasks(isolate, v8::MicrotasksScope::kDoNotRunMicrot
asks); | 55 v8::MicrotasksScope microtasks(isolate, v8::MicrotasksScope::kDoNotRunMicrot
asks); |
| 56 v8::TryCatch tryCatch(isolate); | 56 v8::TryCatch tryCatch(isolate); |
| 57 | 57 |
| 58 v8::Local<v8::RegExp> regex = m_regex.Get(isolate); | 58 v8::Local<v8::RegExp> regex = m_regex.Get(isolate); |
| 59 v8::Local<v8::Value> exec; | 59 v8::Local<v8::Value> exec; |
| 60 if (!regex->Get(context, toV8StringInternalized(isolate, "exec")).ToLocal(&e
xec)) | 60 if (!regex->Get(context, toV8StringInternalized(isolate, "exec")).ToLocal(&e
xec)) |
| 61 return -1; | 61 return -1; |
| 62 v8::Local<v8::Value> argv[] = { toV8String(isolate, string.substring(startFr
om)) }; | 62 v8::Local<v8::Value> argv[] = { toV8String(isolate, string.substring(startFr
om)) }; |
| 63 v8::Local<v8::Value> returnValue; | 63 v8::Local<v8::Value> returnValue; |
| 64 if (!exec.As<v8::Function>()->Call(context, regex, PROTOCOL_ARRAY_LENGTH(arg
v), argv).ToLocal(&returnValue)) | 64 if (!exec.As<v8::Function>()->Call(context, regex, PROTOCOL_ARRAY_LENGTH(arg
v), argv).ToLocal(&returnValue)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 v8::Local<v8::Value> match; | 83 v8::Local<v8::Value> match; |
| 84 if (!result->Get(context, 0).ToLocal(&match)) | 84 if (!result->Get(context, 0).ToLocal(&match)) |
| 85 return -1; | 85 return -1; |
| 86 *matchLength = match.As<v8::String>()->Length(); | 86 *matchLength = match.As<v8::String>()->Length(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 return matchOffset.As<v8::Int32>()->Value() + startFrom; | 89 return matchOffset.As<v8::Int32>()->Value() + startFrom; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace blink | 92 } // namespace blink |
| OLD | NEW |