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

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

Issue 1061503005: bindings: Use Maybe version of Call() (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
« no previous file with comments | « Source/bindings/core/v8/NPV8Object.cpp ('k') | Source/bindings/core/v8/ScriptController.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/PrivateScriptRunner.h" 6 #include "bindings/core/v8/PrivateScriptRunner.h"
7 7
8 #include "bindings/core/v8/DOMWrapperWorld.h" 8 #include "bindings/core/v8/DOMWrapperWorld.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 RELEASE_ASSERT(holder->IsObject()); 189 RELEASE_ASSERT(holder->IsObject());
190 v8::Local<v8::Object> holderObject = v8::Local<v8::Object>::Cast(holder); 190 v8::Local<v8::Object> holderObject = v8::Local<v8::Object>::Cast(holder);
191 v8::Isolate* isolate = scriptState->isolate(); 191 v8::Isolate* isolate = scriptState->isolate();
192 v8::Local<v8::Context> context = scriptState->context(); 192 v8::Local<v8::Context> context = scriptState->context();
193 v8::Local<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate)); 193 v8::Local<v8::Value> isInitialized = V8HiddenValue::getHiddenValue(isolate, holderObject, V8HiddenValue::privateScriptObjectIsInitialized(isolate));
194 if (isInitialized.IsEmpty()) { 194 if (isInitialized.IsEmpty()) {
195 v8::TryCatch block; 195 v8::TryCatch block;
196 v8::Local<v8::Value> initializeFunction; 196 v8::Local<v8::Value> initializeFunction;
197 if (classObject->Get(scriptState->context(), v8String(isolate, "initiali ze")).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) { 197 if (classObject->Get(scriptState->context(), v8String(isolate, "initiali ze")).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) {
198 v8::TryCatch block; 198 v8::TryCatch block;
199 V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(initializ eFunction), scriptState->executionContext(), holder, 0, 0, isolate); 199 v8::Local<v8::Value> result;
200 if (block.HasCaught()) { 200 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(init ializeFunction), scriptState->executionContext(), holder, 0, 0, isolate).ToLocal (&result)) {
201 fprintf(stderr, "Private script error: Object constructor threw an exception.\n"); 201 fprintf(stderr, "Private script error: Object constructor threw an exception.\n");
202 dumpV8Message(context, block.Message()); 202 dumpV8Message(context, block.Message());
203 RELEASE_ASSERT_NOT_REACHED(); 203 RELEASE_ASSERT_NOT_REACHED();
204 } 204 }
205 } 205 }
206 206
207 // Inject the prototype object of the private script into the prototype chain of the holder object. 207 // Inject the prototype object of the private script into the prototype chain of the holder object.
208 // This is necessary to let the holder object use properties defined on the prototype object 208 // This is necessary to let the holder object use properties defined on the prototype object
209 // of the private script. (e.g., if the prototype object has |foo|, the holder object should be able 209 // of the private script. (e.g., if the prototype object has |foo|, the holder object should be able
210 // to use it with |this.foo|.) 210 // to use it with |this.foo|.)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 298 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
299 RELEASE_ASSERT_NOT_REACHED(); 299 RELEASE_ASSERT_NOT_REACHED();
300 } 300 }
301 v8::Local<v8::Value> getter; 301 v8::Local<v8::Value> getter;
302 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "get")).ToLocal(&getter) || !getter->IsFunction()) { 302 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "get")).ToLocal(&getter) || !getter->IsFunction()) {
303 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 303 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
304 RELEASE_ASSERT_NOT_REACHED(); 304 RELEASE_ASSERT_NOT_REACHED();
305 } 305 }
306 initializeHolderIfNeeded(scriptState, classObject, holder); 306 initializeHolderIfNeeded(scriptState, classObject, holder);
307 v8::TryCatch block; 307 v8::TryCatch block;
308 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(v8::Local<v8::Fun ction>::Cast(getter), scriptState->executionContext(), holder, 0, 0, isolate); 308 v8::Local<v8::Value> result;
309 if (block.HasCaught()) { 309 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(getter), scr iptState->executionContext(), holder, 0, 0, isolate).ToLocal(&result)) {
310 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::GetterContext, attributeName, className); 310 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::GetterContext, attributeName, className);
311 block.ReThrow(); 311 block.ReThrow();
312 return v8::Local<v8::Value>(); 312 return v8::Local<v8::Value>();
313 } 313 }
314 return result; 314 return result;
315 } 315 }
316 316
317 bool PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, Script State* scriptStateInUserScript, const char* className, const char* attributeName , v8::Local<v8::Value> holder, v8::Local<v8::Value> v8Value) 317 bool PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, Script State* scriptStateInUserScript, const char* className, const char* attributeName , v8::Local<v8::Value> holder, v8::Local<v8::Value> v8Value)
318 { 318 {
319 v8::Isolate* isolate = scriptState->isolate(); 319 v8::Isolate* isolate = scriptState->isolate();
320 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 320 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
321 v8::Local<v8::Value> descriptor; 321 v8::Local<v8::Value> descriptor;
322 if (!classObject->GetOwnPropertyDescriptor(scriptState->context(), v8String( isolate, attributeName)).ToLocal(&descriptor) || !descriptor->IsObject()) { 322 if (!classObject->GetOwnPropertyDescriptor(scriptState->context(), v8String( isolate, attributeName)).ToLocal(&descriptor) || !descriptor->IsObject()) {
323 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 323 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
324 RELEASE_ASSERT_NOT_REACHED(); 324 RELEASE_ASSERT_NOT_REACHED();
325 } 325 }
326 v8::Local<v8::Value> setter; 326 v8::Local<v8::Value> setter;
327 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "set")).ToLocal(&setter) || !setter->IsFunction()) { 327 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "set")).ToLocal(&setter) || !setter->IsFunction()) {
328 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 328 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
329 RELEASE_ASSERT_NOT_REACHED(); 329 RELEASE_ASSERT_NOT_REACHED();
330 } 330 }
331 initializeHolderIfNeeded(scriptState, classObject, holder); 331 initializeHolderIfNeeded(scriptState, classObject, holder);
332 v8::Local<v8::Value> argv[] = { v8Value }; 332 v8::Local<v8::Value> argv[] = { v8Value };
333 v8::TryCatch block; 333 v8::TryCatch block;
334 V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(setter), scriptSt ate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, isolate); 334 v8::Local<v8::Value> result;
335 if (block.HasCaught()) { 335 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(setter), scr iptState->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, isolate).ToL ocal(&result)) {
336 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::SetterContext, attributeName, className); 336 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::SetterContext, attributeName, className);
337 block.ReThrow(); 337 block.ReThrow();
338 return false; 338 return false;
339 } 339 }
340 return true; 340 return true;
341 } 341 }
342 342
343 v8::Local<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState, ScriptState* scriptStateInUserScript, const char* className, const char* method Name, v8::Local<v8::Value> holder, int argc, v8::Local<v8::Value> argv[]) 343 v8::Local<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState, ScriptState* scriptStateInUserScript, const char* className, const char* method Name, v8::Local<v8::Value> holder, int argc, v8::Local<v8::Value> argv[])
344 { 344 {
345 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 345 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
346 v8::Local<v8::Value> method; 346 v8::Local<v8::Value> method;
347 if (!classObject->Get(scriptState->context(), v8String(scriptState->isolate( ), methodName)).ToLocal(&method) || !method->IsFunction()) { 347 if (!classObject->Get(scriptState->context(), v8String(scriptState->isolate( ), methodName)).ToLocal(&method) || !method->IsFunction()) {
348 fprintf(stderr, "Private script error: Target DOM method was not found. (Class name = %s, Method name = %s)\n", className, methodName); 348 fprintf(stderr, "Private script error: Target DOM method was not found. (Class name = %s, Method name = %s)\n", className, methodName);
349 RELEASE_ASSERT_NOT_REACHED(); 349 RELEASE_ASSERT_NOT_REACHED();
350 } 350 }
351 initializeHolderIfNeeded(scriptState, classObject, holder); 351 initializeHolderIfNeeded(scriptState, classObject, holder);
352 v8::TryCatch block; 352 v8::TryCatch block;
353 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(v8::Local<v8::Fun ction>::Cast(method), scriptState->executionContext(), holder, argc, argv, scrip tState->isolate()); 353 v8::Local<v8::Value> result;
354 if (block.HasCaught()) { 354 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(method), scr iptState->executionContext(), holder, argc, argv, scriptState->isolate()).ToLoca l(&result)) {
355 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className); 355 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className);
356 block.ReThrow(); 356 block.ReThrow();
357 return v8::Local<v8::Value>(); 357 return v8::Local<v8::Value>();
358 } 358 }
359 return result; 359 return result;
360 } 360 }
361 361
362 } // namespace blink 362 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/NPV8Object.cpp ('k') | Source/bindings/core/v8/ScriptController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698