Changeset 14951 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Jun 21, 2006, 2:09:19 PM (19 years ago)
Author:
ggaren
Message:

JavaScriptCore:

Reviewed by Anders.


  • First cut at C API to JavaScript. Includes a unit test, 'testapi.c', and the outline of a test app, 'minidom.c'.


Includes one change to JSC internals: Rename propList to getPropertyList and have it
take its target property list by reference so that subclasses can
add properties to the list before calling through to their superclasses.


Also, I just ran prepare-ChangeLog in about 10 seconds, and I would like
to give a shout-out to that.


  • API/APICast.h: Added. (toJS): (toRef):
  • API/JSBase.h: Added.
  • API/JSCallbackObject.cpp: Added. (KJS::): (KJS::JSCallbackObject::JSCallbackObject): (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::setPrivate): (KJS::JSCallbackObject::getPrivate): (KJS::JSCallbackObject::cachedValueGetter): (KJS::JSCallbackObject::callbackGetter):
  • API/JSCallbackObject.h: Added. (KJS::JSCallbackObject::classInfo):
  • API/JSCharBufferRef.cpp: Added. (JSStringMake): (JSCharBufferCreate): (JSCharBufferCreateUTF8): (JSCharBufferRetain): (JSCharBufferRelease): (JSValueCopyStringValue): (JSCharBufferGetLength): (JSCharBufferGetCharactersPtr): (JSCharBufferGetCharacters): (JSCharBufferGetMaxLengthUTF8): (JSCharBufferGetCharactersUTF8): (JSCharBufferIsEqual): (JSCharBufferIsEqualUTF8): (JSCharBufferCreateWithCFString): (CFStringCreateWithJSCharBuffer):
  • API/JSCharBufferRef.h: Added.
  • API/JSContextRef.cpp: Added. (JSContextCreate): (JSContextDestroy): (JSContextGetGlobalObject): (JSEvaluate): (JSCheckSyntax): (JSContextHasException): (JSContextGetException): (JSContextClearException): (JSContextSetException):
  • API/JSContextRef.h: Added.
  • API/JSObjectRef.cpp: Added. (JSValueToObject): (JSObjectMake): (JSFunctionMake): (JSObjectGetDescription): (JSObjectGetPrototype): (JSObjectSetPrototype): (JSObjectHasProperty): (JSObjectGetProperty): (JSObjectSetProperty): (JSObjectDeleteProperty): (JSObjectGetPrivate): (JSObjectSetPrivate): (JSObjectIsFunction): (JSObjectCallAsFunction): (JSObjectIsConstructor): (JSObjectCallAsConstructor): (JSPropertyListEnumerator::JSPropertyListEnumerator): (JSObjectCreatePropertyEnumerator): (JSPropertyEnumeratorGetNext): (JSPropertyEnumeratorRetain): (JSPropertyEnumeratorRelease): (JSPropertyListAdd):
  • API/JSObjectRef.h: Added.
  • API/JSValueRef.cpp: Added. (JSValueGetType): (JSValueIsUndefined): (JSValueIsNull): (JSValueIsBoolean): (JSValueIsNumber): (JSValueIsString): (JSValueIsObject): (JSValueIsEqual): (JSValueIsStrictEqual): (JSUndefinedMake): (JSNullMake): (JSBooleanMake): (JSNumberMake): (JSValueToBoolean): (JSValueToNumber): (JSGCProtect): (JSGCUnprotect): (JSGCCollect):
  • API/JSValueRef.h: Added.
  • API/JavaScriptCore.h: Added.
  • API/minidom.c: Added. (main):
  • API/minidom.html: Added.
  • API/minidom.js: Added.
  • API/testapi.c: Added. (assertEqualsAsBoolean): (assertEqualsAsNumber): (assertEqualsAsUTF8String): (assertEqualsAsCharactersPtr): (assertEqualsAsCharacters): (MyObject_initialize): (MyObject_copyDescription): (MyObject_hasProperty): (MyObject_getProperty): (MyObject_setProperty): (MyObject_deleteProperty): (MyObject_getPropertyList): (MyObject_callAsFunction): (MyObject_callAsConstructor): (MyObject_convertToType): (MyObject_finalize): (print_callAsFunction): (main): (createStringWithContentsOfFile):
  • API/testapi.js: Added.
  • ChangeLog:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/npruntime_impl.h:
  • kjs/array_instance.h:
  • kjs/array_object.cpp: (ArrayInstance::getPropertyList):
  • kjs/interpreter.cpp: (KJS::Interpreter::evaluate):
  • kjs/nodes.cpp: (ForInNode::execute):
  • kjs/object.cpp: (KJS::JSObject::put): (KJS::JSObject::canPut): (KJS::JSObject::deleteProperty): (KJS::JSObject::propertyIsEnumerable): (KJS::JSObject::getPropertyAttributes): (KJS::JSObject::getPropertyList):
  • kjs/object.h:
  • kjs/property_map.cpp: (KJS::PropertyMap::get):
  • kjs/property_map.h:
  • kjs/scope_chain.cpp: (KJS::ScopeChain::print):
  • kjs/string_object.cpp: (StringInstance::getPropertyList):
  • kjs/string_object.h:
  • kjs/ustring.h: (KJS::UString::Rep::ref):

