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

Side by Side Diff: Source/bindings/core/v8/ScriptRegexp.cpp

Issue 1036803002: binidngs: Make callInternalFunction return MaybeLocal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora Ltd. 3 * Copyright (C) 2008 Collabora Ltd.
4 * Copyright (C) 2011 Peter Varga (pvarga@webkit.org), University of Szeged 4 * Copyright (C) 2011 Peter Varga (pvarga@webkit.org), University of Szeged
5 * Copyright (C) 2013 Google Inc. All rights reserved. 5 * Copyright (C) 2013 Google Inc. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ScriptForbiddenScope::AllowUserAgentScript allowScript; 69 ScriptForbiddenScope::AllowUserAgentScript allowScript;
70 70
71 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 71 v8::Isolate* isolate = v8::Isolate::GetCurrent();
72 v8::HandleScope handleScope(isolate); 72 v8::HandleScope handleScope(isolate);
73 v8::Context::Scope contextScope(V8PerIsolateData::from(isolate)->ensureScrip tRegexpContext()); 73 v8::Context::Scope contextScope(V8PerIsolateData::from(isolate)->ensureScrip tRegexpContext());
74 v8::TryCatch tryCatch; 74 v8::TryCatch tryCatch;
75 75
76 v8::Local<v8::RegExp> regex = m_regex.newLocal(isolate); 76 v8::Local<v8::RegExp> regex = m_regex.newLocal(isolate);
77 v8::Local<v8::Function> exec = regex->Get(v8AtomicString(isolate, "exec")).A s<v8::Function>(); 77 v8::Local<v8::Function> exec = regex->Get(v8AtomicString(isolate, "exec")).A s<v8::Function>();
78 v8::Local<v8::Value> argv[] = { v8String(isolate, string.substring(startFrom )) }; 78 v8::Local<v8::Value> argv[] = { v8String(isolate, string.substring(startFrom )) };
79 v8::Local<v8::Value> returnValue = V8ScriptRunner::callInternalFunction(exec , regex, WTF_ARRAY_LENGTH(argv), argv, isolate); 79 v8::Local<v8::Value> returnValue;
80 80 if (!V8ScriptRunner::callInternalFunction(exec, regex, WTF_ARRAY_LENGTH(argv ), argv, isolate).ToLocal(&returnValue))
81 if (tryCatch.HasCaught())
82 return -1; 81 return -1;
83 82
84 // RegExp#exec returns null if there's no match, otherwise it returns an 83 // RegExp#exec returns null if there's no match, otherwise it returns an
85 // Array of strings with the first being the whole match string and others 84 // Array of strings with the first being the whole match string and others
86 // being subgroups. The Array also has some random properties tacked on like 85 // being subgroups. The Array also has some random properties tacked on like
87 // "index" which is the offset of the match. 86 // "index" which is the offset of the match.
88 // 87 //
89 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obje cts/RegExp/exec 88 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Obje cts/RegExp/exec
90 89
91 ASSERT(!returnValue.IsEmpty()); 90 ASSERT(!returnValue.IsEmpty());
92 if (!returnValue->IsArray()) 91 if (!returnValue->IsArray())
93 return -1; 92 return -1;
94 93
95 v8::Local<v8::Array> result = returnValue.As<v8::Array>(); 94 v8::Local<v8::Array> result = returnValue.As<v8::Array>();
96 int matchOffset = result->Get(v8AtomicString(isolate, "index"))->ToInt32(iso late)->Value(); 95 int matchOffset = result->Get(v8AtomicString(isolate, "index"))->ToInt32(iso late)->Value();
97 if (matchLength) { 96 if (matchLength) {
98 v8::Local<v8::String> match = result->Get(0).As<v8::String>(); 97 v8::Local<v8::String> match = result->Get(0).As<v8::String>();
99 *matchLength = match->Length(); 98 *matchLength = match->Length();
100 } 99 }
101 100
102 return matchOffset + startFrom; 101 return matchOffset + startFrom;
103 } 102 }
104 103
105 } // namespace blink 104 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698