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

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

Issue 2518933002: Remove RELEASE_NOTREACHED(). (Closed)
Patch Set: Created 4 years, 1 month 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 | third_party/WebKit/Source/core/frame/DOMWindow.cpp » ('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 "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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 privateScriptControllerObject->Get(context, v8String(isolate, "import")) 69 privateScriptControllerObject->Get(context, v8String(isolate, "import"))
70 .ToLocalChecked(); 70 .ToLocalChecked();
71 if (importFunctionValue->IsUndefined()) { 71 if (importFunctionValue->IsUndefined()) {
72 v8::Local<v8::Function> function; 72 v8::Local<v8::Function> function;
73 // This is a memory leak, FunctionTemplates are eternal. 73 // This is a memory leak, FunctionTemplates are eternal.
74 if (!v8::FunctionTemplate::New(isolate, importFunction) 74 if (!v8::FunctionTemplate::New(isolate, importFunction)
75 ->GetFunction(context) 75 ->GetFunction(context)
76 .ToLocal(&function) || 76 .ToLocal(&function) ||
77 !v8CallBoolean(privateScriptControllerObject->Set( 77 !v8CallBoolean(privateScriptControllerObject->Set(
78 context, v8String(isolate, "import"), function))) { 78 context, v8String(isolate, "import"), function))) {
79 fprintf(stderr,
80 "Private script error: Setting import function failed. (Class "
81 "name = %s)\n",
82 scriptClassName.utf8().data());
83 dumpV8Message(context, block.Message()); 79 dumpV8Message(context, block.Message());
84 RELEASE_NOTREACHED(); 80 LOG(FATAL)
81 << "Private script error: Setting import function failed. (Class "
82 "name = "
83 << scriptClassName.utf8().data() << ")";
85 } 84 }
86 } 85 }
87 } 86 }
88 87
89 v8::Local<v8::Script> script; 88 v8::Local<v8::Script> script;
90 if (!v8Call(V8ScriptRunner::compileScript( 89 if (!v8Call(V8ScriptRunner::compileScript(
91 v8String(isolate, sourceString), fileName, String(), 90 v8String(isolate, sourceString), fileName, String(),
92 TextPosition::minimumPosition(), isolate, nullptr, nullptr, 91 TextPosition::minimumPosition(), isolate, nullptr, nullptr,
93 nullptr, NotSharableCrossOrigin), 92 nullptr, NotSharableCrossOrigin),
94 script, block)) { 93 script, block)) {
95 fprintf(stderr, "Private script error: Compile failed. (Class name = %s)\n",
96 scriptClassName.utf8().data());
97 dumpV8Message(context, block.Message()); 94 dumpV8Message(context, block.Message());
98 RELEASE_NOTREACHED(); 95 LOG(FATAL) << "Private script error: Compile failed. (Class name = "
96 << scriptClassName.utf8().data() << ")";
99 } 97 }
100 98
101 v8::Local<v8::Value> result; 99 v8::Local<v8::Value> result;
102 if (!v8Call(V8ScriptRunner::runCompiledInternalScript(isolate, script), 100 if (!v8Call(V8ScriptRunner::runCompiledInternalScript(isolate, script),
103 result, block)) { 101 result, block)) {
104 fprintf(stderr,
105 "Private script error: installClass() failed. (Class name = %s)\n",
106 scriptClassName.utf8().data());
107 dumpV8Message(context, block.Message()); 102 dumpV8Message(context, block.Message());
108 RELEASE_NOTREACHED(); 103 LOG(FATAL) << "Private script error: installClass() failed. (Class name = "
104 << scriptClassName.utf8().data() << ")";
109 } 105 }
110 return result; 106 return result;
111 } 107 }
112 108
113 // Private scripts can use privateScriptController.import(bundledResource, 109 // Private scripts can use privateScriptController.import(bundledResource,
114 // compileAndRunScript) to import dependent resources. 110 // compileAndRunScript) to import dependent resources.
115 // |bundledResource| is a string resource name. 111 // |bundledResource| is a string resource name.
116 // |compileAndRunScript| optional boolean representing if the javascript should 112 // |compileAndRunScript| optional boolean representing if the javascript should
117 // be executed. Default: true. 113 // be executed. Default: true.
118 void importFunction(const v8::FunctionCallbackInfo<v8::Value>& args) { 114 void importFunction(const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 String resourceData = 163 String resourceData =
168 loadResourceAsASCIIString(kPrivateScriptSources[index].resourceFile); 164 loadResourceAsASCIIString(kPrivateScriptSources[index].resourceFile);
169 compileAndRunPrivateScript( 165 compileAndRunPrivateScript(
170 scriptState, kPrivateScriptSources[index].scriptClassName, 166 scriptState, kPrivateScriptSources[index].scriptClassName,
171 resourceData.utf8().data(), resourceData.length()); 167 resourceData.utf8().data(), resourceData.length());
172 compiledScriptCount++; 168 compiledScriptCount++;
173 } 169 }
174 } 170 }
175 171
176 if (!compiledScriptCount) { 172 if (!compiledScriptCount) {
177 fprintf(stderr, 173 LOG(FATAL)
178 "Private script error: Target source code was not found. (Class " 174 << "Private script error: Target source code was not found. (Class "
179 "name = %s)\n", 175 "name = "
180 className.utf8().data()); 176 << className.utf8().data() << ")";
181 RELEASE_NOTREACHED();
182 } 177 }
183 } 178 }
184 179
185 static v8::Local<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate) { 180 static v8::Local<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate) {
186 const String className = "PrivateScriptRunner"; 181 const String className = "PrivateScriptRunner";
187 size_t index; 182 size_t index;
188 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is 183 // |kPrivateScriptSources| is defined in V8PrivateScriptSources.h, which is
189 // auto-generated by make_private_script_source.py. 184 // auto-generated by make_private_script_source.py.
190 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { 185 for (index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
191 if (className == kPrivateScriptSources[index].className) 186 if (className == kPrivateScriptSources[index].className)
192 break; 187 break;
193 } 188 }
194 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) { 189 if (index == WTF_ARRAY_LENGTH(kPrivateScriptSources)) {
195 fprintf(stderr, 190 LOG(FATAL)
196 "Private script error: Target source code was not found. (Class " 191 << "Private script error: Target source code was not found. (Class "
197 "name = %s)\n", 192 "name = "
198 className.utf8().data()); 193 << className.utf8().data() << ")";
199 RELEASE_NOTREACHED();
200 } 194 }
201 String resourceData = 195 String resourceData =
202 loadResourceAsASCIIString(kPrivateScriptSources[index].resourceFile); 196 loadResourceAsASCIIString(kPrivateScriptSources[index].resourceFile);
203 return compileAndRunPrivateScript(ScriptState::current(isolate), className, 197 return compileAndRunPrivateScript(ScriptState::current(isolate), className,
204 resourceData.utf8().data(), 198 resourceData.utf8().data(),
205 resourceData.length()); 199 resourceData.length());
206 } 200 }
207 201
208 static v8::Local<v8::Object> classObjectOfPrivateScript( 202 static v8::Local<v8::Object> classObjectOfPrivateScript(
209 ScriptState* scriptState, 203 ScriptState* scriptState,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 v8::Local<v8::Value> initializeFunction; 248 v8::Local<v8::Value> initializeFunction;
255 if (classObject->Get(scriptState->context(), v8String(isolate, "initialize")) 249 if (classObject->Get(scriptState->context(), v8String(isolate, "initialize"))
256 .ToLocal(&initializeFunction) && 250 .ToLocal(&initializeFunction) &&
257 initializeFunction->IsFunction()) { 251 initializeFunction->IsFunction()) {
258 v8::TryCatch block(isolate); 252 v8::TryCatch block(isolate);
259 v8::Local<v8::Value> result; 253 v8::Local<v8::Value> result;
260 if (!V8ScriptRunner::callInternalFunction( 254 if (!V8ScriptRunner::callInternalFunction(
261 v8::Local<v8::Function>::Cast(initializeFunction), holder, 0, 0, 255 v8::Local<v8::Function>::Cast(initializeFunction), holder, 0, 0,
262 isolate) 256 isolate)
263 .ToLocal(&result)) { 257 .ToLocal(&result)) {
264 fprintf(stderr,
265 "Private script error: Object constructor threw an exception.\n");
266 dumpV8Message(context, block.Message()); 258 dumpV8Message(context, block.Message());
267 RELEASE_NOTREACHED(); 259 LOG(FATAL)
260 << "Private script error: Object constructor threw an exception.";
268 } 261 }
269 } 262 }
270 263
271 // Inject the prototype object of the private script into the prototype chain 264 // Inject the prototype object of the private script into the prototype chain
272 // of the holder object. This is necessary to let the holder object use 265 // of the holder object. This is necessary to let the holder object use
273 // properties defined on the prototype object of the private script. (e.g., if 266 // properties defined on the prototype object of the private script. (e.g., if
274 // the prototype object has |foo|, the holder object should be able to use it 267 // the prototype object has |foo|, the holder object should be able to use it
275 // with |this.foo|.) 268 // with |this.foo|.)
276 if (classObject->GetPrototype() != holderObject->GetPrototype()) { 269 if (classObject->GetPrototype() != holderObject->GetPrototype()) {
277 if (!v8CallBoolean( 270 if (!v8CallBoolean(
278 classObject->SetPrototype(context, holderObject->GetPrototype()))) { 271 classObject->SetPrototype(context, holderObject->GetPrototype()))) {
279 fprintf(stderr, "Private script error: SetPrototype failed.\n");
280 dumpV8Message(context, block.Message()); 272 dumpV8Message(context, block.Message());
281 RELEASE_NOTREACHED(); 273 LOG(FATAL) << "Private script error: SetPrototype failed.";
282 } 274 }
283 } 275 }
284 if (!v8CallBoolean(holderObject->SetPrototype(context, classObject))) { 276 if (!v8CallBoolean(holderObject->SetPrototype(context, classObject))) {
285 fprintf(stderr, "Private script error: SetPrototype failed.\n");
286 dumpV8Message(context, block.Message()); 277 dumpV8Message(context, block.Message());
287 RELEASE_NOTREACHED(); 278 LOG(FATAL) << "Private script error: SetPrototype failed.";
288 } 279 }
289 280
290 privateIsInitialized.set(context, holderObject, v8Boolean(true, isolate)); 281 privateIsInitialized.set(context, holderObject, v8Boolean(true, isolate));
291 } 282 }
292 283
293 v8::Local<v8::Value> PrivateScriptRunner::installClassIfNeeded( 284 v8::Local<v8::Value> PrivateScriptRunner::installClassIfNeeded(
294 Document* document, 285 Document* document,
295 String className) { 286 String className) {
296 if (!document->contextDocument()->frame()) 287 if (!document->contextDocument()->frame())
297 return v8::Local<v8::Value>(); 288 return v8::Local<v8::Value>();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (exceptionName == "RangeError" && 346 if (exceptionName == "RangeError" &&
356 messageString.contains("Maximum call stack size exceeded")) { 347 messageString.contains("Maximum call stack size exceeded")) {
357 ScriptState::Scope scope(scriptStateInUserScript); 348 ScriptState::Scope scope(scriptStateInUserScript);
358 ExceptionState exceptionState(errorContext, propertyName, interfaceName, 349 ExceptionState exceptionState(errorContext, propertyName, interfaceName,
359 scriptStateInUserScript->context()->Global(), 350 scriptStateInUserScript->context()->Global(),
360 scriptStateInUserScript->isolate()); 351 scriptStateInUserScript->isolate());
361 exceptionState.throwDOMException(V8RangeError, messageString); 352 exceptionState.throwDOMException(V8RangeError, messageString);
362 return; 353 return;
363 } 354 }
364 355
365 fprintf(stderr, "Private script error: %s was thrown.\n",
366 exceptionName.utf8().data());
367 dumpV8Message(context, tryCatchMessage); 356 dumpV8Message(context, tryCatchMessage);
368 RELEASE_NOTREACHED(); 357 LOG(FATAL) << "Private script error: " << exceptionName.utf8().data()
358 << " was thrown.";
369 } 359 }
370 360
371 } // namespace 361 } // namespace
372 362
373 v8::Local<v8::Value> PrivateScriptRunner::runDOMAttributeGetter( 363 v8::Local<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(
374 ScriptState* scriptState, 364 ScriptState* scriptState,
375 ScriptState* scriptStateInUserScript, 365 ScriptState* scriptStateInUserScript,
376 const char* className, 366 const char* className,
377 const char* attributeName, 367 const char* attributeName,
378 v8::Local<v8::Value> holder) { 368 v8::Local<v8::Value> holder) {
379 v8::Isolate* isolate = scriptState->isolate(); 369 v8::Isolate* isolate = scriptState->isolate();
380 v8::Local<v8::Object> classObject = 370 v8::Local<v8::Object> classObject =
381 classObjectOfPrivateScript(scriptState, className); 371 classObjectOfPrivateScript(scriptState, className);
382 v8::Local<v8::Value> descriptor; 372 v8::Local<v8::Value> descriptor;
383 if (!classObject 373 if (!classObject
384 ->GetOwnPropertyDescriptor(scriptState->context(), 374 ->GetOwnPropertyDescriptor(scriptState->context(),
385 v8String(isolate, attributeName)) 375 v8String(isolate, attributeName))
386 .ToLocal(&descriptor) || 376 .ToLocal(&descriptor) ||
387 !descriptor->IsObject()) { 377 !descriptor->IsObject()) {
388 fprintf(stderr, 378 LOG(FATAL)
389 "Private script error: Target DOM attribute getter was not found. " 379 << "Private script error: Target DOM attribute getter was not found. "
390 "(Class name = %s, Attribute name = %s)\n", 380 "(Class name = "
391 className, attributeName); 381 << className << ", Attribute name = " << attributeName << ")";
392 RELEASE_NOTREACHED();
393 } 382 }
394 v8::Local<v8::Value> getter; 383 v8::Local<v8::Value> getter;
395 if (!v8::Local<v8::Object>::Cast(descriptor) 384 if (!v8::Local<v8::Object>::Cast(descriptor)
396 ->Get(scriptState->context(), v8String(isolate, "get")) 385 ->Get(scriptState->context(), v8String(isolate, "get"))
397 .ToLocal(&getter) || 386 .ToLocal(&getter) ||
398 !getter->IsFunction()) { 387 !getter->IsFunction()) {
399 fprintf(stderr, 388 LOG(FATAL)
400 "Private script error: Target DOM attribute getter was not found. " 389 << "Private script error: Target DOM attribute getter was not found. "
401 "(Class name = %s, Attribute name = %s)\n", 390 "(Class name = "
402 className, attributeName); 391 << className << ", Attribute name = " << attributeName << ")";
403 RELEASE_NOTREACHED();
404 } 392 }
405 initializeHolderIfNeeded(scriptState, classObject, holder); 393 initializeHolderIfNeeded(scriptState, classObject, holder);
406 v8::TryCatch block(isolate); 394 v8::TryCatch block(isolate);
407 v8::Local<v8::Value> result; 395 v8::Local<v8::Value> result;
408 if (!V8ScriptRunner::callInternalFunction( 396 if (!V8ScriptRunner::callInternalFunction(
409 v8::Local<v8::Function>::Cast(getter), holder, 0, 0, isolate) 397 v8::Local<v8::Function>::Cast(getter), holder, 0, 0, isolate)
410 .ToLocal(&result)) { 398 .ToLocal(&result)) {
411 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, 399 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript,
412 ExceptionState::GetterContext, 400 ExceptionState::GetterContext,
413 attributeName, className); 401 attributeName, className);
(...skipping 12 matching lines...) Expand all
426 v8::Local<v8::Value> v8Value) { 414 v8::Local<v8::Value> v8Value) {
427 v8::Isolate* isolate = scriptState->isolate(); 415 v8::Isolate* isolate = scriptState->isolate();
428 v8::Local<v8::Object> classObject = 416 v8::Local<v8::Object> classObject =
429 classObjectOfPrivateScript(scriptState, className); 417 classObjectOfPrivateScript(scriptState, className);
430 v8::Local<v8::Value> descriptor; 418 v8::Local<v8::Value> descriptor;
431 if (!classObject 419 if (!classObject
432 ->GetOwnPropertyDescriptor(scriptState->context(), 420 ->GetOwnPropertyDescriptor(scriptState->context(),
433 v8String(isolate, attributeName)) 421 v8String(isolate, attributeName))
434 .ToLocal(&descriptor) || 422 .ToLocal(&descriptor) ||
435 !descriptor->IsObject()) { 423 !descriptor->IsObject()) {
436 fprintf(stderr, 424 LOG(FATAL)
437 "Private script error: Target DOM attribute setter was not found. " 425 << "Private script error: Target DOM attribute setter was not found. "
438 "(Class name = %s, Attribute name = %s)\n", 426 "(Class name = "
439 className, attributeName); 427 << className << ", Attribute name = " << attributeName << ")";
440 RELEASE_NOTREACHED();
441 } 428 }
442 v8::Local<v8::Value> setter; 429 v8::Local<v8::Value> setter;
443 if (!v8::Local<v8::Object>::Cast(descriptor) 430 if (!v8::Local<v8::Object>::Cast(descriptor)
444 ->Get(scriptState->context(), v8String(isolate, "set")) 431 ->Get(scriptState->context(), v8String(isolate, "set"))
445 .ToLocal(&setter) || 432 .ToLocal(&setter) ||
446 !setter->IsFunction()) { 433 !setter->IsFunction()) {
447 fprintf(stderr, 434 LOG(FATAL) << "Private script error: Target DOM attribute setter was not "
448 "Private script error: Target DOM attribute setter was not found. " 435 "found. (Class name = "
449 "(Class name = %s, Attribute name = %s)\n", 436 << className << ", Attribute name = " << attributeName << ")";
450 className, attributeName);
451 RELEASE_NOTREACHED();
452 } 437 }
453 initializeHolderIfNeeded(scriptState, classObject, holder); 438 initializeHolderIfNeeded(scriptState, classObject, holder);
454 v8::Local<v8::Value> argv[] = {v8Value}; 439 v8::Local<v8::Value> argv[] = {v8Value};
455 v8::TryCatch block(isolate); 440 v8::TryCatch block(isolate);
456 v8::Local<v8::Value> result; 441 v8::Local<v8::Value> result;
457 if (!V8ScriptRunner::callInternalFunction( 442 if (!V8ScriptRunner::callInternalFunction(
458 v8::Local<v8::Function>::Cast(setter), holder, 443 v8::Local<v8::Function>::Cast(setter), holder,
459 WTF_ARRAY_LENGTH(argv), argv, isolate) 444 WTF_ARRAY_LENGTH(argv), argv, isolate)
460 .ToLocal(&result)) { 445 .ToLocal(&result)) {
461 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript, 446 rethrowExceptionInPrivateScript(isolate, block, scriptStateInUserScript,
(...skipping 14 matching lines...) Expand all
476 int argc, 461 int argc,
477 v8::Local<v8::Value> argv[]) { 462 v8::Local<v8::Value> argv[]) {
478 v8::Local<v8::Object> classObject = 463 v8::Local<v8::Object> classObject =
479 classObjectOfPrivateScript(scriptState, className); 464 classObjectOfPrivateScript(scriptState, className);
480 v8::Local<v8::Value> method; 465 v8::Local<v8::Value> method;
481 if (!classObject 466 if (!classObject
482 ->Get(scriptState->context(), 467 ->Get(scriptState->context(),
483 v8String(scriptState->isolate(), methodName)) 468 v8String(scriptState->isolate(), methodName))
484 .ToLocal(&method) || 469 .ToLocal(&method) ||
485 !method->IsFunction()) { 470 !method->IsFunction()) {
486 fprintf(stderr, 471 LOG(FATAL)
487 "Private script error: Target DOM method was not found. (Class " 472 << "Private script error: Target DOM method was not found. (Class "
488 "name = %s, Method name = %s)\n", 473 "name = "
489 className, methodName); 474 << className << ", Method name = " << methodName << ")";
490 RELEASE_NOTREACHED();
491 } 475 }
492 initializeHolderIfNeeded(scriptState, classObject, holder); 476 initializeHolderIfNeeded(scriptState, classObject, holder);
493 v8::TryCatch block(scriptState->isolate()); 477 v8::TryCatch block(scriptState->isolate());
494 v8::Local<v8::Value> result; 478 v8::Local<v8::Value> result;
495 if (!V8ScriptRunner::callInternalFunction( 479 if (!V8ScriptRunner::callInternalFunction(
496 v8::Local<v8::Function>::Cast(method), holder, argc, argv, 480 v8::Local<v8::Function>::Cast(method), holder, argc, argv,
497 scriptState->isolate()) 481 scriptState->isolate())
498 .ToLocal(&result)) { 482 .ToLocal(&result)) {
499 rethrowExceptionInPrivateScript( 483 rethrowExceptionInPrivateScript(
500 scriptState->isolate(), block, scriptStateInUserScript, 484 scriptState->isolate(), block, scriptStateInUserScript,
501 ExceptionState::ExecutionContext, methodName, className); 485 ExceptionState::ExecutionContext, methodName, className);
502 block.ReThrow(); 486 block.ReThrow();
503 return v8::Local<v8::Value>(); 487 return v8::Local<v8::Value>();
504 } 488 }
505 return result; 489 return result;
506 } 490 }
507 491
508 } // namespace blink 492 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/DOMWindow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698