Changeset 60708 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Jun 4, 2010, 2:38:38 PM (15 years ago)
Author:
[email protected]
Message:

Bug 40187 - Change function signature of NativeConstructor to match NativeFunction

Reviewed by Oliver Hunt.

Mostly for consistency, but constructor & args arguments are redundant,
and this will help if we wish to be able to JIT calls to more constructors.

JavaScriptCore:

  • API/JSCallbackConstructor.cpp:

(JSC::constructJSCallback):

  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:

(JSC::::construct):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::executeConstruct):

  • interpreter/Interpreter.h:
  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • runtime/ArrayConstructor.cpp:

(JSC::constructWithArrayConstructor):

  • runtime/BooleanConstructor.cpp:

(JSC::constructWithBooleanConstructor):

  • runtime/ConstructData.cpp:

(JSC::construct):

  • runtime/ConstructData.h:
  • runtime/DateConstructor.cpp:

(JSC::constructWithDateConstructor):

  • runtime/Error.cpp:

(JSC::constructNativeError):
(JSC::Error::create):

  • runtime/ErrorConstructor.cpp:

(JSC::constructWithErrorConstructor):

  • runtime/FunctionConstructor.cpp:

(JSC::constructWithFunctionConstructor):

  • runtime/NativeErrorConstructor.cpp:

(JSC::constructWithNativeErrorConstructor):

  • runtime/NativeErrorConstructor.h:

(JSC::NativeErrorConstructor::errorStructure):

  • runtime/NumberConstructor.cpp:

(JSC::constructWithNumberConstructor):

  • runtime/ObjectConstructor.cpp:

(JSC::constructWithObjectConstructor):

  • runtime/RegExpConstructor.cpp:

(JSC::constructWithRegExpConstructor):

  • runtime/StringConstructor.cpp:

(JSC::constructWithStringConstructor):

WebCore:

  • bindings/js/JSArrayBufferConstructor.cpp:

(WebCore::constructCanvasArrayBuffer):

  • bindings/js/JSAudioConstructor.cpp:

(WebCore::constructAudio):

  • bindings/js/JSEventSourceConstructor.cpp:

(WebCore::constructEventSource):

  • bindings/js/JSFloatArrayConstructor.cpp:

(WebCore::constructCanvasFloatArray):

  • bindings/js/JSImageConstructor.cpp:

(WebCore::constructImage):

  • bindings/js/JSInt16ArrayConstructor.cpp:

(WebCore::constructCanvasShortArray):

  • bindings/js/JSInt32ArrayConstructor.cpp:

(WebCore::constructCanvasIntArray):

  • bindings/js/JSInt8ArrayConstructor.cpp:

(WebCore::constructCanvasByteArray):

  • bindings/js/JSMessageChannelConstructor.cpp:

(WebCore::JSMessageChannelConstructor::construct):

  • bindings/js/JSMessageChannelConstructor.h:
  • bindings/js/JSOptionConstructor.cpp:

(WebCore::constructHTMLOptionElement):

  • bindings/js/JSSharedWorkerConstructor.cpp:

(WebCore::constructSharedWorker):

  • bindings/js/JSUint16ArrayConstructor.cpp:

(WebCore::constructCanvasUnsignedShortArray):

  • bindings/js/JSUint32ArrayConstructor.cpp:

(WebCore::constructCanvasUnsignedIntArray):

  • bindings/js/JSUint8ArrayConstructor.cpp:

(WebCore::constructCanvasUnsignedByteArray):

  • bindings/js/JSWebKitCSSMatrixConstructor.cpp:

(WebCore::constructWebKitCSSMatrix):

  • bindings/js/JSWebKitPointConstructor.cpp:

(WebCore::constructWebKitPoint):

  • bindings/js/JSWebSocketConstructor.cpp:

(WebCore::constructWebSocket):

  • bindings/js/JSWorkerConstructor.cpp:

