OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/inspector/V8Regex.h" | 5 #include "src/inspector/V8Regex.h" |
6 | 6 |
7 #include "src/inspector/StringUtil.h" | 7 #include "src/inspector/StringUtil.h" |
8 #include "src/inspector/V8InspectorImpl.h" | 8 #include "src/inspector/V8InspectorImpl.h" |
9 | 9 |
10 #include "include/v8-inspector.h" | 10 #include "include/v8-inspector.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 v8::Local<v8::RegExp> regex = m_regex.Get(isolate); | 56 v8::Local<v8::RegExp> regex = m_regex.Get(isolate); |
57 v8::Local<v8::Value> exec; | 57 v8::Local<v8::Value> exec; |
58 if (!regex->Get(context, toV8StringInternalized(isolate, "exec")) | 58 if (!regex->Get(context, toV8StringInternalized(isolate, "exec")) |
59 .ToLocal(&exec)) | 59 .ToLocal(&exec)) |
60 return -1; | 60 return -1; |
61 v8::Local<v8::Value> argv[] = { | 61 v8::Local<v8::Value> argv[] = { |
62 toV8String(isolate, string.substring(startFrom))}; | 62 toV8String(isolate, string.substring(startFrom))}; |
63 v8::Local<v8::Value> returnValue; | 63 v8::Local<v8::Value> returnValue; |
64 if (!exec.As<v8::Function>() | 64 if (!exec.As<v8::Function>() |
65 ->Call(context, regex, V8_INSPECTOR_ARRAY_LENGTH(argv), argv) | 65 ->Call(context, regex, arraysize(argv), argv) |
66 .ToLocal(&returnValue)) | 66 .ToLocal(&returnValue)) |
67 return -1; | 67 return -1; |
68 | 68 |
69 // RegExp#exec returns null if there's no match, otherwise it returns an | 69 // RegExp#exec returns null if there's no match, otherwise it returns an |
70 // Array of strings with the first being the whole match string and others | 70 // Array of strings with the first being the whole match string and others |
71 // being subgroups. The Array also has some random properties tacked on like | 71 // being subgroups. The Array also has some random properties tacked on like |
72 // "index" which is the offset of the match. | 72 // "index" which is the offset of the match. |
73 // | 73 // |
74 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Object
s/RegExp/exec | 74 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Object
s/RegExp/exec |
75 | 75 |
76 DCHECK(!returnValue.IsEmpty()); | 76 DCHECK(!returnValue.IsEmpty()); |
77 if (!returnValue->IsArray()) return -1; | 77 if (!returnValue->IsArray()) return -1; |
78 | 78 |
79 v8::Local<v8::Array> result = returnValue.As<v8::Array>(); | 79 v8::Local<v8::Array> result = returnValue.As<v8::Array>(); |
80 v8::Local<v8::Value> matchOffset; | 80 v8::Local<v8::Value> matchOffset; |
81 if (!result->Get(context, toV8StringInternalized(isolate, "index")) | 81 if (!result->Get(context, toV8StringInternalized(isolate, "index")) |
82 .ToLocal(&matchOffset)) | 82 .ToLocal(&matchOffset)) |
83 return -1; | 83 return -1; |
84 if (matchLength) { | 84 if (matchLength) { |
85 v8::Local<v8::Value> match; | 85 v8::Local<v8::Value> match; |
86 if (!result->Get(context, 0).ToLocal(&match)) return -1; | 86 if (!result->Get(context, 0).ToLocal(&match)) return -1; |
87 *matchLength = match.As<v8::String>()->Length(); | 87 *matchLength = match.As<v8::String>()->Length(); |
88 } | 88 } |
89 | 89 |
90 return matchOffset.As<v8::Int32>()->Value() + startFrom; | 90 return matchOffset.As<v8::Int32>()->Value() + startFrom; |
91 } | 91 } |
92 | 92 |
93 } // namespace v8_inspector | 93 } // namespace v8_inspector |
OLD | NEW |