Changeset 91194 in webkit for trunk/Source/JavaScriptCore/API


Ignore:
Timestamp:
Jul 18, 2011, 10:47:13 AM (14 years ago)
Author:
[email protected]
Message:

2011-07-18 Mark Hahnenberg <[email protected]>

Refactor JSC to replace JSCell::operator new with static create method
https://bugs.webkit.org/show_bug.cgi?id=64466

Reviewed by Oliver Hunt ([email protected]) and Darin Adler (Darin Adler).

First step in a longer refactoring process to remove the use of
operator new overloading in order to allocate GC objects and to replace
this method with static create methods for each individual type of heap-allocated
JS object. This particular patch only deals with replacing uses of
operator new within JSC proper. Future patches will remove it from the
parts that interface with the DOM. Due to the DOM's continued dependence
on it, operator new has not actually been removed from JSCell.

  • API/JSCallbackConstructor.h: (JSC::JSCallbackConstructor::create):
  • API/JSCallbackFunction.h: (JSC::JSCallbackFunction::create):
  • API/JSCallbackObject.h: (JSC::JSCallbackObject::operator new): (JSC::JSCallbackObject::create):
  • API/JSCallbackObjectFunctions.h: (JSC::::staticFunctionGetter):
  • API/JSClassRef.cpp: (OpaqueJSClass::prototype):
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp: (JSObjectMake): (JSObjectMakeFunctionWithCallback): (JSObjectMakeConstructor):
  • JavaScriptCore.exp:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::createActivation):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator):
  • bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::makeFunction):
  • bytecompiler/NodesCodegen.cpp: (JSC::RegExpNode::emitBytecode):
  • interpreter/Interpreter.cpp: (JSC::Interpreter::privateExecute): (JSC::Interpreter::retrieveArguments):
  • jit/JITStubs.cpp: (JSC::DEFINE_STUB_FUNCTION):
  • jsc.cpp: (GlobalObject::create): (GlobalObject::GlobalObject): (functionRun): (jscmain):
  • runtime/Arguments.h: (JSC::Arguments::create): (JSC::Arguments::createNoParameters):
  • runtime/ArrayConstructor.cpp: (JSC::constructArrayWithSizeQuirk):
  • runtime/ArrayConstructor.h: (JSC::ArrayConstructor::create):
  • runtime/ArrayPrototype.cpp: (JSC::arrayProtoFuncSplice):
  • runtime/ArrayPrototype.h: (JSC::ArrayPrototype::create):
  • runtime/BooleanConstructor.cpp: (JSC::constructBoolean): (JSC::constructBooleanFromImmediateBoolean):
  • runtime/BooleanConstructor.h: (JSC::BooleanConstructor::create):
  • runtime/BooleanObject.h: (JSC::BooleanObject::create):
  • runtime/BooleanPrototype.h: (JSC::BooleanPrototype::create):
  • runtime/DateConstructor.cpp: (JSC::constructDate):
  • runtime/DateConstructor.h: (JSC::DateConstructor::create):
  • runtime/DateInstance.h: (JSC::DateInstance::create):
  • runtime/DatePrototype.h: (JSC::DatePrototype::create):
  • runtime/Error.cpp: (JSC::createError): (JSC::createEvalError): (JSC::createRangeError): (JSC::createReferenceError): (JSC::createSyntaxError): (JSC::createTypeError): (JSC::createURIError): (JSC::StrictModeTypeErrorFunction::create): (JSC::createTypeErrorFunction):
  • runtime/ErrorConstructor.h: (JSC::ErrorConstructor::create):
  • runtime/ErrorInstance.cpp: (JSC::ErrorInstance::ErrorInstance): (JSC::ErrorInstance::create):
  • runtime/ErrorInstance.h:
  • runtime/ErrorPrototype.cpp: (JSC::ErrorPrototype::ErrorPrototype):
  • runtime/ErrorPrototype.h: (JSC::ErrorPrototype::create):
  • runtime/ExceptionHelpers.cpp: (JSC::InterruptedExecutionError::InterruptedExecutionError): (JSC::InterruptedExecutionError::create): (JSC::createInterruptedExecutionException): (JSC::TerminatedExecutionError::TerminatedExecutionError): (JSC::TerminatedExecutionError::create): (JSC::createTerminatedExecutionException):
  • runtime/Executable.cpp: (JSC::FunctionExecutable::FunctionExecutable): (JSC::FunctionExecutable::fromGlobalCode):
  • runtime/Executable.h: (JSC::ExecutableBase::create): (JSC::NativeExecutable::create): (JSC::ScriptExecutable::ScriptExecutable): (JSC::EvalExecutable::create): (JSC::ProgramExecutable::create): (JSC::FunctionExecutable::create): (JSC::FunctionExecutable::make):
  • runtime/FunctionConstructor.cpp: (JSC::constructFunctionSkippingEvalEnabledCheck):
  • runtime/FunctionConstructor.h: (JSC::FunctionConstructor::create):
  • runtime/FunctionPrototype.cpp: (JSC::FunctionPrototype::addFunctionProperties):
  • runtime/FunctionPrototype.h: (JSC::FunctionPrototype::create):
  • runtime/GetterSetter.h: (JSC::GetterSetter::create):
  • runtime/JSAPIValueWrapper.h: (JSC::JSAPIValueWrapper::create): (JSC::jsAPIValueWrapper):
  • runtime/JSActivation.cpp: (JSC::JSActivation::argumentsGetter):
  • runtime/JSActivation.h: (JSC::JSActivation::create):
  • runtime/JSArray.h: (JSC::JSArray::create):
  • runtime/JSCell.h: (JSC::JSCell::allocateCell):
  • runtime/JSFunction.h: (JSC::JSFunction::create):
  • runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): (JSC::JSGlobalObject::reset):
  • runtime/JSGlobalObject.h: (JSC::constructEmptyArray): (JSC::constructArray):
  • runtime/JSNotAnObject.h: (JSC::JSNotAnObject::create):
  • runtime/JSONObject.h: (JSC::JSONObject::create):
  • runtime/JSObject.cpp: (JSC::JSObject::defineGetter): (JSC::JSObject::defineSetter): (JSC::putDescriptor):
  • runtime/JSObject.h: (JSC::JSFinalObject::create):
  • runtime/JSPropertyNameIterator.cpp: (JSC::JSPropertyNameIterator::create):
  • runtime/JSPropertyNameIterator.h: (JSC::JSPropertyNameIterator::create):
  • runtime/JSString.cpp: (JSC::JSString::substringFromRope): (JSC::JSString::replaceCharacter): (JSC::StringObject::create):
  • runtime/JSString.h: (JSC::RopeBuilder::JSString): (JSC::RopeBuilder::create): (JSC::RopeBuilder::createHasOtherOwner): (JSC::jsSingleCharacterString): (JSC::jsSingleCharacterSubstring): (JSC::jsNontrivialString): (JSC::jsString): (JSC::jsSubstring): (JSC::jsOwnedString):
  • runtime/JSValue.cpp: (JSC::JSValue::toObjectSlowCase): (JSC::JSValue::synthesizeObject): (JSC::JSValue::synthesizePrototype):
  • runtime/Lookup.cpp: (JSC::setUpStaticFunctionSlot):
  • runtime/MathObject.h: (JSC::MathObject::create):
  • runtime/NativeErrorConstructor.cpp: (JSC::NativeErrorConstructor::NativeErrorConstructor):
  • runtime/NativeErrorConstructor.h: (JSC::NativeErrorConstructor::create):
  • runtime/NativeErrorPrototype.h: (JSC::NativeErrorPrototype::create):
  • runtime/NumberConstructor.cpp: (JSC::constructWithNumberConstructor):
  • runtime/NumberConstructor.h: (JSC::NumberConstructor::create):
  • runtime/NumberObject.cpp: (JSC::constructNumber):
  • runtime/NumberObject.h: (JSC::NumberObject::create):
  • runtime/NumberPrototype.h: (JSC::NumberPrototype::create):
  • runtime/ObjectConstructor.h: (JSC::ObjectConstructor::create):
  • runtime/ObjectPrototype.h: (JSC::ObjectPrototype::create):
  • runtime/Operations.h: (JSC::jsString):
  • runtime/RegExp.cpp: (JSC::RegExp::RegExp): (JSC::RegExp::createWithoutCaching): (JSC::RegExp::create):
  • runtime/RegExp.h:
  • runtime/RegExpCache.cpp: (JSC::RegExpCache::lookupOrCreate):
  • runtime/RegExpConstructor.cpp: (JSC::RegExpConstructor::arrayOfMatches): (JSC::constructRegExp):
  • runtime/RegExpConstructor.h: (JSC::RegExpConstructor::create):
  • runtime/RegExpMatchesArray.h: (JSC::RegExpMatchesArray::create):
  • runtime/RegExpObject.h: (JSC::RegExpObject::create):
  • runtime/RegExpPrototype.cpp: (JSC::regExpProtoFuncCompile):
  • runtime/RegExpPrototype.h: (JSC::RegExpPrototype::create):
  • runtime/ScopeChain.h: (JSC::ScopeChainNode::create): (JSC::ScopeChainNode::push):
  • runtime/SmallStrings.cpp: (JSC::SmallStrings::createEmptyString): (JSC::SmallStrings::createSingleCharacterString):
  • runtime/StringConstructor.cpp: (JSC::constructWithStringConstructor):
  • runtime/StringConstructor.h: (JSC::StringConstructor::create):
  • runtime/StringObject.h: (JSC::StringObject::create):
  • runtime/StringObjectThatMasqueradesAsUndefined.h: (JSC::StringObjectThatMasqueradesAsUndefined::create):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncMatch): (JSC::stringProtoFuncSearch):
  • runtime/StringPrototype.h: (JSC::StringPrototype::create):
  • runtime/Structure.h: (JSC::Structure::create): (JSC::Structure::createStructure):
  • runtime/StructureChain.h: (JSC::StructureChain::create):