(WebCore::constructWorker):

  • bindings/js/JSXMLHttpRequestConstructor.cpp:

(WebCore::constructXMLHttpRequest):

  • bindings/js/JSXSLTProcessorConstructor.cpp:

(WebCore::constructXSLTProcessor):

  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/runtime_object.cpp:

(JSC::Bindings::callRuntimeConstructor):

Location:
trunk/JavaScriptCore/runtime
Files:
14 edited

Legend:

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

    r60631 r60708  
    6565}
    6666
    67 static JSObject* constructWithArrayConstructor(ExecState* exec, JSObject*, const ArgList& args)
     67static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec)
    6868{
    69     return constructArrayWithSizeQuirk(exec, args);
     69    ArgList args(exec);
     70    return JSValue::encode(constructArrayWithSizeQuirk(exec, args));
    7071}
    7172
  • trunk/JavaScriptCore/runtime/BooleanConstructor.cpp

    r60631 r60708  
    4646}
    4747
    48 static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args)
     48static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
    4949{
    50     return constructBoolean(exec, args);
     50    ArgList args(exec);
     51    return JSValue::encode(constructBoolean(exec, args));
    5152}
    5253
  • trunk/JavaScriptCore/runtime/ConstructData.cpp

    r60392 r60708  
    3434namespace JSC {
    3535
    36 JSObject* construct(ExecState* exec, JSValue object, ConstructType constructType, const ConstructData& constructData, const ArgList& args)
     36JSObject* construct(ExecState* exec, JSValue constructorObject, ConstructType constructType, const ConstructData& constructData, const ArgList& args)
    3737{
    38     if (constructType == ConstructTypeHost)
    39         return constructData.native.function(exec, asObject(object), args);
    40 
    41     ASSERT(constructType == ConstructTypeJS);
    42     JSFunction* jsFunction = asFunction(object);
    43 
    44     ASSERT(!jsFunction->isHostFunction());
    45     Structure* structure;
    46     JSValue prototype = jsFunction->get(exec, exec->propertyNames().prototype);
    47     if (prototype.isObject())
    48         structure = asObject(prototype)->inheritorID();
    49     else
    50         structure = exec->lexicalGlobalObject()->emptyObjectStructure();
    51     JSObject* thisObj = new (exec) JSObject(structure);
    52 
    53     JSValue result = exec->interpreter()->executeConstruct(jsFunction->jsExecutable(), exec, jsFunction, thisObj, args, jsFunction->scope().node(), exec->exceptionSlot());
    54     if (exec->hadException() || !result.isObject())
    55         return thisObj;
    56     return asObject(result);
     38    ASSERT(constructType == ConstructTypeJS || constructType == ConstructTypeHost);
     39    return exec->interpreter()->executeConstruct(exec, asObject(constructorObject), constructType, constructData, args, exec->exceptionSlot());
    5740}
    5841
  • trunk/JavaScriptCore/runtime/ConstructData.h

    r47412 r60708  
    3030#define ConstructData_h
    3131
     32#include "JSValue.h"
     33
    3234namespace JSC {
    3335
     
    3638    class FunctionExecutable;
    3739    class JSObject;
    38     class JSValue;
    3940    class ScopeChainNode;
    4041
     
    4546    };
    4647
    47     typedef JSObject* (*NativeConstructor)(ExecState*, JSObject*, const ArgList&);
     48    typedef EncodedJSValue (JSC_HOST_CALL *NativeConstructor)(ExecState*);
    4849
    4950    union ConstructData {
  • trunk/JavaScriptCore/runtime/DateConstructor.cpp

    r60631 r60708  
    117117}
    118118   
    119 static JSObject* constructWithDateConstructor(ExecState* exec, JSObject*, const ArgList& args)
     119static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec)
    120120{
    121     return constructDate(exec, args);
     121    ArgList args(exec);
     122    return JSValue::encode(constructDate(exec, args));
    122123}
    123124
  • trunk/JavaScriptCore/runtime/Error.cpp

    r54464 r60708  
    3939const char* expressionEndOffsetPropertyName = "expressionEndOffset";
    4040
     41static JSObject* constructNativeError(ExecState* exec, const UString& message, NativeErrorConstructor* constructor, const char* name)
     42{
     43    ErrorInstance* object = new (exec) ErrorInstance(constructor->errorStructure());
     44    JSString* messageString = message.isEmpty() ? jsString(exec, name) : jsString(exec, message);
     45    object->putDirect(exec->propertyNames().message, messageString);
     46    return object;
     47}
     48
    4149JSObject* Error::create(ExecState* exec, ErrorType type, const UString& message, int lineNumber, intptr_t sourceID, const UString& sourceURL)
    4250{
    43     JSObject* constructor;
    44     const char* name;
     51    JSObject* error;
     52
    4553    switch (type) {
    4654        case EvalError:
    47             constructor = exec->lexicalGlobalObject()->evalErrorConstructor();
    48             name = "Evaluation error";
     55            error = constructNativeError(exec, message, exec->lexicalGlobalObject()->evalErrorConstructor(), "Evaluation error");
    4956            break;
    5057        case RangeError:
    51             constructor = exec->lexicalGlobalObject()->rangeErrorConstructor();
    52             name = "Range error";
     58            error = constructNativeError(exec, message, exec->lexicalGlobalObject()->rangeErrorConstructor(), "Range error");
    5359            break;
    5460        case ReferenceError:
    55             constructor = exec->lexicalGlobalObject()->referenceErrorConstructor();
    56             name = "Reference error";
     61            error = constructNativeError(exec, message, exec->lexicalGlobalObject()->referenceErrorConstructor(), "Reference error");
    5762            break;
    5863        case SyntaxError:
    59             constructor = exec->lexicalGlobalObject()->syntaxErrorConstructor();
    60             name = "Syntax error";
     64            error = constructNativeError(exec, message, exec->lexicalGlobalObject()->syntaxErrorConstructor(), "Syntax error");
    6165            break;
    6266        case TypeError:
    63             constructor = exec->lexicalGlobalObject()->typeErrorConstructor();
    64             name = "Type error";
     67            error = constructNativeError(exec, message, exec->lexicalGlobalObject()->typeErrorConstructor(), "Type error");
    6568            break;
    6669        case URIError:
    67             constructor = exec->lexicalGlobalObject()->URIErrorConstructor();
    68             name = "URI error";
     70            error = constructNativeError(exec, message, exec->lexicalGlobalObject()->URIErrorConstructor(), "URI error");
    6971            break;
    7072        default:
    71             constructor = exec->lexicalGlobalObject()->errorConstructor();
    72             name = "Error";
    73             break;
     73            JSObject* constructor = exec->lexicalGlobalObject()->errorConstructor();
     74            const char* name = "Error";
     75            MarkedArgumentBuffer args;
     76            if (message.isEmpty())
     77                args.append(jsString(exec, name));
     78            else
     79                args.append(jsString(exec, message));
     80            ConstructData constructData;
     81            ConstructType constructType = constructor->getConstructData(constructData);
     82            error = construct(exec, constructor, constructType, constructData, args);
    7483    }
    75 
    76     MarkedArgumentBuffer args;
    77     if (message.isEmpty())
    78         args.append(jsString(exec, name));
    79     else
    80         args.append(jsString(exec, message));
    81     ConstructData constructData;
    82     ConstructType constructType = constructor->getConstructData(constructData);
    83     JSObject* error = construct(exec, constructor, constructType, constructData, args);
    8484
    8585    if (lineNumber != -1)
  • trunk/JavaScriptCore/runtime/ErrorConstructor.cpp

    r60631 r60708  
    4747}
    4848
    49 static JSObject* constructWithErrorConstructor(ExecState* exec, JSObject*, const ArgList& args)
     49static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec)
    5050{
    51     return constructError(exec, args);
     51    ArgList args(exec);
     52    return JSValue::encode(constructError(exec, args));
    5253}
    5354
  • trunk/JavaScriptCore/runtime/FunctionConstructor.cpp

    r60631 r60708  
    4545}
    4646
    47 static JSObject* constructWithFunctionConstructor(ExecState* exec, JSObject*, const ArgList& args)
     47static EncodedJSValue JSC_HOST_CALL constructWithFunctionConstructor(ExecState* exec)
    4848{
    49     return constructFunction(exec, args);
     49    ArgList args(exec);
     50    return JSValue::encode(constructFunction(exec, args));
    5051}
    5152
  • trunk/JavaScriptCore/runtime/NativeErrorConstructor.cpp

    r60631 r60708  
    5252}
    5353
    54 static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args)
     54static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec)
    5555{
    56     return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
     56    ArgList args(exec);
     57    return JSValue::encode(static_cast<NativeErrorConstructor*>(exec->callee())->construct(exec, args));
    5758}
    5859
  • trunk/JavaScriptCore/runtime/NativeErrorConstructor.h

    r59974 r60708  
    3838        ErrorInstance* construct(ExecState*, const ArgList&);
    3939
     40        Structure* errorStructure() { return m_errorStructure.get(); }
     41
    4042    private:
    4143        virtual ConstructType getConstructData(ConstructData&);
  • trunk/JavaScriptCore/runtime/NumberConstructor.cpp

    r60631 r60708  
    101101
    102102// ECMA 15.7.1
    103 static JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args)
     103static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec)
    104104{
    105105    NumberObject* object = new (exec) NumberObject(exec->lexicalGlobalObject()->numberObjectStructure());
    106     double n = args.isEmpty() ? 0 : args.at(0).toNumber(exec);
     106    double n = exec->argumentCount() ? exec->argument(0).toNumber(exec) : 0;
    107107    object->setInternalValue(jsNumber(exec, n));
    108     return object;
     108    return JSValue::encode(object);
    109109}
    110110
  • trunk/JavaScriptCore/runtime/ObjectConstructor.cpp

    r60631 r60708  
    7070}
    7171
    72 static JSObject* constructWithObjectConstructor(ExecState* exec, JSObject*, const ArgList& args)
    73 {
    74     return constructObject(exec, args);
     72static EncodedJSValue JSC_HOST_CALL constructWithObjectConstructor(ExecState* exec)
     73{
     74    ArgList args(exec);
     75    return JSValue::encode(constructObject(exec, args));
    7576}
    7677
  • trunk/JavaScriptCore/runtime/RegExpConstructor.cpp

    r60631 r60708  
    308308}
    309309
    310 static JSObject* constructWithRegExpConstructor(ExecState* exec, JSObject*, const ArgList& args)
    311 {
    312     return constructRegExp(exec, args);
     310static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
     311{
     312    ArgList args(exec);
     313    return JSValue::encode(constructRegExp(exec, args));
    313314}
    314315
  • trunk/JavaScriptCore/runtime/StringConstructor.cpp

    r60631 r60708  
    6767
    6868// ECMA 15.5.2
    69 static JSObject* constructWithStringConstructor(ExecState* exec, JSObject*, const ArgList& args)
     69static EncodedJSValue JSC_HOST_CALL constructWithStringConstructor(ExecState* exec)
    7070{
    71     if (args.isEmpty())
    72         return new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure());
    73     return new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure(), args.at(0).toString(exec));
     71    if (!exec->argumentCount())
     72        return JSValue::encode(new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure()));
     73    return JSValue::encode(new (exec) StringObject(exec, exec->lexicalGlobalObject()->stringObjectStructure(), exec->argument(0).toString(exec)));
    7474}
    7575
Note: See TracChangeset for help on using the changeset viewer.