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

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

Issue 2330843002: Blink-in-JS should not run micro tasks (Closed)
Patch Set: temp Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | 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 "bindings/core/v8/PrivateScriptRunner.h" 5 #include "bindings/core/v8/PrivateScriptRunner.h"
6 6
7 #include "bindings/core/v8/DOMWrapperWorld.h" 7 #include "bindings/core/v8/DOMWrapperWorld.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/V8Binding.h" 9 #include "bindings/core/v8/V8Binding.h"
10 #include "bindings/core/v8/V8PerContextData.h" 10 #include "bindings/core/v8/V8PerContextData.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 v8::Local<v8::Context> context = scriptState->context(); 193 v8::Local<v8::Context> context = scriptState->context();
194 auto privateIsInitialized = V8PrivateProperty::getPrivateScriptRunnerIsIniti alized(isolate); 194 auto privateIsInitialized = V8PrivateProperty::getPrivateScriptRunnerIsIniti alized(isolate);
195 if (privateIsInitialized.hasValue(context, holderObject)) 195 if (privateIsInitialized.hasValue(context, holderObject))
196 return; // Already initialized. 196 return; // Already initialized.
197 197
198 v8::TryCatch block(isolate); 198 v8::TryCatch block(isolate);
199 v8::Local<v8::Value> initializeFunction; 199 v8::Local<v8::Value> initializeFunction;
200 if (classObject->Get(scriptState->context(), v8String(isolate, "initialize") ).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) { 200 if (classObject->Get(scriptState->context(), v8String(isolate, "initialize") ).ToLocal(&initializeFunction) && initializeFunction->IsFunction()) {
201 v8::TryCatch block(isolate); 201 v8::TryCatch block(isolate);
202 v8::Local<v8::Value> result; 202 v8::Local<v8::Value> result;
203 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(initiali zeFunction), scriptState->getExecutionContext(), holder, 0, 0, isolate).ToLocal( &result)) { 203 if (!V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast( initializeFunction), holder, 0, 0, isolate).ToLocal(&result)) {
204 fprintf(stderr, "Private script error: Object constructor threw an e xception.\n"); 204 fprintf(stderr, "Private script error: Object constructor threw an e xception.\n");
205 dumpV8Message(context, block.Message()); 205 dumpV8Message(context, block.Message());
206 RELEASE_NOTREACHED(); 206 RELEASE_NOTREACHED();
207 } 207 }
208 } 208 }
209 209
210 // Inject the prototype object of the private script into the prototype chai n of the holder object. 210 // Inject the prototype object of the private script into the prototype chai n of the holder object.
211 // This is necessary to let the holder object use properties defined on the prototype object 211 // This is necessary to let the holder object use properties defined on the prototype object
212 // of the private script. (e.g., if the prototype object has |foo|, the hold er object should be able 212 // of the private script. (e.g., if the prototype object has |foo|, the hold er object should be able
213 // to use it with |this.foo|.) 213 // to use it with |this.foo|.)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 RELEASE_NOTREACHED(); 298 RELEASE_NOTREACHED();
299 } 299 }
300 v8::Local<v8::Value> getter; 300 v8::Local<v8::Value> getter;
301 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "get")).ToLocal(&getter) || !getter->IsFunction()) { 301 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "get")).ToLocal(&getter) || !getter->IsFunction()) {
302 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 302 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
303 RELEASE_NOTREACHED(); 303 RELEASE_NOTREACHED();
304 } 304 }
305 initializeHolderIfNeeded(scriptState, classObject, holder); 305 initializeHolderIfNeeded(scriptState, classObject, holder);
306 v8::TryCatch block(isolate); 306 v8::TryCatch block(isolate);
307 v8::Local<v8::Value> result; 307 v8::Local<v8::Value> result;
308 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(getter), scr iptState->getExecutionContext(), holder, 0, 0, isolate).ToLocal(&result)) { 308 if (!V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(gett er), holder, 0, 0, isolate).ToLocal(&result)) {
309 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::GetterContext, attributeName, className); 309 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::GetterContext, attributeName, className);
310 block.ReThrow(); 310 block.ReThrow();
311 return v8::Local<v8::Value>(); 311 return v8::Local<v8::Value>();
312 } 312 }
313 return result; 313 return result;
314 } 314 }
315 315
316 bool PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, Script State* scriptStateInUserScript, const char* className, const char* attributeName , v8::Local<v8::Value> holder, v8::Local<v8::Value> v8Value) 316 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 { 317 {
318 v8::Isolate* isolate = scriptState->isolate(); 318 v8::Isolate* isolate = scriptState->isolate();
319 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 319 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
320 v8::Local<v8::Value> descriptor; 320 v8::Local<v8::Value> descriptor;
321 if (!classObject->GetOwnPropertyDescriptor(scriptState->context(), v8String( isolate, attributeName)).ToLocal(&descriptor) || !descriptor->IsObject()) { 321 if (!classObject->GetOwnPropertyDescriptor(scriptState->context(), v8String( isolate, attributeName)).ToLocal(&descriptor) || !descriptor->IsObject()) {
322 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 322 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
323 RELEASE_NOTREACHED(); 323 RELEASE_NOTREACHED();
324 } 324 }
325 v8::Local<v8::Value> setter; 325 v8::Local<v8::Value> setter;
326 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "set")).ToLocal(&setter) || !setter->IsFunction()) { 326 if (!v8::Local<v8::Object>::Cast(descriptor)->Get(scriptState->context(), v8 String(isolate, "set")).ToLocal(&setter) || !setter->IsFunction()) {
327 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName); 327 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
328 RELEASE_NOTREACHED(); 328 RELEASE_NOTREACHED();
329 } 329 }
330 initializeHolderIfNeeded(scriptState, classObject, holder); 330 initializeHolderIfNeeded(scriptState, classObject, holder);
331 v8::Local<v8::Value> argv[] = { v8Value }; 331 v8::Local<v8::Value> argv[] = { v8Value };
332 v8::TryCatch block(isolate); 332 v8::TryCatch block(isolate);
333 v8::Local<v8::Value> result; 333 v8::Local<v8::Value> result;
334 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(setter), scr iptState->getExecutionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, isolate). ToLocal(&result)) { 334 if (!V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(sett er), holder, WTF_ARRAY_LENGTH(argv), argv, isolate).ToLocal(&result)) {
335 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::SetterContext, attributeName, className); 335 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, ExceptionState::SetterContext, attributeName, className);
336 block.ReThrow(); 336 block.ReThrow();
337 return false; 337 return false;
338 } 338 }
339 return true; 339 return true;
340 } 340 }
341 341
342 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[]) 342 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 { 343 {
344 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className); 344 v8::Local<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
345 v8::Local<v8::Value> method; 345 v8::Local<v8::Value> method;
346 if (!classObject->Get(scriptState->context(), v8String(scriptState->isolate( ), methodName)).ToLocal(&method) || !method->IsFunction()) { 346 if (!classObject->Get(scriptState->context(), v8String(scriptState->isolate( ), methodName)).ToLocal(&method) || !method->IsFunction()) {
347 fprintf(stderr, "Private script error: Target DOM method was not found. (Class name = %s, Method name = %s)\n", className, methodName); 347 fprintf(stderr, "Private script error: Target DOM method was not found. (Class name = %s, Method name = %s)\n", className, methodName);
348 RELEASE_NOTREACHED(); 348 RELEASE_NOTREACHED();
349 } 349 }
350 initializeHolderIfNeeded(scriptState, classObject, holder); 350 initializeHolderIfNeeded(scriptState, classObject, holder);
351 v8::TryCatch block(scriptState->isolate()); 351 v8::TryCatch block(scriptState->isolate());
352 v8::Local<v8::Value> result; 352 v8::Local<v8::Value> result;
353 if (!V8ScriptRunner::callFunction(v8::Local<v8::Function>::Cast(method), scr iptState->getExecutionContext(), holder, argc, argv, scriptState->isolate()).ToL ocal(&result)) { 353 if (!V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(meth od), holder, argc, argv, scriptState->isolate()).ToLocal(&result)) {
354 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className); 354 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className);
355 block.ReThrow(); 355 block.ReThrow();
356 return v8::Local<v8::Value>(); 356 return v8::Local<v8::Value>();
357 } 357 }
358 return result; 358 return result;
359 } 359 }
360 360
361 } // namespace blink 361 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698