Changeset 57134 in webkit


Ignore:
Timestamp:
Apr 6, 2010 1:46:23 AM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-04-06 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Refactored error reporting mechanizm on Worker Global Objects.
Unlike other event listeners which accept single argument(Event)
onerror handler on worker global object should be a function
accepting three arguments. This error reporting was implementedas
EventListener::reportError method which had custom implementations
for v8 and JSC. This patch removes EventListener::reportError and
moves its functionality into custom bindings(V8WorkerContextErrorHandler
and JSWorkerContextErrorHandler) that implement EventListener inerface
for the onerror handler.

This patch also makes uncaught exceptions that happen in the onerror
listener be reported to the Worker's onerror handler.

https://bugs.webkit.org/show_bug.cgi?id=36375

  • Android.jscbindings.mk:
  • GNUmakefile.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSBindingsAllInOne.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventListener.h:
  • bindings/js/JSWorkerContextErrorHandler.cpp: Added. (WebCore::JSWorkerContextErrorHandler::JSWorkerContextErrorHandler): (WebCore::JSWorkerContextErrorHandler::~JSWorkerContextErrorHandler): (WebCore::JSWorkerContextErrorHandler::handleEvent):
  • bindings/js/JSWorkerContextErrorHandler.h: Added. (WebCore::JSWorkerContextErrorHandler::create): (WebCore::createJSWorkerContextErrorHandler):
  • bindings/scripts/CodeGeneratorJS.pm:
  • bindings/scripts/CodeGeneratorV8.pm:
  • bindings/v8/V8WorkerContextErrorHandler.cpp: Added. (WebCore::V8WorkerContextErrorHandler::V8WorkerContextErrorHandler): (WebCore::V8WorkerContextErrorHandler::callListenerFunction):
  • bindings/v8/V8WorkerContextErrorHandler.h: Added. (WebCore::V8WorkerContextErrorHandler::create):
  • bindings/v8/V8WorkerContextEventListener.cpp:
  • bindings/v8/V8WorkerContextEventListener.h:
  • dom/EventListener.h:
  • workers/WorkerContext.cpp: (WebCore::WorkerContext::WorkerContext): (WebCore::WorkerContext::reportException):
  • workers/WorkerContext.h:

2010-04-06 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Test that exception which occurs in onerror handler is reported to the Worker object.

https://bugs.webkit.org/show_bug.cgi?id=36375

  • fast/workers/worker-script-error-expected.txt:
  • fast/workers/worker-script-error.html:
