Changeset 57192 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Apr 6, 2010, 9:38:23 PM (15 years ago)
Author:
[email protected]
Message:

2010-04-06 Adam Barth <[email protected]>

Reviewed by Eric Seidel.

REGRESSION: Worker termination via JS timeout may cause worker tests like fast/workers/worker-terminate.html fail.
https://bugs.webkit.org/show_bug.cgi?id=36646

Add a new exception type for forcibly terminating a JavaScript stack.
The new exception functions similarly to the
InterruptedExecutionException but is conceptually different because
execution is terminated instead of just interrupted.

  • GNUmakefile.am:
    • Added new Terminator.h file.
  • JavaScriptCore.gypi:
    • Added new Terminator.h file.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
    • Added new Terminator.h file.
  • JavaScriptCore.xcodeproj/project.pbxproj:
    • Added new Terminator.h file.
  • interpreter/Interpreter.cpp: (JSC::Interpreter::throwException):
    • Fully unwind the stack for TerminatedExecutionException.

(JSC::Interpreter::privateExecute):

  • Check if we've been terminated at the same time we check if we've timed out.
  • jit/JITStubs.cpp: (JSC::DEFINE_STUB_FUNCTION):
    • Check if we've been terminated at the same time we check if we've timed out.
  • runtime/Completion.cpp:
    • Some exceptions define special completion types so that calls can see why we terminated evaluation.

(JSC::evaluate):

  • runtime/Completion.h:
    • Define a new completion type for termination.

(JSC::):

  • runtime/ExceptionHelpers.cpp:
    • Define TerminatedExecutionException and refactor pseudo-RTTI virtual function to be more semantic.

(JSC::InterruptedExecutionError::exceptionType):
(JSC::TerminatedExecutionError::TerminatedExecutionError):
(JSC::TerminatedExecutionError::exceptionType):
(JSC::TerminatedExecutionError::toString):
(JSC::createTerminatedExecutionException):

  • runtime/ExceptionHelpers.h:
    • Entry point for generating a TerminatedExecutionException.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData):
    • Add a Terminator object that can be used to asynchronously terminate a JavaScript execution stack.
  • runtime/JSGlobalData.h:
  • runtime/JSObject.h: (JSC::JSObject::exceptionType):
    • Define that, by default, thrown objects have a normal exception type.
  • runtime/Terminator.h: Added.
    • Added a new controller object that can be used to terminate execution asynchronously. This object is more or less a glorified bool.

(JSC::Terminator::Terminator):
(JSC::Terminator::termianteSoon):
(JSC::Terminator::shouldTerminate):

2010-04-06 Adam Barth <[email protected]>

Reviewed by Eric Seidel.

REGRESSION: Worker termination via JS timeout may cause worker tests like fast/workers/worker-terminate.html fail.
https://bugs.webkit.org/show_bug.cgi?id=36646

  • fast/workers/resources/worker-run-forever.js: Added.
  • fast/workers/worker-terminate-forever-expected.txt: Added.
  • fast/workers/worker-terminate-forever.html: Added.
    • Test what happens when we terminate an infinitely running worker. The essential point is that we don't spam the console with nonsense about a timeout.
  • platform/mac/Skipped:
    • Rescue worker-terminate.html from the Skipped list now that we've fixed the underlying bug that was causing the flakiness.

2010-04-06 Adam Barth <[email protected]>

Reviewed by Eric Seidel.

REGRESSION: Worker termination via JS timeout may cause worker tests like fast/workers/worker-terminate.html fail.
https://bugs.webkit.org/show_bug.cgi?id=36646

Cause the worker code to swallow termination exceptions because these
need not be reported to the user because they are an implementation
detail of how we terminate worker execution.

Test: fast/workers/worker-terminate-forever.html

  • bindings/js/JSDOMBinding.cpp: (WebCore::reportException):
    • Refuse to report termination exceptions to the user because they are an implementation detail.
  • bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::forbidExecution):
    • Instead of using timeouts to stop run away workers, use our fancy new Terminator object.
