Ignore:
Timestamp:
Jul 1, 2006, 9:06:07 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Phase 2 in the JS API.


  • Added support for specifying static tables of values -- this should obviate the need for using complicated callbacks for most lookups.


  • API objects are now created with classes (JSClassRef) -- in order to support static values, and in order to prevent API objects from storing their data inline, and thus falling into the oversized (read: slow and prone to giving Maciej the frowny face) heap.


  • Added two specialized JSObject subclasses -- JSCallbackFunction and JSCallbackConstructor -- to allow JSFunctionMake and JSConstructorMake to continue to work with the new class model. Another solution to this problem would be to create a custom class object for each function and constructor you make. This solution is more code but also more efficient.


  • Substantially beefed up the minidom example to demonstrate and test a lot of these techniques. Its output is still pretty haphazard, though.


  • Gave the <kjs/ preface to some includes -- I'm told this matters to building on some versions of Linux.


  • Implemented JSValueIsInstanceOf and JSValueIsObjectOfClass


  • Removed GetDescription callback. Something in the class datastructure should take care of this.
  • API/JSBase.h:
  • API/JSCallbackConstructor.cpp: Added. (KJS::): (KJS::JSCallbackConstructor::JSCallbackConstructor): (KJS::JSCallbackConstructor::implementsConstruct): (KJS::JSCallbackConstructor::construct): (KJS::JSCallbackConstructor::setPrivate): (KJS::JSCallbackConstructor::getPrivate):
  • API/JSCallbackConstructor.h: Added. (KJS::JSCallbackConstructor::classInfo):
  • API/JSCallbackFunction.cpp: Added. (KJS::): (KJS::JSCallbackFunction::JSCallbackFunction): (KJS::JSCallbackFunction::implementsCall): (KJS::JSCallbackFunction::callAsFunction): (KJS::JSCallbackFunction::setPrivate): (KJS::JSCallbackFunction::getPrivate):
  • API/JSCallbackFunction.h: Added. (KJS::JSCallbackFunction::classInfo):
  • API/JSCallbackObject.cpp: (KJS::): (KJS::JSCallbackObject::JSCallbackObject): (KJS::JSCallbackObject::init): (KJS::JSCallbackObject::~JSCallbackObject): (KJS::JSCallbackObject::className): (KJS::JSCallbackObject::getOwnPropertySlot): (KJS::JSCallbackObject::put): (KJS::JSCallbackObject::deleteProperty): (KJS::JSCallbackObject::implementsConstruct): (KJS::JSCallbackObject::construct): (KJS::JSCallbackObject::implementsCall): (KJS::JSCallbackObject::callAsFunction): (KJS::JSCallbackObject::getPropertyList): (KJS::JSCallbackObject::toBoolean): (KJS::JSCallbackObject::toNumber): (KJS::JSCallbackObject::toString): (KJS::JSCallbackObject::inherits): (KJS::JSCallbackObject::staticValueGetter): (KJS::JSCallbackObject::staticFunctionGetter): (KJS::JSCallbackObject::callbackGetter):
  • API/JSCallbackObject.h:
  • API/JSCharBufferRef.cpp:
  • API/JSClassRef.cpp: Added. (JSClassCreate): (JSClassRetain): (JSClassRelease):
  • API/JSClassRef.h: Added. (StaticValueEntry::StaticValueEntry): (StaticFunctionEntry::StaticFunctionEntry): (JSClass::JSClass):
  • API/JSContextRef.cpp: (JSContextCreate): (JSEvaluate):
  • API/JSContextRef.h:
  • API/JSNode.c: Added. (JSNodePrototype_appendChild): (JSNodePrototype_removeChild): (JSNodePrototype_replaceChild): (JSNodePrototype_class): (JSNode_getNodeType): (JSNode_getChildNodes): (JSNode_getFirstChild): (JSNode_finalize): (JSNode_class): (JSNode_prototype): (JSNode_new): (JSNode_construct):
  • API/JSNode.h: Added.
  • API/JSNodeList.c: Added. (JSNodeListPrototype_item): (JSNodeListPrototype_class): (JSNodeList_length): (JSNodeList_getProperty): (JSNodeList_finalize): (JSNodeList_class): (JSNodeList_prototype): (JSNodeList_new):
  • API/JSNodeList.h: Added.
  • API/JSObjectRef.cpp: (JSObjectMake): (JSFunctionMake): (JSConstructorMake): (JSPropertyEnumerator::JSPropertyEnumerator): (JSObjectCreatePropertyEnumerator): (JSPropertyEnumeratorGetNext): (JSPropertyEnumeratorRetain): (JSPropertyEnumeratorRelease):
  • API/JSObjectRef.h: (JSObjectCallbacks::):
  • API/JSValueRef.cpp: (JSValueIsObjectOfClass): (JSValueIsInstanceOf):
  • API/JSValueRef.h:
  • API/Node.c: Added. (Node_new): (Node_appendChild): (Node_removeChild): (Node_replaceChild): (Node_ref): (Node_deref):
  • API/Node.h: Added.
  • API/NodeList.c: Added. (NodeList_new): (NodeList_length): (NodeList_item): (NodeList_ref): (NodeList_deref):
  • API/NodeList.h: Added.
  • API/minidom.c: (main): (print): (createStringWithContentsOfFile):
  • API/minidom.js:
  • API/testapi.c: (assertEqualsAsCharacters): (MyObject_getProperty): (MyObject_class): (myConstructor_callAsConstructor): (main):
  • API/testapi.js:
  • JavaScriptCore.xcodeproj/project.pbxproj:
