Changeset 57134 in webkit
- Timestamp:
- Apr 6, 2010 1:46:23 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 20 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r57116 r57134 1 2010-04-06 Yury Semikhatsky <yurys@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Test that exception which occurs in onerror handler is reported to the Worker object. 6 7 https://bugs.webkit.org/show_bug.cgi?id=36375 8 9 * fast/workers/worker-script-error-expected.txt: 10 * fast/workers/worker-script-error.html: 11 1 12 2010-04-05 Dimitri Glazkov <dglazkov@chromium.org> 2 13 -
trunk/LayoutTests/fast/workers/worker-script-error-expected.txt
r57082 r57134 5 5 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1. 6 6 PASS: event listener invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1. 7 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: bar' at line 3. 7 8 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7. 8 9 PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7. -
trunk/LayoutTests/fast/workers/worker-script-error.html
r57082 r57134 82 82 try { 83 83 var worker = new Worker("resources/worker-error-in-handling-script-error.js"); 84 var errorCount = 0; 84 85 worker.onerror = function(evt) { 85 86 log("PASS: onerror invoked for a script that has script error '" + evt.message + "' at line " + evt.lineno + "."); 86 runNextTest(); 87 ++errorCount; 88 // Second error happens in the onerror handler. Run next test only when it's reported. 89 if (errorCount == 2) 90 runNextTest(); 87 91 return false; 88 92 } -
trunk/WebCore/Android.jscbindings.mk
r57082 r57134 158 158 bindings/js/JSWorkerContextBase.cpp \ 159 159 bindings/js/JSWorkerContextCustom.cpp \ 160 bindings/js/JSWorkerContextErrorHandler.cpp \ 160 161 bindings/js/JSWorkerCustom.cpp \ 161 162 bindings/js/JSXMLHttpRequestConstructor.cpp \ -
trunk/WebCore/ChangeLog
r57133 r57134 1 2010-04-06 Yury Semikhatsky <yurys@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Refactored error reporting mechanizm on Worker Global Objects. 6 Unlike other event listeners which accept single argument(Event) 7 onerror handler on worker global object should be a function 8 accepting three arguments. This error reporting was implementedas 9 EventListener::reportError method which had custom implementations 10 for v8 and JSC. This patch removes EventListener::reportError and 11 moves its functionality into custom bindings(V8WorkerContextErrorHandler 12 and JSWorkerContextErrorHandler) that implement EventListener inerface 13 for the onerror handler. 14 15 This patch also makes uncaught exceptions that happen in the onerror 16 listener be reported to the Worker's onerror handler. 17 18 https://bugs.webkit.org/show_bug.cgi?id=36375 19 20 * Android.jscbindings.mk: 21 * GNUmakefile.am: 22 * WebCore.gypi: 23 * WebCore.pro: 24 * WebCore.vcproj/WebCore.vcproj: 25 * WebCore.xcodeproj/project.pbxproj: 26 * bindings/js/JSBindingsAllInOne.cpp: 27 * bindings/js/JSEventListener.cpp: 28 * bindings/js/JSEventListener.h: 29 * bindings/js/JSWorkerContextErrorHandler.cpp: Added. 30 (WebCore::JSWorkerContextErrorHandler::JSWorkerContextErrorHandler): 31 (WebCore::JSWorkerContextErrorHandler::~JSWorkerContextErrorHandler): 32 (WebCore::JSWorkerContextErrorHandler::handleEvent): 33 * bindings/js/JSWorkerContextErrorHandler.h: Added. 34 (WebCore::JSWorkerContextErrorHandler::create): 35 (WebCore::createJSWorkerContextErrorHandler): 36 * bindings/scripts/CodeGeneratorJS.pm: 37 * bindings/scripts/CodeGeneratorV8.pm: 38 * bindings/v8/V8WorkerContextErrorHandler.cpp: Added. 39 (WebCore::V8WorkerContextErrorHandler::V8WorkerContextErrorHandler): 40 (WebCore::V8WorkerContextErrorHandler::callListenerFunction): 41 * bindings/v8/V8WorkerContextErrorHandler.h: Added. 42 (WebCore::V8WorkerContextErrorHandler::create): 43 * bindings/v8/V8WorkerContextEventListener.cpp: 44 * bindings/v8/V8WorkerContextEventListener.h: 45 * dom/EventListener.h: 46 * workers/WorkerContext.cpp: 47 (WebCore::WorkerContext::WorkerContext): 48 (WebCore::WorkerContext::reportException): 49 * workers/WorkerContext.h: 50 1 51 2010-04-06 Pavel Feldman <pfeldman@chromium.org> 2 52 -
trunk/WebCore/GNUmakefile.am
r57082 r57134 474 474 WebCore/bindings/js/JSWebKitPointConstructor.cpp \ 475 475 WebCore/bindings/js/JSWebKitPointConstructor.h \ 476 WebCore/bindings/js/JSWorkerContextErrorHandler.cpp \ 477 WebCore/bindings/js/JSWorkerContextErrorHandler.h \ 476 478 WebCore/bindings/js/JSXMLHttpRequestConstructor.cpp \ 477 479 WebCore/bindings/js/JSXMLHttpRequestConstructor.h \ -
trunk/WebCore/WebCore.gypi
r57082 r57134 625 625 'bindings/js/JSWorkerContextBase.h', 626 626 'bindings/js/JSWorkerContextCustom.cpp', 627 'bindings/js/JSWorkerContextErrorHandler.cpp', 628 'bindings/js/JSWorkerContextErrorHandler.h', 627 629 'bindings/js/JSWorkerCustom.cpp', 628 630 'bindings/js/JSXMLHttpRequestConstructor.cpp', … … 887 889 'bindings/v8/V8Utilities.cpp', 888 890 'bindings/v8/V8Utilities.h', 891 'bindings/v8/V8WorkerContextErrorHandler.cpp', 892 'bindings/v8/V8WorkerContextErrorHandler.h', 889 893 'bindings/v8/V8WorkerContextEventListener.cpp', 890 894 'bindings/v8/V8WorkerContextEventListener.h', -
trunk/WebCore/WebCore.pro
r57082 r57134 364 364 bindings/js/JSPluginElementFunctions.cpp \ 365 365 bindings/js/JSPopStateEventCustom.cpp \ 366 bindings/js/JSWorkerContextErrorHandler.cpp \ 366 367 bindings/js/JavaScriptProfile.h \ 367 368 bindings/js/JavaScriptProfileNode.h \ … … 1072 1073 bindings/js/JSWorkerConstructor.h \ 1073 1074 bindings/js/JSWorkerContextBase.h \ 1074 bindings/js/JSWorkerContext Base.h \1075 bindings/js/JSWorkerContextErrorHandler.h \ 1075 1076 bindings/js/JSXMLHttpRequestConstructor.h \ 1076 1077 bindings/js/JSXSLTProcessorConstructor.h \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r57082 r57134 40065 40065 </File> 40066 40066 <File 40067 RelativePath="..\bindings\js\JSWorkerContextErrorHandler.cpp" > 40068 <FileConfiguration 40069 Name="Debug|Win32" 40070 ExcludedFromBuild="true" 40071 > 40072 <Tool 40073 Name="VCCLCompilerTool" 40074 /> 40075 </FileConfiguration> 40076 <FileConfiguration 40077 Name="Release|Win32" 40078 ExcludedFromBuild="true" 40079 > 40080 <Tool 40081 Name="VCCLCompilerTool" 40082 /> 40083 </FileConfiguration> 40084 <FileConfiguration 40085 Name="Debug_Internal|Win32" 40086 ExcludedFromBuild="true" 40087 > 40088 <Tool 40089 Name="VCCLCompilerTool" 40090 /> 40091 </FileConfiguration> 40092 <FileConfiguration 40093 Name="Debug_Cairo|Win32" 40094 ExcludedFromBuild="true" 40095 > 40096 <Tool 40097 Name="VCCLCompilerTool" 40098 /> 40099 </FileConfiguration> 40100 <FileConfiguration 40101 Name="Release_Cairo|Win32" 40102 ExcludedFromBuild="true" 40103 > 40104 <Tool 40105 Name="VCCLCompilerTool" 40106 /> 40107 </FileConfiguration> 40108 <FileConfiguration 40109 Name="Debug_All|Win32" 40110 ExcludedFromBuild="true" 40111 > 40112 <Tool 40113 Name="VCCLCompilerTool" 40114 /> 40115 </FileConfiguration> 40116 </File> 40117 <File 40118 RelativePath="..\bindings\js\JSWorkerContextErrorHandler.h" 40119 > 40120 </File> 40121 <File 40067 40122 RelativePath="..\bindings\js\JSXMLHttpRequestConstructor.cpp" 40068 40123 > -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r57095 r57134 4894 4894 F3644B001119805900E0D537 /* InjectedScript.h in Headers */ = {isa = PBXBuildFile; fileRef = F3644AFE1119805900E0D537 /* InjectedScript.h */; }; 4895 4895 F375CC071150D300008DDB81 /* InspectorWorkerResource.h in Headers */ = {isa = PBXBuildFile; fileRef = F375CC061150D300008DDB81 /* InspectorWorkerResource.h */; }; 4896 F3D461481161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */; }; 4897 F3D461491161D53200CA0D09 /* JSWorkerContextErrorHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */; }; 4896 4898 F4EAF4AE10C742B1009100D3 /* OpenTypeSanitizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F4EAF4AC10C742B1009100D3 /* OpenTypeSanitizer.cpp */; }; 4897 4899 F4EAF4AF10C742B1009100D3 /* OpenTypeSanitizer.h in Headers */ = {isa = PBXBuildFile; fileRef = F4EAF4AD10C742B1009100D3 /* OpenTypeSanitizer.h */; }; … … 10265 10267 F3644AFE1119805900E0D537 /* InjectedScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedScript.h; sourceTree = "<group>"; }; 10266 10268 F375CC061150D300008DDB81 /* InspectorWorkerResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorWorkerResource.h; sourceTree = "<group>"; }; 10269 F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerContextErrorHandler.cpp; sourceTree = "<group>"; }; 10270 F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerContextErrorHandler.h; sourceTree = "<group>"; }; 10267 10271 F4EAF4AC10C742B1009100D3 /* OpenTypeSanitizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenTypeSanitizer.cpp; path = opentype/OpenTypeSanitizer.cpp; sourceTree = "<group>"; }; 10268 10272 F4EAF4AD10C742B1009100D3 /* OpenTypeSanitizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenTypeSanitizer.h; path = opentype/OpenTypeSanitizer.h; sourceTree = "<group>"; }; … … 14854 14858 E1C36D320EB0A094007410BC /* JSWorkerContextBase.cpp */, 14855 14859 E1C36D330EB0A094007410BC /* JSWorkerContextBase.h */, 14860 F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */, 14861 F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */, 14856 14862 BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */, 14857 14863 BCA378BB0D15F64200B793D6 /* ScheduledAction.h */, … … 17956 17962 E18256900EF2B02D00933242 /* JSWorkerContext.h in Headers */, 17957 17963 E1C36D350EB0A094007410BC /* JSWorkerContextBase.h in Headers */, 17964 F3D461491161D53200CA0D09 /* JSWorkerContextErrorHandler.h in Headers */, 17958 17965 E1C362EF0EAF2AA9007410BC /* JSWorkerLocation.h in Headers */, 17959 17966 E1271A580EEECDE400F61213 /* JSWorkerNavigator.h in Headers */, … … 20271 20278 E1C36D340EB0A094007410BC /* JSWorkerContextBase.cpp in Sources */, 20272 20279 E18258AC0EF3CD7000933242 /* JSWorkerContextCustom.cpp in Sources */, 20280 F3D461481161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp in Sources */, 20273 20281 E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */, 20274 20282 E1C362F00EAF2AA9007410BC /* JSWorkerLocation.cpp in Sources */, -
trunk/WebCore/bindings/js/JSBindingsAllInOne.cpp
r54777 r57134 128 128 #include "JSWorkerContextBase.cpp" 129 129 #include "JSWorkerContextCustom.cpp" 130 #include "JSWorkerContextErrorHandler.cpp" 130 131 #include "JSWorkerCustom.cpp" 131 132 #include "JSXMLHttpRequestConstructor.cpp" -
trunk/WebCore/bindings/js/JSEventListener.cpp
r57082 r57134 134 134 } 135 135 136 bool JSEventListener::reportError(ScriptExecutionContext* context, const String& message, const String& url, int lineNumber)137 {138 JSLock lock(SilenceAssertionsOnly);139 140 JSObject* jsFunction = this->jsFunction(context);141 if (!jsFunction)142 return false;143 144 JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, m_isolatedWorld.get());145 ExecState* exec = globalObject->globalExec();146 147 CallData callData;148 CallType callType = jsFunction->getCallData(callData);149 150 if (callType == CallTypeNone)151 return false;152 153 MarkedArgumentBuffer args;154 args.append(jsString(exec, message));155 args.append(jsString(exec, url));156 args.append(jsNumber(exec, lineNumber));157 158 JSGlobalData* globalData = globalObject->globalData();159 DynamicGlobalObjectScope globalObjectScope(exec, globalData->dynamicGlobalObject ? globalData->dynamicGlobalObject : globalObject);160 161 JSValue thisValue = globalObject->toThisObject(exec);162 163 globalData->timeoutChecker.start();164 JSValue returnValue = JSC::call(exec, jsFunction, callType, callData, thisValue, args);165 globalData->timeoutChecker.stop();166 167 // If an error occurs while handling the script error, it should be bubbled up.168 if (exec->hadException()) {169 exec->clearException();170 return false;171 }172 173 bool bubbleEvent;174 return returnValue.getBoolean(bubbleEvent) && !bubbleEvent;175 }176 177 136 bool JSEventListener::virtualisAttribute() const 178 137 { -
trunk/WebCore/bindings/js/JSEventListener.h
r57082 r57134 61 61 virtual void invalidateJSFunction(JSC::JSObject*); 62 62 virtual void handleEvent(ScriptExecutionContext*, Event*); 63 virtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber);64 63 virtual bool virtualisAttribute() const; 65 64 -
trunk/WebCore/bindings/js/JSWorkerContextErrorHandler.h
r57133 r57134 1 1 /* 2 * Copyright (C) 20 06, 2007, 2008, 2009Google Inc. All rights reserved.2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 */ 30 30 31 #ifndef V8WorkerContextEventListener_h32 #define V8WorkerContextEventListener_h31 #ifndef JSWorkerContextErrorHandler_h 32 #define JSWorkerContextErrorHandler_h 33 33 34 #if ENABLE(WORKERS) 35 36 #include "V8CustomEventListener.h" 37 #include <v8.h> 38 #include <wtf/PassRefPtr.h> 34 #include "JSEventListener.h" 39 35 40 36 namespace WebCore { 41 37 42 class Event; 43 class WorkerContextExecutionProxy; 38 class JSWorkerContextErrorHandler : public JSEventListener { 39 public: 40 static PassRefPtr<JSWorkerContextErrorHandler> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld) 41 { 42 return adoptRef(new JSWorkerContextErrorHandler(listener, wrapper, isAttribute, isolatedWorld)); 43 } 44 44 45 class V8WorkerContextEventListener : public V8EventListener { 46 public: 47 static PassRefPtr<V8WorkerContextEventListener> create(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext) 48 { 49 return adoptRef(new V8WorkerContextEventListener(listener, isInline, worldContext)); 50 } 45 virtual ~JSWorkerContextErrorHandler(); 51 46 52 virtual void handleEvent(ScriptExecutionContext*, Event*); 53 virtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber); 47 private: 48 JSWorkerContextErrorHandler(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld); 49 virtual void handleEvent(ScriptExecutionContext*, Event*); 50 }; 54 51 55 private: 56 V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext); 52 // Creates a JS EventListener for "onerror" event handler in worker context. It has custom implementation because 53 // unlike other event listeners it accepts three parameters. 54 inline PassRefPtr<JSWorkerContextErrorHandler> createJSWorkerContextErrorHandler(JSC::ExecState* exec, JSC::JSValue listener, JSC::JSObject* wrapper) 55 { 56 if (!listener.isObject()) 57 return 0; 57 58 58 virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); 59 v8::Local<v8::Object> getReceiverObject(ScriptExecutionContext*, Event*); 60 }; 59 return JSWorkerContextErrorHandler::create(asObject(listener), wrapper, true, currentWorld(exec)); 60 } 61 61 62 62 } // namespace WebCore 63 63 64 #endif // WORKERS 65 66 #endif // V8WorkerContextEventListener_h 64 #endif // JSWorkerContextErrorHandler_h -
trunk/WebCore/bindings/scripts/CodeGeneratorJS.pm
r57082 r57134 1485 1485 push(@implContent, " UNUSED_PARAM(exec);\n"); 1486 1486 push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(static_cast<$className*>(thisObject)->impl());\n"); 1487 push(@implContent, " imp->set$implSetterFunctionName(createJSAttributeEventListener(exec, value, thisObject));\n"); 1487 if ($interfaceName eq "WorkerContext" and $name eq "onerror") { 1488 $implIncludes{"JSWorkerContextErrorHandler.h"} = 1; 1489 push(@implContent, " imp->set$implSetterFunctionName(createJSWorkerContextErrorHandler(exec, value, thisObject));\n"); 1490 } else { 1491 push(@implContent, " imp->set$implSetterFunctionName(createJSAttributeEventListener(exec, value, thisObject));\n"); 1492 } 1488 1493 } elsif ($attribute->signature->type =~ /Constructor$/) { 1489 1494 my $constructorType = $attribute->signature->type; -
trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm
r57082 r57134 912 912 $implIncludes{"V8AbstractEventListener.h"} = 1; 913 913 push(@implContentDecls, " transferHiddenDependency(info.Holder(), imp->$attrName(), value, V8${interfaceName}::eventListenerCacheIndex);\n"); 914 push(@implContentDecls, " imp->set$implSetterFunctionName(V8DOMWrapper::getEventListener(value, true, ListenerFindOrCreate)"); 914 if ($interfaceName eq "WorkerContext" and $attribute->signature->name eq "onerror") { 915 $implIncludes{"V8EventListenerList.h"} = 1; 916 $implIncludes{"V8WorkerContextErrorHandler.h"} = 1; 917 push(@implContentDecls, " imp->set$implSetterFunctionName(V8EventListenerList::findOrCreateWrapper<V8WorkerContextErrorHandler>(value, true)"); 918 } else { 919 push(@implContentDecls, " imp->set$implSetterFunctionName(V8DOMWrapper::getEventListener(value, true, ListenerFindOrCreate)"); 920 } 915 921 } else { 916 922 push(@implContentDecls, " imp->set$implSetterFunctionName($result"); -
trunk/WebCore/bindings/v8/V8WorkerContextErrorHandler.cpp
r57133 r57134 1 1 /* 2 * Copyright (C) 20 06, 2007, 2008, 2009Google Inc. All rights reserved.2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 */ 30 30 31 #ifndef V8WorkerContextEventListener_h 32 #define V8WorkerContextEventListener_h 31 #include "config.h" 33 32 34 33 #if ENABLE(WORKERS) 35 34 36 #include "V8CustomEventListener.h" 37 #include <v8.h> 38 #include <wtf/PassRefPtr.h> 35 #include "V8WorkerContextErrorHandler.h" 36 37 #include "ErrorEvent.h" 38 #include "V8Binding.h" 39 39 40 40 namespace WebCore { 41 41 42 class Event; 43 class WorkerContextExecutionProxy; 42 V8WorkerContextErrorHandler::V8WorkerContextErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext) 43 : V8WorkerContextEventListener(listener, isInline, worldContext) 44 { 45 } 44 46 45 class V8WorkerContextEventListener : public V8EventListener { 46 public: 47 static PassRefPtr<V8WorkerContextEventListener> create(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext)48 {49 return adoptRef(new V8WorkerContextEventListener(listener, isInline, worldContext));50 }51 52 v irtual void handleEvent(ScriptExecutionContext*, Event*);53 v irtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber);54 55 private:56 V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext);57 58 virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);59 v8::Local<v8::Object> getReceiverObject(ScriptExecutionContext*, Event*);60 }; 47 v8::Local<v8::Value> V8WorkerContextErrorHandler::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) 48 { 49 ASSERT(event->isErrorEvent()); 50 v8::Local<v8::Object> listener = getListenerObject(context); 51 v8::Local<v8::Value> returnValue; 52 if (!listener.IsEmpty() && listener->IsFunction()) { 53 ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event); 54 v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener); 55 v8::Local<v8::Object> thisValue = v8::Context::GetCurrent()->Global(); 56 v8::Handle<v8::Value> parameters[3] = { v8String(errorEvent->message()), v8String(errorEvent->filename()), v8::Integer::New(errorEvent->lineno()) }; 57 returnValue = callFunction->Call(thisValue, 3, parameters); 58 if (!returnValue.IsEmpty() && returnValue->IsBoolean() && !returnValue->BooleanValue()) 59 event->preventDefault(); 60 } 61 return returnValue; 62 } 61 63 62 64 } // namespace WebCore 63 65 64 66 #endif // WORKERS 65 66 #endif // V8WorkerContextEventListener_h -
trunk/WebCore/bindings/v8/V8WorkerContextErrorHandler.h
r57133 r57134 1 1 /* 2 * Copyright (C) 20 06, 2007, 2008, 2009Google Inc. All rights reserved.2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 */ 30 30 31 #ifndef V8WorkerContextE ventListener_h32 #define V8WorkerContextE ventListener_h31 #ifndef V8WorkerContextErrorHandler_h 32 #define V8WorkerContextErrorHandler_h 33 33 34 34 #if ENABLE(WORKERS) 35 35 36 #include "V8 CustomEventListener.h"36 #include "V8WorkerContextEventListener.h" 37 37 #include <v8.h> 38 38 #include <wtf/PassRefPtr.h> … … 40 40 namespace WebCore { 41 41 42 class Event; 43 class WorkerContextExecutionProxy; 42 class V8WorkerContextErrorHandler : public V8WorkerContextEventListener { 43 public: 44 static PassRefPtr<V8WorkerContextErrorHandler> create(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext) 45 { 46 return adoptRef(new V8WorkerContextErrorHandler(listener, isInline, worldContext)); 47 } 44 48 45 class V8WorkerContextEventListener : public V8EventListener { 46 public: 47 static PassRefPtr<V8WorkerContextEventListener> create(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext) 48 { 49 return adoptRef(new V8WorkerContextEventListener(listener, isInline, worldContext)); 50 } 49 private: 50 V8WorkerContextErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext); 51 51 52 virtual void handleEvent(ScriptExecutionContext*, Event*); 53 virtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber); 54 55 private: 56 V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext); 57 58 virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); 59 v8::Local<v8::Object> getReceiverObject(ScriptExecutionContext*, Event*); 60 }; 52 virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); 53 }; 61 54 62 55 } // namespace WebCore … … 64 57 #endif // WORKERS 65 58 66 #endif // V8WorkerContextE ventListener_h59 #endif // V8WorkerContextErrorHandler_h -
trunk/WebCore/bindings/v8/V8WorkerContextEventListener.cpp
r57082 r57134 83 83 } 84 84 85 bool V8WorkerContextEventListener::reportError(ScriptExecutionContext* context, const String& message, const String& url, int lineNumber)86 {87 if (!context)88 return false;89 90 // The callback function can clear the event listener and destroy 'this' object. Keep a local reference to it.91 RefPtr<V8AbstractEventListener> protect(this);92 93 v8::HandleScope handleScope;94 95 WorkerContextExecutionProxy* proxy = workerProxy(context);96 if (!proxy)97 return false;98 99 v8::Handle<v8::Context> v8Context = proxy->context();100 if (v8Context.IsEmpty())101 return false;102 103 // Enter the V8 context in which to perform the event handling.104 v8::Context::Scope scope(v8Context);105 106 v8::Local<v8::Object> listener = getListenerObject(context);107 v8::Local<v8::Value> returnValue;108 {109 // Catch exceptions thrown in calling the function so they do not propagate to javascript code that caused the event to fire.110 v8::TryCatch tryCatch;111 tryCatch.SetVerbose(true);112 113 // Call the function.114 if (!listener.IsEmpty() && listener->IsFunction()) {115 v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener);116 v8::Local<v8::Object> thisValue = v8::Context::GetCurrent()->Global();117 118 v8::Handle<v8::Value> parameters[3] = { v8String(message), v8String(url), v8::Integer::New(lineNumber) };119 returnValue = callFunction->Call(thisValue, 3, parameters);120 }121 122 // If an error occurs while handling the script error, it should be bubbled up.123 if (tryCatch.HasCaught()) {124 tryCatch.Reset();125 return false;126 }127 }128 129 // If the function returns false, then the error is handled. Otherwise, the error is not handled.130 bool errorHandled = returnValue->IsBoolean() && !returnValue->BooleanValue();131 132 return errorHandled;133 }134 135 85 v8::Local<v8::Value> V8WorkerContextEventListener::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) 136 86 { -
trunk/WebCore/bindings/v8/V8WorkerContextEventListener.h
r57082 r57134 51 51 52 52 virtual void handleEvent(ScriptExecutionContext*, Event*); 53 virtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber); 53 54 protected: 55 V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext); 54 56 55 57 private: 56 V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext);57 58 58 virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); 59 59 v8::Local<v8::Object> getReceiverObject(ScriptExecutionContext*, Event*); -
trunk/WebCore/dom/EventListener.h
r57082 r57134 47 47 virtual bool operator==(const EventListener&) = 0; 48 48 virtual void handleEvent(ScriptExecutionContext*, Event*) = 0; 49 // Return true to indicate that the error is handled.50 virtual bool reportError(ScriptExecutionContext*, const String& /*message*/, const String& /*url*/, int /*lineNumber*/) { return false; }51 49 virtual bool wasCreatedFromMarkup() const { return false; } 52 50 -
trunk/WebCore/workers/WorkerContext.cpp
r57082 r57134 33 33 34 34 #include "ActiveDOMObject.h" 35 #include "Database.h"36 35 #include "DOMTimer.h" 37 36 #include "DOMWindow.h" 37 #include "Database.h" 38 #include "ErrorEvent.h" 38 39 #include "Event.h" 39 40 #include "EventException.h" … … 65 66 , m_thread(thread) 66 67 , m_closing(false) 68 , m_reportingException(false) 67 69 { 68 70 setSecurityOrigin(SecurityOrigin::create(url)); … … 228 230 { 229 231 bool errorHandled = false; 230 if (onerror()) 231 errorHandled = onerror()->reportError(this, errorMessage, sourceURL, lineNumber); 232 232 if (!m_reportingException) { 233 if (onerror()) { 234 m_reportingException = true; 235 RefPtr<ErrorEvent> errorEvent(ErrorEvent::create(errorMessage, sourceURL, lineNumber)); 236 onerror()->handleEvent(this, errorEvent.get()); 237 errorHandled = errorEvent->defaultPrevented(); 238 m_reportingException = false; 239 } 240 } 233 241 if (!errorHandled) 234 242 thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL); -
trunk/WebCore/workers/WorkerContext.h
r57082 r57134 155 155 #endif 156 156 bool m_closing; 157 bool m_reportingException; 157 158 EventTargetData m_eventTargetData; 158 159 };
Note: See TracChangeset
for help on using the changeset viewer.