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

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

Issue 478623002: Blink-in-JS: Output a correct JS file name and line number when an exception is thrown (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | « 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 "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"
11 #include "bindings/core/v8/V8PerContextData.h" 11 #include "bindings/core/v8/V8PerContextData.h"
12 #include "bindings/core/v8/V8ScriptRunner.h" 12 #include "bindings/core/v8/V8ScriptRunner.h"
13 #include "core/PrivateScriptSources.h" 13 #include "core/PrivateScriptSources.h"
14 #ifndef NDEBUG 14 #ifndef NDEBUG
15 #include "core/PrivateScriptSourcesForTesting.h" 15 #include "core/PrivateScriptSourcesForTesting.h"
16 #endif 16 #endif
17 #include "core/dom/ExceptionCode.h" 17 #include "core/dom/ExceptionCode.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 static void dumpV8Message(v8::Handle<v8::Message> message) 21 static void dumpV8Message(v8::Handle<v8::Message> message)
22 { 22 {
23 if (message.IsEmpty()) 23 if (message.IsEmpty())
24 return; 24 return;
25 25
26 // FIXME: How can we get a resource name when an exception is thrown by DOM attributes/methods 26 // FIXME: GetScriptOrigin() and GetLineNumber() return empty handles
27 // implemented in private scripts? In that case, currently ResourceName() re turns an empty handle. 27 // when they are called at the first time if V8 has a pending exception.
28 // So we need to call twice to get a correct ScriptOrigin and line number.
29 // This is a bug of V8.
Jens Widell 2014/08/15 04:55:29 Is there a bug report?
haraken 2014/08/15 04:57:23 Not yet, I'm writing a fix :)
30 message->GetScriptOrigin();
31 message->GetLineNumber();
32
28 v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName (); 33 v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName ();
29 String fileName = "Unknown JavaScript file"; 34 String fileName = "Unknown JavaScript file";
30 if (!resourceName.IsEmpty() && resourceName->IsString()) 35 if (!resourceName.IsEmpty() && resourceName->IsString())
31 fileName = toCoreString(v8::Handle<v8::String>::Cast(resourceName)); 36 fileName = toCoreString(v8::Handle<v8::String>::Cast(resourceName));
32 int lineNumber = message->GetLineNumber(); 37 int lineNumber = message->GetLineNumber();
33 v8::Handle<v8::String> errorMessage = message->Get(); 38 v8::Handle<v8::String> errorMessage = message->Get();
34 fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, to CoreString(errorMessage).utf8().data()); 39 fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, to CoreString(errorMessage).utf8().data());
35 } 40 }
36 41
37 static void dumpJSError(String exceptionName, v8::Handle<v8::Message> message) 42 static void dumpJSError(String exceptionName, v8::Handle<v8::Message> message)
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (exceptionName == "ReferenceError") { 291 if (exceptionName == "ReferenceError") {
287 exceptionState.throwDOMException(V8ReferenceError, messageString); 292 exceptionState.throwDOMException(V8ReferenceError, messageString);
288 exceptionState.throwIfNeeded(); 293 exceptionState.throwIfNeeded();
289 dumpJSError(exceptionName, tryCatchMessage); 294 dumpJSError(exceptionName, tryCatchMessage);
290 return true; 295 return true;
291 } 296 }
292 return false; 297 return false;
293 } 298 }
294 299
295 } // namespace blink 300 } // 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