- Standardized which functions take a JSContext as an argument. The rule is:
if you might execute JavaScript, you take a JSContext, otherwise you don't.
The FIXME in JSObjectRef.h requires refactoring some parts of Interpreter,
but not API changes, so I'm putting it off until later.
* API/JSCallbackObject.cpp:
(KJS::JSCallbackObject::JSCallbackObject):
(KJS::JSCallbackObject::init):
* API/JSCallbackObject.h:
* API/JSContextRef.cpp:
(JSContextCreate):
* API/JSContextRef.h:
* API/JSObjectRef.cpp:
(JSObjectMake):
(JSPropertyEnumeratorGetNext):
* API/JSObjectRef.h:
* API/testapi.c:
(MyObject_initialize):
(main):
* JavaScriptCore.exp:
* kjs/array_object.cpp:
(ArrayInstance::setLength):
(ArrayInstance::pushUndefinedObjectsToEnd):
* kjs/nodes.cpp:
(ForInNode::execute):
* kjs/reference.cpp:
(KJS::Reference::getPropertyName):
(KJS::Reference::getValue):
* kjs/reference.h:
* kjs/scope_chain.cpp:
(KJS::ScopeChain::print):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15225
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
const ClassInfo JSCallbackObject::info = { "CallbackObject", 0, 0, 0 };
-JSCallbackObject::JSCallbackObject(JSClassRef jsClass)
+JSCallbackObject::JSCallbackObject(JSContextRef context, JSClassRef jsClass)
: JSObject()
{
- init(jsClass);
+ init(context, jsClass);
}
-JSCallbackObject::JSCallbackObject(JSClassRef jsClass, JSObject* prototype)
+JSCallbackObject::JSCallbackObject(JSContextRef context, JSClassRef jsClass, JSObject* prototype)
: JSObject(prototype)
{
- init(jsClass);
+ init(context, jsClass);
}
-void JSCallbackObject::init(JSClassRef jsClass)
+void JSCallbackObject::init(JSContextRef context, JSClassRef jsClass)
{
m_privateData = 0;
m_class = JSClassRetain(jsClass);
do {
if (JSInitializeCallback initialize = jsClass->callbacks.initialize)
- initialize(thisRef);
+ initialize(context, thisRef);
} while ((jsClass = jsClass->parent));
}
class JSCallbackObject : public JSObject
{
public:
- JSCallbackObject(JSClassRef globalObjectClass);
- JSCallbackObject(JSClassRef globalObjectClass, JSObject* prototype);
+ JSCallbackObject(JSContextRef, JSClassRef);
+ JSCallbackObject(JSContextRef, JSClassRef, JSObject* prototype);
virtual ~JSCallbackObject();
virtual UString className() const;
JSCallbackObject(); // prevent default construction
JSCallbackObject(const JSCallbackObject&);
- void init(JSClassRef jsClass);
+ void init(JSContextRef, JSClassRef);
static JSValue* cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
static JSValue* staticValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
JSObject* globalObject;
if (globalObjectClass)
- globalObject = new JSCallbackObject(globalObjectClass);
+ // FIXME: We need to pass a real ExecState here to support an initialize callback in globalObjectClass
+ globalObject = new JSCallbackObject(0, globalObjectClass);
else
globalObject = new JSObject();
#ifdef __cplusplus
}
#endif
-
+
#endif // JSContextRef_h
if (!jsClass)
return toRef(new JSObject(jsPrototype)); // slightly more efficient
else
- return toRef(new JSCallbackObject(jsClass, jsPrototype));
+ return toRef(new JSCallbackObject(context, jsClass, jsPrototype));
}
JSObjectRef JSFunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction)
return JSPropertyEnumeratorRetain(enumerator);
}
-JSStringBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyEnumeratorRef enumerator)
+JSStringBufferRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator)
{
- ExecState* exec = toJS(context);
ReferenceListIterator& iterator = enumerator->iterator;
if (iterator != enumerator->list.end()) {
- JSStringBufferRef result = toRef(iterator->getPropertyName(exec).ustring().rep());
+ JSStringBufferRef result = toRef(iterator->getPropertyName().ustring().rep());
iterator++;
return result;
}
/*!
@typedef JSInitializeCallback
@abstract The callback invoked when an object is first created.
+@param context The execution context to use.
@param object The JSObject being created.
@discussion If you named your function Initialize, you would declare it like this:
-void Initialize(JSObjectRef object);
+void Initialize(JSContextRef context, JSObjectRef object);
*/
-
-// FIXME: Needs to take a context argument, but can't because no context exists when we're creating the global object
typedef void
-(*JSInitializeCallback) (JSObjectRef object);
+(*JSInitializeCallback) (JSContextRef context, JSObjectRef object);
/*!
@typedef JSFinalizeCallback
/*!
@function
@abstract Gets a property enumerator's next property.
-@param context The execution context to use.
@param enumerator The JSPropertyEnumerator whose next property you want to get.
@result A JSStringBuffer containing the property's name, or NULL if all properties have been enumerated.
*/
-JSStringBufferRef JSPropertyEnumeratorGetNext(JSContextRef context, JSPropertyEnumeratorRef enumerator);
+JSStringBufferRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator);
/*!
@function
/* MyObject pseudo-class */
static bool didInitialize = false;
-static void MyObject_initialize(JSObjectRef object)
+static void MyObject_initialize(JSContextRef context, JSObjectRef object)
{
UNUSED_PARAM(context);
UNUSED_PARAM(object);
JSObjectSetProperty(context, o, jsCFString, JSNumberMake(1), kJSPropertyAttributeDontEnum);
JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(context, o);
int count = 0;
- while (JSPropertyEnumeratorGetNext(context, enumerator))
+ while (JSPropertyEnumeratorGetNext(enumerator))
++count;
JSPropertyEnumeratorRelease(enumerator);
assert(count == 1); // jsCFString should not be enumerated
+2006-07-07 Geoffrey Garen <ggaren@apple.com>
+
+ Reviewed by Maciej.
+
+ - Standardized which functions take a JSContext as an argument. The rule is:
+ if you might execute JavaScript, you take a JSContext, otherwise you don't.
+
+ The FIXME in JSObjectRef.h requires refactoring some parts of Interpreter,
+ but not API changes, so I'm putting it off until later.
+
+ * API/JSCallbackObject.cpp:
+ (KJS::JSCallbackObject::JSCallbackObject):
+ (KJS::JSCallbackObject::init):
+ * API/JSCallbackObject.h:
+ * API/JSContextRef.cpp:
+ (JSContextCreate):
+ * API/JSContextRef.h:
+ * API/JSObjectRef.cpp:
+ (JSObjectMake):
+ (JSPropertyEnumeratorGetNext):
+ * API/JSObjectRef.h:
+ * API/testapi.c:
+ (MyObject_initialize):
+ (main):
+ * JavaScriptCore.exp:
+ * kjs/array_object.cpp:
+ (ArrayInstance::setLength):
+ (ArrayInstance::pushUndefinedObjectsToEnd):
+ * kjs/nodes.cpp:
+ (ForInNode::execute):
+ * kjs/reference.cpp:
+ (KJS::Reference::getPropertyName):
+ (KJS::Reference::getValue):
+ * kjs/reference.h:
+ * kjs/scope_chain.cpp:
+ (KJS::ScopeChain::print):
+
2006-07-06 Geoffrey Garen <ggaren@apple.com>
Reviewed by Maciej.
__ZNK3KJS8JSObject9classNameEv
__ZNK3KJS8JSObject9toBooleanEPNS_9ExecStateE
__ZNK3KJS9ExecState18lexicalInterpreterEv
-__ZNK3KJS9Reference15getPropertyNameEPNS_9ExecStateE
+__ZNK3KJS9Reference15getPropertyNameEv
__ZTVN3KJS19InternalFunctionImpE
__ZTVN3KJS8JSObjectE
_kJSObjectCallbacksNone
while (it != sparseProperties.end()) {
Reference ref = it++;
bool ok;
- unsigned index = ref.getPropertyName(exec).toArrayIndex(&ok);
+ unsigned index = ref.getPropertyName().toArrayIndex(&ok);
if (ok && index > newLength) {
ref.deleteValue(exec);
}
while (it != sparseProperties.end()) {
Reference ref = it++;
storage[o] = ref.getValue(exec);
- JSObject::deleteProperty(exec, ref.getPropertyName(exec));
+ JSObject::deleteProperty(exec, ref.getPropertyName());
o++;
}
ReferenceListIterator propIt = propertyList.begin();
while (propIt != propertyList.end()) {
- Identifier name = propIt->getPropertyName(exec);
+ Identifier name = propIt->getPropertyName();
if (!v->hasProperty(exec, name)) {
propIt++;
continue;
{
}
-Identifier Reference::getPropertyName(ExecState*) const
+Identifier Reference::getPropertyName() const
{
if (propertyNameIsNumber && prop.isNull())
prop = Identifier::from(propertyNameAsNumber);
JSValue *o = base;
if (!o || !o->isObject()) {
if (!o || o->isNull())
- return throwError(exec, ReferenceError, "Can't find variable: " + getPropertyName(exec).ustring());
+ return throwError(exec, ReferenceError, "Can't find variable: " + getPropertyName().ustring());
return throwError(exec, ReferenceError, "Base is not an object");
}
* Performs the GetPropertyName type conversion operation on this value
* (ECMA 8.7)
*/
- Identifier getPropertyName(ExecState *exec) const;
+ Identifier getPropertyName() const;
/**
* Performs the GetValue type conversion operation on this value
fprintf(stderr, "----- [scope %p] -----\n", o);
for (ReferenceListIterator propIter = propertyList.begin(); propIter != propEnd; propIter++) {
- Identifier name = propIter->getPropertyName(exec);
+ Identifier name = propIter->getPropertyName();
fprintf(stderr, "%s, ", name.ascii());
}
fprintf(stderr, "\n");