File:
1 edited

Legend:

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

    r15043 r15133  
    2828#include "JSValueRef.h"
    2929#include "JSObjectRef.h"
     30#include "JSCallbackConstructor.h"
     31#include "JSCallbackFunction.h"
    3032#include "JSCallbackObject.h"
    3133
     
    3638
    3739using namespace KJS;
    38 
    39 const JSObjectCallbacks kJSObjectCallbacksNone = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    4040
    4141JSObjectRef JSValueToObject(JSContextRef context, JSValueRef value)
     
    5252}   
    5353
    54 JSObjectRef JSObjectMake(JSContextRef context, const JSObjectCallbacks* callbacks, JSObjectRef prototype)
     54JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSObjectRef prototype)
    5555{
    5656    JSLock lock;
     
    6262        jsPrototype = exec->lexicalInterpreter()->builtinObjectPrototype();
    6363
    64     if (callbacks == &kJSObjectCallbacksNone)
     64    if (!jsClass)
    6565        return toRef(new JSObject(jsPrototype)); // slightly more efficient
    6666    else
    67         return toRef(new JSCallbackObject(callbacks, jsPrototype));
     67        return toRef(new JSCallbackObject(jsClass, jsPrototype));
    6868}
    6969
    7070JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callback)
    7171{
    72     ExecState* exec = toJS(context);
    73     JSObjectCallbacks callbacks = kJSObjectCallbacksNone;
    74     callbacks.callAsFunction = callback;
    75 
    76     return JSObjectMake(context, &callbacks, toRef(exec->lexicalInterpreter()->builtinFunctionPrototype()));
     72    JSLock lock;
     73    ExecState* exec = toJS(context);
     74    return toRef(new JSCallbackFunction(exec, callback));
    7775}
    7876
    7977JSObjectRef JSConstructorMake(JSContextRef context, JSCallAsConstructorCallback callback)
    8078{
    81     ExecState* exec = toJS(context);
    82     JSObjectCallbacks callbacks = kJSObjectCallbacksNone;
    83     callbacks.callAsConstructor = callback;
    84    
    85     return JSObjectMake(context, &callbacks, toRef(exec->lexicalInterpreter()->builtinObjectPrototype()));
     79    JSLock lock;
     80    ExecState* exec = toJS(context);
     81    return toRef(new JSCallbackConstructor(exec, callback));
    8682}
    8783
     
    224220}
    225221
    226 struct __JSPropertyListEnumerator
    227 {
    228     __JSPropertyListEnumerator() : refCount(0), iterator(list.end())
     222struct __JSPropertyEnumerator
     223{
     224    __JSPropertyEnumerator() : refCount(0), iterator(list.end())
    229225    {
    230226    }
     
    235231};
    236232
    237 JSPropertyListEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object)
    238 {
    239     JSLock lock;
    240     ExecState* exec = toJS(context);
    241     JSObject* jsObject = toJS(object);
    242    
    243     JSPropertyListEnumeratorRef enumerator = new __JSPropertyListEnumerator();
     233JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object)
     234{
     235    JSLock lock;
     236    ExecState* exec = toJS(context);
     237    JSObject* jsObject = toJS(object);
     238   
     239    JSPropertyEnumeratorRef enumerator = new __JSPropertyEnumerator();
    244240    jsObject->getPropertyList(exec, enumerator->list);
    245241    enumerator->iterator = enumerator->list.begin();
    246242   
    247     return enumerator;
    248 }
    249 
    250 JSCharBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyListEnumeratorRef enumerator)
     243    return JSPropertyEnumeratorRetain(enumerator);
     244}
     245
     246JSCharBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyEnumeratorRef enumerator)
    251247{
    252248    ExecState* exec = toJS(context);
     
    259255}
    260256
    261 JSPropertyListEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyListEnumeratorRef enumerator)
     257JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator)
    262258{
    263259    ++enumerator->refCount;
     
    265261}
    266262
    267 void JSPropertyEnumeratorRelease(JSPropertyListEnumeratorRef enumerator)
     263void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator)
    268264{
    269265    if (--enumerator->refCount == 0)
Note: See TracChangeset for help on using the changeset viewer.