Changeset 34659 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Jun 19, 2008, 10:29:29 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Darin.

Prepare JavaScript heap for being per-thread.

Location:
trunk/JavaScriptCore/API
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSBase.cpp

    r34581 r34659  
    2929
    3030#include "APICast.h"
     31#include "completion.h"
    3132#include <kjs/ExecState.h>
    3233#include <kjs/InitializeThreading.h>
     
    8687        initializeThreading();
    8788
     89    // It might seem that we have a context passed to this function, and can use toJS(ctx)->heap(), but the parameter is likely to be NULL,
     90    // and it may actually be garbage for some clients (most likely, because of JSGarbageCollect being called after releasing the context).
     91
    8892    JSLock lock;
    89     if (!Collector::isBusy())
    90         Collector::collect();
     93
     94    // FIXME: It would be good to avoid creating a JSGlobalData instance if it didn't exist for this thread yet.
     95    Heap* heap = JSGlobalData::threadInstance().heap;
     96    if (!heap->isBusy())
     97        heap->collect();
     98
     99    // FIXME: Similarly, we shouldn't create a shared instance here.
     100    heap = JSGlobalData::sharedInstance().heap;
     101    if (!heap->isBusy())
     102        heap->collect();
     103
    91104    // FIXME: Perhaps we should trigger a second mark and sweep
    92105    // once the garbage collector is done if this is called when
  • trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h

    r34607 r34659  
    471471            if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
    472472                if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
    473                     JSObject* o = new JSCallbackFunction(exec, callAsFunction, propertyName);
     473                    JSObject* o = new (exec) JSCallbackFunction(exec, callAsFunction, propertyName);
    474474                    thisObj->putDirect(propertyName, o, entry->attributes);
    475475                    return o;
  • trunk/JavaScriptCore/API/JSClassRef.cpp

    r34361 r34659  
    163163        if (!parentPrototype)
    164164            parentPrototype = exec->dynamicGlobalObject()->objectPrototype();
    165         cachedPrototype = new JSCallbackObject<JSObject>(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction
     165        cachedPrototype = new (exec) JSCallbackObject<JSObject>(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction
    166166    }
    167167    return cachedPrototype;
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r34581 r34659  
    4545
    4646    if (!globalObjectClass) {
    47         JSGlobalObject* globalObject = new JSGlobalObject;
     47        JSGlobalObject* globalObject = new (JSGlobalObject::Shared) JSGlobalObject;
    4848        return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
    4949    }
    5050
    51     JSGlobalObject* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass);
     51    JSGlobalObject* globalObject = new (JSGlobalObject::Shared) JSCallbackObject<JSGlobalObject>(globalObjectClass);
    5252    JSGlobalContextRef ctx = toGlobalRef(globalObject->globalExec());
    5353    JSValue* prototype = globalObjectClass->prototype(ctx);
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r34607 r34659  
    7575
    7676    if (!jsClass)
    77         return toRef(new JSObject(exec->lexicalGlobalObject()->objectPrototype())); // slightly more efficient
     77        return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->objectPrototype())); // slightly more efficient
    7878
    7979    JSValue* jsPrototype = jsClass->prototype(ctx);
     
    8181        jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
    8282
    83     return toRef(new JSCallbackObject<JSObject>(exec, jsClass, jsPrototype, data));
     83    return toRef(new (exec) JSCallbackObject<JSObject>(exec, jsClass, jsPrototype, data));
    8484}
    8585
     
    9090    Identifier nameID = name ? Identifier(exec, toJS(name)) : Identifier(exec, "anonymous");
    9191   
    92     return toRef(new JSCallbackFunction(exec, callAsFunction, nameID));
     92    return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID));
    9393}
    9494
     
    102102        : exec->dynamicGlobalObject()->objectPrototype();
    103103   
    104     JSCallbackConstructor* constructor = new JSCallbackConstructor(exec, jsClass, callAsConstructor);
     104    JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec, jsClass, callAsConstructor);
    105105    constructor->putDirect(exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);
    106106    return toRef(constructor);
     
    119119    ArgList args;
    120120    for (unsigned i = 0; i < parameterCount; i++)
    121         args.append(jsString(UString(toJS(parameterNames[i]))));
    122     args.append(jsString(UString(bodyRep)));
     121        args.append(jsString(exec, UString(toJS(parameterNames[i]))));
     122    args.append(jsString(exec, UString(bodyRep)));
    123123
    124124    JSObject* result = exec->dynamicGlobalObject()->functionConstructor()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
  • trunk/JavaScriptCore/API/JSValueRef.cpp

    r34581 r34659  
    177177}
    178178
    179 JSValueRef JSValueMakeNumber(JSContextRef, double value)
    180 {
    181     JSLock lock;
    182     return toRef(jsNumber(value));
    183 }
    184 
    185 JSValueRef JSValueMakeString(JSContextRef, JSStringRef string)
     179JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
     180{
     181    JSLock lock;
     182    return toRef(jsNumber(toJS(ctx), value));
     183}
     184
     185JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
    186186{
    187187    JSLock lock;
    188188    UString::Rep* rep = toJS(string);
    189     return toRef(jsString(UString(rep)));
     189    return toRef(jsString(toJS(ctx), UString(rep)));
    190190}
    191191
Note: See TracChangeset for help on using the changeset viewer.