Changeset 15133 in webkit for trunk/JavaScriptCore/API/minidom.js


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/minidom.js

    r14951 r15133  
    2626
    2727// For browser-based testing
    28 if (window) {
     28if (typeof window != 'undefined') {
    2929    /*
    3030    The methods and constructors below approximate what that the native host should provide
     
    6060    }
    6161
    62     Node.prototype.tag = "Node";
     62    Node.prototype.nodeType = "Node";
    6363
    6464    Node.prototype.appendChild = function(child) {
     
    7474
    7575        printSpaces(numSpaces);
    76         print('<' + this.tag + '>' + '\n');
     76        print('<' + this.nodeType + '>' + '\n');
    7777       
    7878        var childNodesLength = this.childNodes.length;
     
    8181       
    8282        printSpaces(numSpaces);
    83         print('</' + this.tag + '>\n');
     83        print('</' + this.nodeType + '>\n');
    8484    }
    8585
     
    9191    TextNode.prototype = new Node();
    9292   
    93     TextNode.prototype.tag = "Text";
     93    TextNode.prototype.nodeType = "Text";
    9494   
    9595    TextNode.prototype.serialize = function(numSpaces) {
     
    105105    Element.prototype = new Node();
    106106   
    107     Element.prototype.tag = "Element";
     107    Element.prototype.nodeType = "Element";
    108108
    109109    RootElement = function()
     
    113113    RootElement.prototype = new Element();
    114114
    115     RootElement.prototype.tag = "Root";
     115    RootElement.prototype.nodeType = "Root";
    116116   
    117117    HeroElement = function()
     
    121121    HeroElement.prototype = new Element();
    122122
    123     HeroElement.prototype.tag = "Hero";
     123    HeroElement.prototype.nodeType = "Hero";
    124124
    125125    VillainElement = function()
     
    129129    VillainElement.prototype = new Element();
    130130
    131     VillainElement.prototype.tag = "Villain";
     131    VillainElement.prototype.nodeType = "Villain";
    132132
    133133    NameElement = function()
     
    137137    NameElement.prototype = new Element();
    138138
    139     NameElement.prototype.tag = "Name";
     139    NameElement.prototype.nodeType = "Name";
    140140
    141141    WeaponElement = function()
     
    145145    WeaponElement.prototype = new Element();
    146146
    147     WeaponElement.prototype.tag = "Weapon";
     147    WeaponElement.prototype.nodeType = "Weapon";
    148148
    149149    Document = function()
     
    168168function test()
    169169{
     170    print("Node is " + Node);
     171    for (var p in Node)
     172        print(p + ": " + Node[p]);
     173   
     174    node = new Node();
     175    print("node is " + node);
     176    for (var p in node)
     177        print(p + ": " + node[p]);
     178
     179    child1 = new Node();
     180    child2 = new Node();
     181    child3 = new Node();
     182   
     183    node.appendChild(child1);
     184    node.appendChild(child2);
     185
     186    for (var i = 0; i < node.childNodes.length + 1; i++) {
     187        print("item " + i + ": " + node.childNodes.item(i));
     188    }
     189   
     190    for (var i = 0; i < node.childNodes.length + 1; i++) {
     191        print(i + ": " + node.childNodes[i]);
     192    }
     193
     194    node.removeChild(child1);
     195    node.replaceChild(child3, child2);
     196   
     197    for (var i = 0; i < node.childNodes.length + 1; i++) {
     198        print("item " + i + ": " + node.childNodes.item(i));
     199    }
     200
     201    for (var i = 0; i < node.childNodes.length + 1; i++) {
     202        print(i + ": " + node.childNodes[i]);
     203    }
     204
     205    try {
     206        node.appendChild(null);
     207    } catch(e) {
     208        print("caught: " + e);
     209    }
     210   
     211    try {
     212        var o = new Object();
     213        o.appendChild = node.appendChild;
     214        o.appendChild(node);
     215    } catch(e) {
     216        print("caught: " + e);
     217    }
     218   
     219    try {
     220        node.appendChild();
     221    } catch(e) {
     222        print("caught: " + e);
     223    }
     224
     225    /*
    170226    var element, name, weapon;
    171227   
     
    173229    document.appendChild(document.createElement('Root'));
    174230
    175     /* Tank Girl */
     231    // Tank Girl
    176232    element = document.createElement('Hero');
    177233
     
    195251
    196252
    197     /* Skeletor */
     253    // Skeletor
    198254    element = document.createElement('Villain');
    199255
     
    212268    document.firstChild.appendChild(element);
    213269
    214     /* Serialize */
     270    // Serialize
    215271    document.serialize();
     272    */
    216273}
     274
     275test();
Note: See TracChangeset for help on using the changeset viewer.