+2005-07-01 Geoffrey Garen <ggaren@apple.com>
+
+ -landed patch by Eric Seidel <macdome@opendarwin.org>
+
+ -for http://bugzilla.opendarwin.org/show_bug.cgi?id=3657
+ GroundWork: Moving some functions from khtml->jsc following kjs TOT
+
+ - no layout test necessary yet - only groundwork
+
+ Reviewed by darin.
+
+ * kjs/lookup.h:
+ (KJS::cacheGlobalObject):
+
2005-07-01 Geoffrey Garen <ggaren@apple.com>
-landed patch by Carsten Guenther <cguenther@gmail.com>
#ifndef _KJSLOOKUP_H_
#define _KJSLOOKUP_H_
+#include "interpreter.h"
#include "identifier.h"
#include "object.h"
#include <stdio.h>
else
thisObj->putValueProperty(exec, entry->value, value, attr);
}
+
+ /**
+ * This template method retrieves or create an object that is unique
+ * (for a given interpreter) The first time this is called (for a given
+ * property name), the Object will be constructed, and set as a property
+ * of the interpreter's global object. Later calls will simply retrieve
+ * that cached object. Note that the object constructor must take 1 argument, exec.
+ */
+ template <class ClassCtor>
+ inline ObjectImp *cacheGlobalObject(ExecState *exec, const Identifier &propertyName)
+ {
+ ObjectImp *globalObject = static_cast<ObjectImp *>(exec->lexicalInterpreter()->globalObject().imp());
+ ValueImp *obj = globalObject->getDirect(propertyName);
+ if (obj) {
+ assert(obj->isObject());
+ return static_cast<ObjectImp *>(obj);
+ }
+ ObjectImp *newObject = new ClassCtor(exec);
+ globalObject->put(exec, propertyName, Value(newObject), Internal);
+ return newObject;
+ }
+
+ /**
+ * Helpers to define prototype objects (each of which simply implements
+ * the functions for a type of objects).
+ * Sorry for this not being very readable, but it actually saves much copy-n-paste.
+ * ParentProto is not our base class, it's the object we use as fallback.
+ * The reason for this is that there should only be ONE DOMNode.hasAttributes (e.g.),
+ * not one in each derived class. So we link the (unique) prototypes between them.
+ *
+ * Using those macros is very simple: define the hashtable (e.g. "DOMNodeProtoTable"), then
+ * DEFINE_PROTOTYPE("DOMNode",DOMNodeProto)
+ * IMPLEMENT_PROTOFUNC(DOMNodeProtoFunc)
+ * IMPLEMENT_PROTOTYPE(DOMNodeProto,DOMNodeProtoFunc)
+ * and use DOMNodeProto::self(exec) as prototype in the DOMNode constructor.
+ * If the prototype has a "parent prototype", e.g. DOMElementProto falls back on DOMNodeProto,
+ * then the last line will use IMPLEMENT_PROTOTYPE_WITH_PARENT, with DOMNodeProto as last argument.
+ */
+#define DEFINE_PROTOTYPE(ClassName,ClassProto) \
+ class ClassProto : public ObjectImp { \
+ friend ObjectImp *cacheGlobalObject<ClassProto>(ExecState *exec, const Identifier &propertyName); \
+ public: \
+ static ObjectImp *self(ExecState *exec) \
+ { \
+ return cacheGlobalObject<ClassProto>( exec, "[[" ClassName ".prototype]]" ); \
+ } \
+ protected: \
+ ClassProto( ExecState *exec ) \
+ : ObjectImp( exec->lexicalInterpreter()->builtinObjectPrototype() ) {} \
+ \
+ public: \
+ virtual const ClassInfo *classInfo() const { return &info; } \
+ static const ClassInfo info; \
+ Value get(ExecState *exec, const Identifier &propertyName) const; \
+ bool hasProperty(ExecState *exec, const Identifier &propertyName) const; \
+ }; \
+ const ClassInfo ClassProto::info = { ClassName, 0, &ClassProto##Table, 0 };
+
+#define IMPLEMENT_PROTOTYPE(ClassProto,ClassFunc) \
+ Value ClassProto::get(ExecState *exec, const Identifier &propertyName) const \
+ { \
+ /*fprintf( stderr, "%sProto::get(%s) [in macro, no parent]\n", info.className, propertyName.ascii());*/ \
+ return lookupGetFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this ); \
+ } \
+ bool ClassProto::hasProperty(ExecState *exec, const Identifier &propertyName) const \
+ { /*stupid but we need this to have a common macro for the declaration*/ \
+ return ObjectImp::hasProperty(exec, propertyName); \
+ }
+
+#define IMPLEMENT_PROTOTYPE_WITH_PARENT(ClassProto,ClassFunc,ParentProto) \
+ Value ClassProto::get(ExecState *exec, const Identifier &propertyName) const \
+ { \
+ /*fprintf( stderr, "%sProto::get(%s) [in macro]\n", info.className, propertyName.ascii());*/ \
+ Value val = lookupGetFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this ); \
+ if ( val.type() != UndefinedType ) return val; \
+ /* Not found -> forward request to "parent" prototype */ \
+ return ParentProto::self(exec)->get( exec, propertyName ); \
+ } \
+ bool ClassProto::hasProperty(ExecState *exec, const Identifier &propertyName) const \
+ { \
+ if (ObjectImp::hasProperty(exec, propertyName)) \
+ return true; \
+ return ParentProto::self(exec)->hasProperty(exec, propertyName); \
+ }
+
+#define IMPLEMENT_PROTOFUNC(ClassFunc) \
+ class ClassFunc : public DOMFunction { \
+ public: \
+ ClassFunc(ExecState *exec, int i, int len) \
+ : DOMFunction( /*proto? */ ), id(i) { \
+ Value protect(this); \
+ put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); \
+ } \
+ /** You need to implement that one */ \
+ virtual Value tryCall(ExecState *exec, Object &thisObj, const List &args); \
+ private: \
+ int id; \
+ };
/*
* List of things to do when porting an objectimp to the 'static hashtable' mechanism:
+2005-07-01 Geoffrey Garen <ggaren@apple.com>
+
+ -landed patch by Eric Seidel <macdome@opendarwin.org>
+
+ -for http://bugzilla.opendarwin.org/show_bug.cgi?id=3657
+ GroundWork: Moving some functions from khtml->jsc following kjs TOT
+
+ - no layout test necessary yet - only groundwork
+
+ Reviewed by darin.
+
+ * ForwardingHeaders/qintdict.h:
+ * khtml/ecma/kjs_binding.h:
+
2005-07-01 Geoffrey Garen <ggaren@apple.com>
-landed patch by Carsten Guenther <cguenther@gmail.com>
+#import <KWQIntDict.h>
+
#import "KWQIntDict.h"
thisObj->putValue(exec, entry->value, value, attr);
}
- /**
- * This template method retrieves or create an object that is unique
- * (for a given interpreter) The first time this is called (for a given
- * property name), the Object will be constructed, and set as a property
- * of the interpreter's global object. Later calls will simply retrieve
- * that cached object. Note that the object constructor must take 1 argument, exec.
- */
- template <class ClassCtor>
- inline ObjectImp *cacheGlobalObject(ExecState *exec, const Identifier &propertyName)
- {
- ObjectImp *globalObject = static_cast<ObjectImp *>(exec->lexicalInterpreter()->globalObject().imp());
- ValueImp *obj = globalObject->getDirect(propertyName);
- if (obj) {
- assert(obj->isObject());
- return static_cast<ObjectImp *>(obj);
- }
- ObjectImp *newObject = new ClassCtor(exec);
- globalObject->put(exec, propertyName, Value(newObject), Internal);
- return newObject;
- }
-
- /**
- * Helpers to define prototype objects (each of which simply implements
- * the functions for a type of objects).
- * Sorry for this not being very readable, but it actually saves much copy-n-paste.
- * ParentProto is not our base class, it's the object we use as fallback.
- * The reason for this is that there should only be ONE DOMNode.hasAttributes (e.g.),
- * not one in each derived class. So we link the (unique) prototypes between them.
- *
- * Using those macros is very simple: define the hashtable (e.g. "DOMNodeProtoTable"), then
- * DEFINE_PROTOTYPE("DOMNode",DOMNodeProto)
- * IMPLEMENT_PROTOFUNC(DOMNodeProtoFunc)
- * IMPLEMENT_PROTOTYPE(DOMNodeProto,DOMNodeProtoFunc)
- * and use DOMNodeProto::self(exec) as prototype in the DOMNode constructor.
- * If the prototype has a "parent prototype", e.g. DOMElementProto falls back on DOMNodeProto,
- * then the last line will use IMPLEMENT_PROTOTYPE_WITH_PARENT, with DOMNodeProto as last argument.
- */
-#define DEFINE_PROTOTYPE(ClassName,ClassProto) \
- class ClassProto : public ObjectImp { \
- friend ObjectImp *cacheGlobalObject<ClassProto>(ExecState *exec, const Identifier &propertyName); \
- public: \
- static ObjectImp *self(ExecState *exec) \
- { \
- return cacheGlobalObject<ClassProto>( exec, "[[" ClassName ".prototype]]" ); \
- } \
- protected: \
- ClassProto( ExecState *exec ) \
- : ObjectImp( exec->lexicalInterpreter()->builtinObjectPrototype() ) {} \
- \
- public: \
- virtual const ClassInfo *classInfo() const { return &info; } \
- static const ClassInfo info; \
- Value get(ExecState *exec, const Identifier &propertyName) const; \
- bool hasProperty(ExecState *exec, const Identifier &propertyName) const; \
- }; \
- const ClassInfo ClassProto::info = { ClassName, 0, &ClassProto##Table, 0 };
-
-#define IMPLEMENT_PROTOTYPE(ClassProto,ClassFunc) \
- Value ClassProto::get(ExecState *exec, const Identifier &propertyName) const \
- { \
- /*fprintf( stderr, "%sProto::get(%s) [in macro, no parent]\n", info.className, propertyName.ascii());*/ \
- return lookupGetFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this ); \
- } \
- bool ClassProto::hasProperty(ExecState *exec, const Identifier &propertyName) const \
- { /*stupid but we need this to have a common macro for the declaration*/ \
- return ObjectImp::hasProperty(exec, propertyName); \
- }
-
-#define IMPLEMENT_PROTOTYPE_WITH_PARENT(ClassProto,ClassFunc,ParentProto) \
- Value ClassProto::get(ExecState *exec, const Identifier &propertyName) const \
- { \
- /*fprintf( stderr, "%sProto::get(%s) [in macro]\n", info.className, propertyName.ascii());*/ \
- Value val = lookupGetFunction<ClassFunc,ObjectImp>(exec, propertyName, &ClassProto##Table, this ); \
- if ( val.type() != UndefinedType ) return val; \
- /* Not found -> forward request to "parent" prototype */ \
- return ParentProto::self(exec)->get( exec, propertyName ); \
- } \
- bool ClassProto::hasProperty(ExecState *exec, const Identifier &propertyName) const \
- { \
- if (ObjectImp::hasProperty(exec, propertyName)) \
- return true; \
- return ParentProto::self(exec)->hasProperty(exec, propertyName); \
- }
-
-#define IMPLEMENT_PROTOFUNC(ClassFunc) \
- class ClassFunc : public DOMFunction { \
- public: \
- ClassFunc(ExecState *exec, int i, int len) \
- : DOMFunction( /*proto? */ ), id(i) { \
- Value protect(this); \
- put(exec,lengthPropertyName,Number(len),DontDelete|ReadOnly|DontEnum); \
- } \
- /** You need to implement that one */ \
- virtual Value tryCall(ExecState *exec, Object &thisObj, const List &args); \
- private: \
- int id; \
- };
-
} // namespace
#endif