Location:
trunk/JavaScriptCore/runtime
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Completion.cpp

    r52856 r57192  
    6363
    6464    if (exception) {
    65         if (exception.isObject() && asObject(exception)->isWatchdogException())
    66             return Completion(Interrupted, exception);
    67         return Completion(Throw, exception);
     65        ComplType exceptionType = Throw;
     66        if (exception.isObject())
     67            exceptionType = asObject(exception)->exceptionType();
     68        return Completion(exceptionType, exception);
    6869    }
    6970    return Completion(Normal, result);
  • trunk/JavaScriptCore/runtime/Completion.h

    r44224 r57192  
    3232    class SourceCode;
    3333
    34     enum ComplType { Normal, Break, Continue, ReturnValue, Throw, Interrupted };
     34    enum ComplType { Normal, Break, Continue, ReturnValue, Throw, Interrupted, Terminated };
    3535
    3636    /*
  • trunk/JavaScriptCore/runtime/ExceptionHelpers.cpp

    r54464 r57192  
    4747    }
    4848
    49     virtual bool isWatchdogException() const { return true; }
     49    virtual ComplType exceptionType() const { return Interrupted; }
    5050
    5151    virtual UString toString(ExecState*) const { return "JavaScript execution exceeded timeout."; }
     
    5555{
    5656    return new (globalData) InterruptedExecutionError(globalData);
     57}
     58
     59class TerminatedExecutionError : public JSObject {
     60public:
     61    TerminatedExecutionError(JSGlobalData* globalData)
     62        : JSObject(globalData->terminatedExecutionErrorStructure)
     63    {
     64    }
     65
     66    virtual ComplType exceptionType() const { return Terminated; }
     67
     68    virtual UString toString(ExecState*) const { return "JavaScript execution terminated."; }
     69};
     70
     71JSValue createTerminatedExecutionException(JSGlobalData* globalData)
     72{
     73    return new (globalData) TerminatedExecutionError(globalData);
    5774}
    5875
  • trunk/JavaScriptCore/runtime/ExceptionHelpers.h

    r54394 r57192  
    4444   
    4545    JSValue createInterruptedExecutionException(JSGlobalData*);
     46    JSValue createTerminatedExecutionException(JSGlobalData*);
    4647    JSValue createStackOverflowError(ExecState*);
    4748    JSValue createTypeError(ExecState*, const char* message);
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r52956 r57192  
    116116    , activationStructure(JSActivation::createStructure(jsNull()))
    117117    , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
     118    , terminatedExecutionErrorStructure(JSObject::createStructure(jsNull()))
    118119    , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
    119120    , stringStructure(JSString::createStructure(jsNull()))
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r52956 r57192  
    3838#include "NumericStrings.h"
    3939#include "SmallStrings.h"
     40#include "Terminator.h"
    4041#include "TimeoutChecker.h"
    4142#include "WeakRandom.h"
     
    117118        RefPtr<Structure> activationStructure;
    118119        RefPtr<Structure> interruptedExecutionErrorStructure;
     120        RefPtr<Structure> terminatedExecutionErrorStructure;
    119121        RefPtr<Structure> staticScopeStructure;
    120122        RefPtr<Structure> stringStructure;
     
    154156#endif
    155157        TimeoutChecker timeoutChecker;
     158        Terminator terminator;
    156159        Heap heap;
    157160
  • trunk/JavaScriptCore/runtime/JSObject.h

    r57019 r57192  
    2727#include "ClassInfo.h"
    2828#include "CommonIdentifiers.h"
     29#include "Completion.h"
    2930#include "CallFrame.h"
    3031#include "JSCell.h"
     
    196197        virtual bool isVariableObject() const { return false; }
    197198        virtual bool isActivationObject() const { return false; }
    198         virtual bool isWatchdogException() const { return false; }
    199199        virtual bool isNotAnObjectErrorStub() const { return false; }
     200
     201        virtual ComplType exceptionType() const { return Throw; }
    200202
    201203        void allocatePropertyStorage(size_t oldSize, size_t newSize);
  • trunk/JavaScriptCore/runtime/Terminator.h

    r57191 r57192  
    11/*
    2  * Copyright (C) 2008 Apple 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
     
    1111 *     notice, this list of conditions and the following disclaimer in the
    1212 *     documentation and/or other materials provided with the distribution.
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     13 * 3.  Neither the name of Google Inc. ("Google") nor the names of
    1414 *     its contributors may be used to endorse or promote products derived
    1515 *     from this software without specific prior written permission.
     
    2727 */
    2828
    29 #ifndef ExceptionHelpers_h
    30 #define ExceptionHelpers_h
    31 
     29#ifndef Terminator_h
     30#define Terminator_h
    3231
    3332namespace JSC {
    3433
    35     class CodeBlock;
    36     class ExecState;
    37     class Identifier;
    38     class JSGlobalData;
    39     class JSNotAnObjectErrorStub;
    40     class JSObject;
    41     class JSValue;
    42     class Node;
    43     struct Instruction;
    44    
    45     JSValue createInterruptedExecutionException(JSGlobalData*);
    46     JSValue createStackOverflowError(ExecState*);
    47     JSValue createTypeError(ExecState*, const char* message);
    48     JSValue createUndefinedVariableError(ExecState*, const Identifier&, unsigned bytecodeOffset, CodeBlock*);
    49     JSNotAnObjectErrorStub* createNotAnObjectErrorStub(ExecState*, bool isNull);
    50     JSObject* createInvalidParamError(ExecState*, const char* op, JSValue, unsigned bytecodeOffset, CodeBlock*);
    51     JSObject* createNotAConstructorError(ExecState*, JSValue, unsigned bytecodeOffset, CodeBlock*);
    52     JSValue createNotAFunctionError(ExecState*, JSValue, unsigned bytecodeOffset, CodeBlock*);
    53     JSObject* createNotAnObjectError(ExecState*, JSNotAnObjectErrorStub*, unsigned bytecodeOffset, CodeBlock*);
    54     JSValue throwOutOfMemoryError(ExecState*);
     34class Terminator {
     35public:
     36    Terminator() : m_shouldTerminate(false) { }
     37
     38    void terminateSoon() { m_shouldTerminate = true; }
     39    bool shouldTerminate() const { return m_shouldTerminate; }
     40
     41private:
     42    bool m_shouldTerminate;
     43};
    5544
    5645} // namespace JSC
    5746
    58 #endif // ExceptionHelpers_h
     47#endif // Terminator_h
Note: See TracChangeset for help on using the changeset viewer.