JavaScriptGlue:

Reviewed by Anders.


  • Required for JS API: Rename propList to getPropertyList and have it take its target property list by reference so that subclasses can add properties to the list before calling through to their superclasses.
  • JSUtils.cpp: (KJSValueToCFTypeInternal):
  • JSValueWrapper.cpp: (JSValueWrapper::JSObjectCopyPropertyNames):
  • UserObjectImp.cpp: (UserObjectImp::getPropertyList):
  • UserObjectImp.h:
Location:
trunk/JavaScriptCore/kjs
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_instance.h

    r12317 r14951  
    4040    virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    4141    virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
    42     virtual ReferenceList propList(ExecState *exec, bool recursive);
     42    virtual void getPropertyList(ExecState*, ReferenceList& propertyList, bool recursive);
    4343
    4444    virtual void mark();
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r14821 r14951  
    199199}
    200200
    201 ReferenceList ArrayInstance::propList(ExecState *exec, bool recursive)
    202 {
    203   ReferenceList properties = JSObject::propList(exec,recursive);
    204 
     201void ArrayInstance::getPropertyList(ExecState* exec, ReferenceList& propertyList, bool recursive)
     202{
    205203  // avoid fetching this every time through the loop
    206204  JSValue *undefined = jsUndefined();
     
    210208    JSValue *imp = storage[i];
    211209    if (imp && imp != undefined) {
    212       properties.append(Reference(this, i));
    213     }
    214   }
    215   return properties;
     210      propertyList.append(Reference(this, i));
     211    }
     212  }
     213  return JSObject::getPropertyList(exec, propertyList, recursive);
    216214}
    217215
  • trunk/JavaScriptCore/kjs/interpreter.cpp

    r14913 r14951  
    421421}
    422422
    423 Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue*)
    424 {
    425     return evaluate(sourceURL, startingLineNumber, code.data(), code.size());
     423Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
     424{
     425    return evaluate(sourceURL, startingLineNumber, code.data(), code.size(), thisV);
    426426}
    427427
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r14893 r14951  
    18591859  JSObject *v;
    18601860  Completion c;
    1861   ReferenceList propList;
     1861  ReferenceList propertyList;
    18621862
    18631863  if (varDecl) {
     
    18781878  KJS_CHECKEXCEPTION
    18791879  v = e->toObject(exec);
    1880   propList = v->propList(exec);
    1881 
    1882   ReferenceListIterator propIt = propList.begin();
    1883 
    1884   while (propIt != propList.end()) {
     1880  v->getPropertyList(exec, propertyList);
     1881
     1882  ReferenceListIterator propIt = propertyList.begin();
     1883
     1884  while (propIt != propertyList.end()) {
    18851885    Identifier name = propIt->getPropertyName(exec);
    18861886    if (!v->hasProperty(exec, name)) {
  • trunk/JavaScriptCore/kjs/object.cpp

    r13821 r14951  
    237237    obj = this;
    238238    while (true) {
    239       int attributes;
     239      unsigned attributes;
    240240      if (JSValue *gs = obj->_prop.get(propertyName, attributes)) {
    241241        if (attributes & GetterSetter) {
     
    278278bool JSObject::canPut(ExecState *, const Identifier &propertyName) const
    279279{
    280   int attributes;
     280  unsigned attributes;
    281281   
    282282  // Don't look in the prototype here. We can always put an override
     
    305305bool JSObject::deleteProperty(ExecState */*exec*/, const Identifier &propertyName)
    306306{
    307   int attributes;
     307  unsigned attributes;
    308308  JSValue *v = _prop.get(propertyName, attributes);
    309309  if (v) {
     
    453453bool JSObject::propertyIsEnumerable(ExecState*, const Identifier& propertyName) const
    454454{
    455   int attributes;
     455  unsigned attributes;
    456456 
    457457  if (!getPropertyAttributes(propertyName, attributes))
     
    461461}
    462462
    463 bool JSObject::getPropertyAttributes(const Identifier& propertyName, int& attributes) const
     463bool JSObject::getPropertyAttributes(const Identifier& propertyName, unsigned& attributes) const
    464464{
    465465  if (_prop.get(propertyName, attributes))
     
    476476}
    477477
    478 ReferenceList JSObject::propList(ExecState *exec, bool recursive)
    479 {
    480   ReferenceList list;
    481   if (_proto->isObject() && recursive)
    482     list = static_cast<JSObject*>(_proto)->propList(exec,recursive);
    483 
    484   _prop.addEnumerablesToReferenceList(list, this);
     478void JSObject::getPropertyList(ExecState *exec, ReferenceList& propertyList, bool recursive)
     479{
     480  _prop.addEnumerablesToReferenceList(propertyList, this);
    485481
    486482  // Add properties from the static hashtable of properties
     
    492488      for (int i = 0; i < size; ++i, ++e) {
    493489        if ( e->s && !(e->attr & DontEnum) )
    494           list.append(Reference(this, e->s)); /// ######### check for duplicates with the propertymap
     490          propertyList.append(Reference(this, e->s)); /// ######### check for duplicates with the propertymap
    495491      }
    496492    }
    497493    info = info->parentClass;
    498494  }
    499 
    500   return list;
     495  if (_proto->isObject() && recursive)
     496      static_cast<JSObject*>(_proto)->getPropertyList(exec, propertyList, recursive);
    501497}
    502498
  • trunk/JavaScriptCore/kjs/object.h

    r14256 r14951  
    457457     * @return A List of References to properties of the object.
    458458     **/
    459     virtual ReferenceList propList(ExecState *exec, bool recursive = true);
     459    virtual void getPropertyList(ExecState *exec, ReferenceList& propertyList, bool recursive = true);
    460460
    461461    /**
     
    478478    void setInternalValue(JSValue *v);
    479479
    480     JSValue *toPrimitive(ExecState *exec, JSType preferredType = UnspecifiedType) const;
    481     bool toBoolean(ExecState *exec) const;
    482     double toNumber(ExecState *exec) const;
    483     UString toString(ExecState *exec) const;
    484     JSObject *toObject(ExecState *exec) const;
     480    virtual JSValue *toPrimitive(ExecState *exec, JSType preferredType = UnspecifiedType) const;
     481    virtual bool toBoolean(ExecState *exec) const;
     482    virtual double toNumber(ExecState *exec) const;
     483    virtual UString toString(ExecState *exec) const;
     484    virtual JSObject *toObject(ExecState *exec) const;
    485485   
    486     bool getPropertyAttributes(const Identifier& propertyName, int& attributes) const;
     486    bool getPropertyAttributes(const Identifier& propertyName, unsigned& attributes) const;
    487487   
    488488    // Returns whether the object should be treated as undefined when doing equality comparisons
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r14256 r14951  
    160160}
    161161
    162 JSValue *PropertyMap::get(const Identifier &name, int &attributes) const
     162JSValue *PropertyMap::get(const Identifier &name, unsigned &attributes) const
    163163{
    164164    assert(!name.isNull());
  • trunk/JavaScriptCore/kjs/property_map.h

    r14256 r14951  
    7777        void remove(const Identifier &name);
    7878        JSValue *get(const Identifier &name) const;
    79         JSValue *get(const Identifier &name, int &attributes) const;
     79        JSValue *get(const Identifier &name, unsigned &attributes) const;
    8080        JSValue **getLocation(const Identifier &name);
    8181
  • trunk/JavaScriptCore/kjs/scope_chain.cpp

    r13960 r14951  
    4343    for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) {
    4444        JSObject* o = *scopeIter;
    45         ReferenceList propList = o->propList(exec, false);
    46         ReferenceListIterator propEnd = propList.end();
     45        ReferenceList propertyList;
     46        o->getPropertyList(exec, propertyList, false);
     47        ReferenceListIterator propEnd = propertyList.end();
    4748
    4849        fprintf(stderr, "----- [scope %p] -----\n", o);
    49         for (ReferenceListIterator propIter = propList.begin(); propIter != propEnd; propIter++) {
     50        for (ReferenceListIterator propIter = propertyList.begin(); propIter != propEnd; propIter++) {
    5051            Identifier name = propIter->getPropertyName(exec);
    5152            fprintf(stderr, "%s, ", name.ascii());
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r14821 r14951  
    9595}
    9696
    97 ReferenceList StringInstance::propList(ExecState *exec, bool recursive)
    98 {
    99   ReferenceList properties = JSObject::propList(exec,recursive);
    100 
     97void StringInstance::getPropertyList(ExecState *exec, ReferenceList& propertyList, bool recursive)
     98{
    10199  //### FIXME: should avoid duplicates with prototype
    102100  UString str = internalValue()->toString(exec);
    103101  for (int i = 0; i < str.size(); i++)
    104     properties.append(Reference(this, i));
    105   return properties;
     102    propertyList.append(Reference(this, i));
     103  return JSObject::getPropertyList(exec, propertyList, recursive);
    106104}
    107105
  • trunk/JavaScriptCore/kjs/string_object.h

    r13821 r14951  
    3535    virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
    3636    virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    37     virtual ReferenceList propList(ExecState *exec, bool recursive);
     37    virtual void getPropertyList(ExecState *exec, ReferenceList& propertyList, bool recursive);
    3838
    3939    virtual const ClassInfo *classInfo() const { return &info; }
  • trunk/JavaScriptCore/kjs/ustring.h

    r14734 r14951  
    193193      static unsigned computeHash(const char *);
    194194
    195       void ref() { ++rc; }
     195      Rep* ref() { ++rc; return this; }
    196196      void deref() { if (--rc == 0) destroy(); }
    197197
Note: See TracChangeset for help on using the changeset viewer.