Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8Regex.cpp

Issue 1804043002: Revert of Remove V8RecrusionScope, cleanup call sites. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 27 matching lines...) Expand all
38 if (m_regex.IsEmpty() || string.isEmpty()) 38 if (m_regex.IsEmpty() || string.isEmpty())
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;
44 44
45 v8::Isolate* isolate = m_debugger->isolate(); 45 v8::Isolate* isolate = m_debugger->isolate();
46 v8::HandleScope handleScope(isolate); 46 v8::HandleScope handleScope(isolate);
47 v8::Local<v8::Context> context = m_debugger->regexContext(); 47 v8::Local<v8::Context> context = m_debugger->regexContext();
48 v8::Context::Scope contextScope(context);
48 v8::TryCatch tryCatch(isolate); 49 v8::TryCatch tryCatch(isolate);
49 50
50 v8::Local<v8::RegExp> regex = m_regex.Get(isolate); 51 v8::Local<v8::RegExp> regex = m_regex.Get(isolate);
51 v8::Local<v8::Value> exec; 52 v8::Local<v8::Value> exec;
52 if (!regex->Get(context, toV8StringInternalized(isolate, "exec")).ToLocal(&e xec)) 53 if (!regex->Get(context, toV8StringInternalized(isolate, "exec")).ToLocal(&e xec))
53 return -1; 54 return -1;
54 v8::Local<v8::Value> argv[] = { toV8String(isolate, string.substring(startFr om)) }; 55 v8::Local<v8::Value> argv[] = { toV8String(isolate, string.substring(startFr om)) };
55 v8::Local<v8::Value> returnValue; 56 v8::Local<v8::Value> returnValue;
56 if (!exec.As<v8::Function>()->Call(context, regex, WTF_ARRAY_LENGTH(argv), a rgv).ToLocal(&returnValue)) 57 if (!m_debugger->client()->callInternalFunction(exec.As<v8::Function>(), reg ex, WTF_ARRAY_LENGTH(argv), argv).ToLocal(&returnValue))
57 return -1; 58 return -1;
58 59
59 // RegExp#exec returns null if there's no match, otherwise it returns an 60 // RegExp#exec returns null if there's no match, otherwise it returns an
60 // Array of strings with the first being the whole match string and others 61 // Array of strings with the first being the whole match string and others
61 // being subgroups. The Array also has some random properties tacked on like 62 // being subgroups. The Array also has some random properties tacked on like
62 // "index" which is the offset of the match. 63 // "index" which is the offset of the match.
63 // 64 //
64 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obje cts/RegExp/exec 65 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obje cts/RegExp/exec
65 66
66 ASSERT(!returnValue.IsEmpty()); 67 ASSERT(!returnValue.IsEmpty());
67 if (!returnValue->IsArray()) 68 if (!returnValue->IsArray())
68 return -1; 69 return -1;
69 70
70 v8::Local<v8::Array> result = returnValue.As<v8::Array>(); 71 v8::Local<v8::Array> result = returnValue.As<v8::Array>();
71 v8::Local<v8::Value> matchOffset; 72 v8::Local<v8::Value> matchOffset;
72 if (!result->Get(context, toV8StringInternalized(isolate, "index")).ToLocal( &matchOffset)) 73 if (!result->Get(context, toV8StringInternalized(isolate, "index")).ToLocal( &matchOffset))
73 return -1; 74 return -1;
74 if (matchLength) { 75 if (matchLength) {
75 v8::Local<v8::Value> match; 76 v8::Local<v8::Value> match;
76 if (!result->Get(context, 0).ToLocal(&match)) 77 if (!result->Get(context, 0).ToLocal(&match))
77 return -1; 78 return -1;
78 *matchLength = match.As<v8::String>()->Length(); 79 *matchLength = match.As<v8::String>()->Length();
79 } 80 }
80 81
81 return matchOffset.As<v8::Int32>()->Value() + startFrom; 82 return matchOffset.As<v8::Int32>()->Value() + startFrom;
82 } 83 }
83 84
84 } // namespace blink 85 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698