Location:
trunk/Source/JavaScriptCore/API
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSCallbackConstructor.h

    r84052 r91194  
    3333
    3434class JSCallbackConstructor : public JSObjectWithGlobalObject {
     35protected:
     36    JSCallbackConstructor(JSGlobalObject*, Structure*, JSClassRef, JSObjectCallAsConstructorCallback);
    3537public:
    36     JSCallbackConstructor(JSGlobalObject*, Structure*, JSClassRef, JSObjectCallAsConstructorCallback);
     38    static JSCallbackConstructor* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSClassRef classRef, JSObjectCallAsConstructorCallback callback)
     39    {
     40        return new (allocateCell<JSCallbackConstructor>(*exec->heap())) JSCallbackConstructor(globalObject, structure, classRef, callback);
     41    }
     42   
    3743    virtual ~JSCallbackConstructor();
    3844    JSClassRef classRef() const { return m_class; }
  • trunk/Source/JavaScriptCore/API/JSCallbackFunction.h

    r84052 r91194  
    3333
    3434class JSCallbackFunction : public InternalFunction {
     35protected:
     36    JSCallbackFunction(ExecState*, JSGlobalObject*, JSObjectCallAsFunctionCallback, const Identifier& name);
     37
    3538public:
    36     JSCallbackFunction(ExecState*, JSGlobalObject*, JSObjectCallAsFunctionCallback, const Identifier& name);
     39    static JSCallbackFunction* create(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const Identifier& name)
     40    {
     41        return new (allocateCell<JSCallbackFunction>(*exec->heap())) JSCallbackFunction(exec, globalObject, callback, name);
     42    }
    3743
    3844    static const ClassInfo s_info;
  • trunk/Source/JavaScriptCore/API/JSCallbackObject.h

    r87588 r91194  
    117117template <class Base>
    118118class JSCallbackObject : public Base {
    119 public:
     119protected:
    120120    JSCallbackObject(ExecState*, JSGlobalObject*, Structure*, JSClassRef, void* data);
    121121    JSCallbackObject(JSGlobalData&, JSClassRef, Structure*);
     122    // We'd like to use the placement version of operator new defined in JSCell, but
     123    // we can't because Base is a template argument, so we just duplicate the same
     124    // functionality here.
     125    void* operator new(size_t, void* ptr) { return ptr; }
     126
     127public:
     128    static JSCallbackObject* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSClassRef classRef, void* data)
     129    {
     130        return new (allocateCell<JSCallbackObject>(*exec->heap())) JSCallbackObject(exec, globalObject, structure, classRef, data);
     131    }
     132    static JSCallbackObject* create(JSGlobalData& globalData, JSClassRef classRef, Structure* structure)
     133    {
     134        return new (allocateCell<JSCallbackObject>(globalData.heap)) JSCallbackObject(globalData, classRef, structure);
     135    }
    122136
    123137    void setPrivate(void* data);
  • trunk/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r88587 r91194  
    561561                if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
    562562                   
    563                     JSObject* o = new (exec) JSCallbackFunction(exec, asGlobalObject(thisObj->getAnonymousValue(0)), callAsFunction, propertyName);
     563                    JSObject* o = JSCallbackFunction::create(exec, asGlobalObject(thisObj->getAnonymousValue(0)), callAsFunction, propertyName);
    564564                    thisObj->putDirect(exec->globalData(), propertyName, o, entry->attributes);
    565565                    return o;
  • trunk/Source/JavaScriptCore/API/JSClassRef.cpp

    r83751 r91194  
    252252    if (!jsClassData.cachedPrototype) {
    253253        // Recursive, but should be good enough for our purposes
    254         jsClassData.cachedPrototype.set(exec->globalData(), new (exec) JSCallbackObject<JSObjectWithGlobalObject>(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData), 0); // set jsClassData as the object's private data, so it can clear our reference on destruction
     254        jsClassData.cachedPrototype.set(exec->globalData(), JSCallbackObject<JSObjectWithGlobalObject>::create(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData), 0); // set jsClassData as the object's private data, so it can clear our reference on destruction
    255255        if (parentClass) {
    256256            if (JSObject* prototype = parentClass->prototype(exec))
  • trunk/Source/JavaScriptCore/API/JSContextRef.cpp

    r86785 r91194  
    9898    }
    9999
    100     JSGlobalObject* globalObject = new (globalData.get()) JSCallbackObject<JSGlobalObject>(*globalData, globalObjectClass, JSCallbackObject<JSGlobalObject>::createStructure(*globalData, jsNull()));
     100    JSGlobalObject* globalObject = JSCallbackObject<JSGlobalObject>::create(*globalData, globalObjectClass, JSCallbackObject<JSGlobalObject>::createStructure(*globalData, jsNull()));
    101101    ExecState* exec = globalObject->globalExec();
    102102    JSValue prototype = globalObjectClass->prototype(exec);
  • trunk/Source/JavaScriptCore/API/JSObjectRef.cpp

    r83751 r91194  
    8282        return toRef(constructEmptyObject(exec));
    8383
    84     JSCallbackObject<JSObjectWithGlobalObject>* object = new (exec) JSCallbackObject<JSObjectWithGlobalObject>(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
     84    JSCallbackObject<JSObjectWithGlobalObject>* object = JSCallbackObject<JSObjectWithGlobalObject>::create(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
    8585    if (JSObject* prototype = jsClass->prototype(exec))
    8686        object->setPrototype(exec->globalData(), prototype);
     
    9696    Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
    9797   
    98     return toRef(new (exec) JSCallbackFunction(exec, exec->lexicalGlobalObject(), callAsFunction, nameID));
     98    return toRef(JSCallbackFunction::create(exec, exec->lexicalGlobalObject(), callAsFunction, nameID));
    9999}
    100100
     
    108108        jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
    109109
    110     JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);
     110    JSCallbackConstructor* constructor = JSCallbackConstructor::create(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);
    111111    constructor->putDirect(exec->globalData(), exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);
    112112    return toRef(constructor);
Note: See TracChangeset for help on using the changeset viewer.