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/V8DebuggerImpl.h" | 7 #include "platform/v8_inspector/V8DebuggerImpl.h" |
8 #include "platform/v8_inspector/V8StringUtil.h" | 8 #include "platform/v8_inspector/V8StringUtil.h" |
9 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 9 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 V8Regex::V8Regex(V8DebuggerImpl* debugger, const String& pattern, TextCaseSensit
ivity caseSensitivity, MultilineMode multilineMode) | 13 V8Regex::V8Regex(V8DebuggerImpl* debugger, const String16& pattern, bool caseSen
sitive, bool multiline) |
14 : m_debugger(debugger) | 14 : m_debugger(debugger) |
15 { | 15 { |
16 v8::Isolate* isolate = m_debugger->isolate(); | 16 v8::Isolate* isolate = m_debugger->isolate(); |
17 v8::HandleScope handleScope(isolate); | 17 v8::HandleScope handleScope(isolate); |
18 v8::Local<v8::Context> context = m_debugger->regexContext(); | 18 v8::Local<v8::Context> context = m_debugger->regexContext(); |
19 v8::Context::Scope contextScope(context); | 19 v8::Context::Scope contextScope(context); |
20 v8::TryCatch tryCatch(isolate); | 20 v8::TryCatch tryCatch(isolate); |
21 | 21 |
22 unsigned flags = v8::RegExp::kNone; | 22 unsigned flags = v8::RegExp::kNone; |
23 if (caseSensitivity == TextCaseInsensitive) | 23 if (!caseSensitive) |
24 flags |= v8::RegExp::kIgnoreCase; | 24 flags |= v8::RegExp::kIgnoreCase; |
25 if (multilineMode == MultilineEnabled) | 25 if (multiline) |
26 flags |= v8::RegExp::kMultiline; | 26 flags |= v8::RegExp::kMultiline; |
27 | 27 |
28 v8::Local<v8::RegExp> regex; | 28 v8::Local<v8::RegExp> regex; |
29 if (v8::RegExp::New(context, toV8String(isolate, pattern), static_cast<v8::R
egExp::Flags>(flags)).ToLocal(®ex)) | 29 if (v8::RegExp::New(context, toV8String(isolate, pattern), static_cast<v8::R
egExp::Flags>(flags)).ToLocal(®ex)) |
30 m_regex.Reset(isolate, regex); | 30 m_regex.Reset(isolate, regex); |
31 } | 31 } |
32 | 32 |
33 int V8Regex::match(const String& string, int startFrom, int* matchLength) const | 33 int V8Regex::match(const String16& string, int startFrom, int* matchLength) cons
t |
34 { | 34 { |
35 if (matchLength) | 35 if (matchLength) |
36 *matchLength = 0; | 36 *matchLength = 0; |
37 | 37 |
38 if (m_regex.IsEmpty() || string.isNull()) | 38 if (m_regex.IsEmpty() || string.isNull()) |
39 return -1; | 39 return -1; |
40 | 40 |
41 // v8 strings are limited to int. | 41 // v8 strings are limited to int. |
42 if (string.length() > INT_MAX) | 42 if (string.length() > INT_MAX) |
43 return -1; | 43 return -1; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 v8::Local<v8::Value> match; | 76 v8::Local<v8::Value> match; |
77 if (!result->Get(context, 0).ToLocal(&match)) | 77 if (!result->Get(context, 0).ToLocal(&match)) |
78 return -1; | 78 return -1; |
79 *matchLength = match.As<v8::String>()->Length(); | 79 *matchLength = match.As<v8::String>()->Length(); |
80 } | 80 } |
81 | 81 |
82 return matchOffset.As<v8::Int32>()->Value() + startFrom; | 82 return matchOffset.As<v8::Int32>()->Value() + startFrom; |
83 } | 83 } |
84 | 84 |
85 } // namespace blink | 85 } // namespace blink |
OLD | NEW |