Location:
trunk
Files:
1 added
20 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r57116 r57134  
     12010-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
    1122010-04-05  Dimitri Glazkov  <dglazkov@chromium.org>
    213
  • trunk/LayoutTests/fast/workers/worker-script-error-expected.txt

    r57082 r57134  
    55PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1.
    66PASS: event listener invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1.
     7PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: bar' at line 3.
    78PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
    89PASS: 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  
    8282    try {
    8383        var worker = new Worker("resources/worker-error-in-handling-script-error.js");
     84        var errorCount = 0;
    8485        worker.onerror = function(evt) {
    8586            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();
    8791            return false;
    8892        }
  • trunk/WebCore/Android.jscbindings.mk

    r57082 r57134  
    158158        bindings/js/JSWorkerContextBase.cpp \
    159159        bindings/js/JSWorkerContextCustom.cpp \
     160        bindings/js/JSWorkerContextErrorHandler.cpp \
    160161        bindings/js/JSWorkerCustom.cpp \
    161162        bindings/js/JSXMLHttpRequestConstructor.cpp \
  • trunk/WebCore/ChangeLog

    r57133 r57134  
     12010-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
    1512010-04-06  Pavel Feldman  <pfeldman@chromium.org>
    252
  • trunk/WebCore/GNUmakefile.am

    r57082 r57134  
    474474        WebCore/bindings/js/JSWebKitPointConstructor.cpp \
    475475        WebCore/bindings/js/JSWebKitPointConstructor.h \
     476        WebCore/bindings/js/JSWorkerContextErrorHandler.cpp \
     477        WebCore/bindings/js/JSWorkerContextErrorHandler.h \
    476478        WebCore/bindings/js/JSXMLHttpRequestConstructor.cpp \
    477479        WebCore/bindings/js/JSXMLHttpRequestConstructor.h \
  • trunk/WebCore/WebCore.gypi

    r57082 r57134  
    625625            'bindings/js/JSWorkerContextBase.h',
    626626            'bindings/js/JSWorkerContextCustom.cpp',
     627            'bindings/js/JSWorkerContextErrorHandler.cpp',
     628            'bindings/js/JSWorkerContextErrorHandler.h',
    627629            'bindings/js/JSWorkerCustom.cpp',
    628630            'bindings/js/JSXMLHttpRequestConstructor.cpp',
     
    887889            'bindings/v8/V8Utilities.cpp',
    888890            'bindings/v8/V8Utilities.h',
     891            'bindings/v8/V8WorkerContextErrorHandler.cpp',
     892            'bindings/v8/V8WorkerContextErrorHandler.h',
    889893            'bindings/v8/V8WorkerContextEventListener.cpp',
    890894            'bindings/v8/V8WorkerContextEventListener.h',
  • trunk/WebCore/WebCore.pro

    r57082 r57134  
    364364    bindings/js/JSPluginElementFunctions.cpp \
    365365    bindings/js/JSPopStateEventCustom.cpp \
     366    bindings/js/JSWorkerContextErrorHandler.cpp \
    366367    bindings/js/JavaScriptProfile.h \
    367368    bindings/js/JavaScriptProfileNode.h \
     
    10721073    bindings/js/JSWorkerConstructor.h \
    10731074    bindings/js/JSWorkerContextBase.h \
    1074     bindings/js/JSWorkerContextBase.h \
     1075    bindings/js/JSWorkerContextErrorHandler.h \
    10751076    bindings/js/JSXMLHttpRequestConstructor.h \
    10761077    bindings/js/JSXSLTProcessorConstructor.h \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r57082 r57134  
    4006540065                                </File>
    4006640066                                <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
    4006740122                                        RelativePath="..\bindings\js\JSXMLHttpRequestConstructor.cpp"
    4006840123                                        >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r57095 r57134  
    48944894                F3644B001119805900E0D537 /* InjectedScript.h in Headers */ = {isa = PBXBuildFile; fileRef = F3644AFE1119805900E0D537 /* InjectedScript.h */; };
    48954895                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 */; };
    48964898                F4EAF4AE10C742B1009100D3 /* OpenTypeSanitizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F4EAF4AC10C742B1009100D3 /* OpenTypeSanitizer.cpp */; };
    48974899                F4EAF4AF10C742B1009100D3 /* OpenTypeSanitizer.h in Headers */ = {isa = PBXBuildFile; fileRef = F4EAF4AD10C742B1009100D3 /* OpenTypeSanitizer.h */; };
     
    1026510267                F3644AFE1119805900E0D537 /* InjectedScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedScript.h; sourceTree = "<group>"; };
    1026610268                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>"; };
    1026710271                F4EAF4AC10C742B1009100D3 /* OpenTypeSanitizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenTypeSanitizer.cpp; path = opentype/OpenTypeSanitizer.cpp; sourceTree = "<group>"; };
    1026810272                F4EAF4AD10C742B1009100D3 /* OpenTypeSanitizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenTypeSanitizer.h; path = opentype/OpenTypeSanitizer.h; sourceTree = "<group>"; };
     
    1485414858                                E1C36D320EB0A094007410BC /* JSWorkerContextBase.cpp */,
    1485514859                                E1C36D330EB0A094007410BC /* JSWorkerContextBase.h */,
     14860                                F3D461461161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp */,
     14861                                F3D461471161D53200CA0D09 /* JSWorkerContextErrorHandler.h */,
    1485614862                                BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */,
    1485714863                                BCA378BB0D15F64200B793D6 /* ScheduledAction.h */,
     
    1795617962                                E18256900EF2B02D00933242 /* JSWorkerContext.h in Headers */,
    1795717963                                E1C36D350EB0A094007410BC /* JSWorkerContextBase.h in Headers */,
     17964                                F3D461491161D53200CA0D09 /* JSWorkerContextErrorHandler.h in Headers */,
    1795817965                                E1C362EF0EAF2AA9007410BC /* JSWorkerLocation.h in Headers */,
    1795917966                                E1271A580EEECDE400F61213 /* JSWorkerNavigator.h in Headers */,
     
    2027120278                                E1C36D340EB0A094007410BC /* JSWorkerContextBase.cpp in Sources */,
    2027220279                                E18258AC0EF3CD7000933242 /* JSWorkerContextCustom.cpp in Sources */,
     20280                                F3D461481161D53200CA0D09 /* JSWorkerContextErrorHandler.cpp in Sources */,
    2027320281                                E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */,
    2027420282                                E1C362F00EAF2AA9007410BC /* JSWorkerLocation.cpp in Sources */,
  • trunk/WebCore/bindings/js/JSBindingsAllInOne.cpp

    r54777 r57134  
    128128#include "JSWorkerContextBase.cpp"
    129129#include "JSWorkerContextCustom.cpp"
     130#include "JSWorkerContextErrorHandler.cpp"
    130131#include "JSWorkerCustom.cpp"
    131132#include "JSXMLHttpRequestConstructor.cpp"
  • trunk/WebCore/bindings/js/JSEventListener.cpp

    r57082 r57134  
    134134}
    135135
    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 
    177136bool JSEventListener::virtualisAttribute() const
    178137{
  • trunk/WebCore/bindings/js/JSEventListener.h

    r57082 r57134  
    6161        virtual void invalidateJSFunction(JSC::JSObject*);
    6262        virtual void handleEvent(ScriptExecutionContext*, Event*);
    63         virtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber);
    6463        virtual bool virtualisAttribute() const;
    6564
  • trunk/WebCore/bindings/js/JSWorkerContextErrorHandler.h

    r57133 r57134  
    11/*
    2  * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2010 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef V8WorkerContextEventListener_h
    32 #define V8WorkerContextEventListener_h
     31#ifndef JSWorkerContextErrorHandler_h
     32#define JSWorkerContextErrorHandler_h
    3333
    34 #if ENABLE(WORKERS)
    35 
    36 #include "V8CustomEventListener.h"
    37 #include <v8.h>
    38 #include <wtf/PassRefPtr.h>
     34#include "JSEventListener.h"
    3935
    4036namespace WebCore {
    4137
    42     class Event;
    43     class WorkerContextExecutionProxy;
     38class JSWorkerContextErrorHandler : public JSEventListener {
     39public:
     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    }
    4444
    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();
    5146
    52         virtual void handleEvent(ScriptExecutionContext*, Event*);
    53         virtual bool reportError(ScriptExecutionContext*, const String& message, const String& url, int lineNumber);
     47private:
     48    JSWorkerContextErrorHandler(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld);
     49    virtual void handleEvent(ScriptExecutionContext*, Event*);
     50};
    5451
    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.
     54inline PassRefPtr<JSWorkerContextErrorHandler> createJSWorkerContextErrorHandler(JSC::ExecState* exec, JSC::JSValue listener, JSC::JSObject* wrapper)
     55{
     56    if (!listener.isObject())
     57        return 0;
    5758
    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}
    6161
    6262} // namespace WebCore
    6363
    64 #endif // WORKERS
    65 
    66 #endif // V8WorkerContextEventListener_h
     64#endif // JSWorkerContextErrorHandler_h
  • trunk/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r57082 r57134  
    14851485                            push(@implContent, "    UNUSED_PARAM(exec);\n");
    14861486                            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                            }
    14881493                        } elsif ($attribute->signature->type =~ /Constructor$/) {
    14891494                            my $constructorType = $attribute->signature->type;
  • trunk/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r57082 r57134  
    912912            $implIncludes{"V8AbstractEventListener.h"} = 1;
    913913            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            }
    915921        } else {
    916922            push(@implContentDecls, "    imp->set$implSetterFunctionName($result");
  • trunk/WebCore/bindings/v8/V8WorkerContextErrorHandler.cpp

    r57133 r57134  
    11/*
    2  * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2010 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef V8WorkerContextEventListener_h
    32 #define V8WorkerContextEventListener_h
     31#include "config.h"
    3332
    3433#if ENABLE(WORKERS)
    3534
    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"
    3939
    4040namespace WebCore {
    4141
    42     class Event;
    43     class WorkerContextExecutionProxy;
     42V8WorkerContextErrorHandler::V8WorkerContextErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext)
     43    : V8WorkerContextEventListener(listener, isInline, worldContext)
     44{
     45}
    4446
    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         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     };
     47v8::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}
    6163
    6264} // namespace WebCore
    6365
    6466#endif // WORKERS
    65 
    66 #endif // V8WorkerContextEventListener_h
  • trunk/WebCore/bindings/v8/V8WorkerContextErrorHandler.h

    r57133 r57134  
    11/*
    2  * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2010 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef V8WorkerContextEventListener_h
    32 #define V8WorkerContextEventListener_h
     31#ifndef V8WorkerContextErrorHandler_h
     32#define V8WorkerContextErrorHandler_h
    3333
    3434#if ENABLE(WORKERS)
    3535
    36 #include "V8CustomEventListener.h"
     36#include "V8WorkerContextEventListener.h"
    3737#include <v8.h>
    3838#include <wtf/PassRefPtr.h>
     
    4040namespace WebCore {
    4141
    42     class Event;
    43     class WorkerContextExecutionProxy;
     42class V8WorkerContextErrorHandler : public V8WorkerContextEventListener {
     43public:
     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    }
    4448
    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         }
     49private:
     50    V8WorkerContextErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext);
    5151
    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};
    6154
    6255} // namespace WebCore
     
    6457#endif // WORKERS
    6558
    66 #endif // V8WorkerContextEventListener_h
     59#endif // V8WorkerContextErrorHandler_h
  • trunk/WebCore/bindings/v8/V8WorkerContextEventListener.cpp

    r57082 r57134  
    8383}
    8484
    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 
    13585v8::Local<v8::Value> V8WorkerContextEventListener::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event)
    13686{
  • trunk/WebCore/bindings/v8/V8WorkerContextEventListener.h

    r57082 r57134  
    5151
    5252        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);
    5456
    5557    private:
    56         V8WorkerContextEventListener(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext);
    57 
    5858        virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);
    5959        v8::Local<v8::Object> getReceiverObject(ScriptExecutionContext*, Event*);
  • trunk/WebCore/dom/EventListener.h

    r57082 r57134  
    4747        virtual bool operator==(const EventListener&) = 0;
    4848        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; }
    5149        virtual bool wasCreatedFromMarkup() const { return false; }
    5250
  • trunk/WebCore/workers/WorkerContext.cpp

    r57082 r57134  
    3333
    3434#include "ActiveDOMObject.h"
    35 #include "Database.h"
    3635#include "DOMTimer.h"
    3736#include "DOMWindow.h"
     37#include "Database.h"
     38#include "ErrorEvent.h"
    3839#include "Event.h"
    3940#include "EventException.h"
     
    6566    , m_thread(thread)
    6667    , m_closing(false)
     68    , m_reportingException(false)
    6769{
    6870    setSecurityOrigin(SecurityOrigin::create(url));
     
    228230{
    229231    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    }
    233241    if (!errorHandled)
    234242        thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL);
  • trunk/WebCore/workers/WorkerContext.h

    r57082 r57134  
    155155#endif
    156156        bool m_closing;
     157        bool m_reportingException;
    157158        EventTargetData m_eventTargetData;
    158159    };
Note: See TracChangeset for help on using the changeset viewer.