Commit 2564df29 authored by ggaren's avatar ggaren
Browse files

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):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@15225 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 554ad6fb
......@@ -37,19 +37,19 @@ namespace KJS {
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);
......@@ -58,7 +58,7 @@ void JSCallbackObject::init(JSClassRef jsClass)
do {
if (JSInitializeCallback initialize = jsClass->callbacks.initialize)
initialize(thisRef);
initialize(context, thisRef);
} while ((jsClass = jsClass->parent));
}
......
......@@ -36,8 +36,8 @@ namespace KJS {
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;
......@@ -75,7 +75,7 @@ private:
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);
......
......@@ -40,7 +40,8 @@ JSContextRef JSContextCreate(JSClassRef globalObjectClass)
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();
......
......@@ -110,5 +110,5 @@ bool JSCheckSyntax(JSContextRef context, JSStringBufferRef script, JSStringBuffe
#ifdef __cplusplus
}
#endif
#endif // JSContextRef_h
......@@ -53,7 +53,7 @@ JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSObjectRef p
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)
......@@ -281,12 +281,11 @@ JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, J
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;
}
......
......@@ -57,15 +57,14 @@ typedef unsigned JSPropertyAttributes;
/*!
@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
......@@ -492,11 +491,10 @@ void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator);
/*!
@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
......
......@@ -122,7 +122,7 @@ static JSValueRef jsGlobalValue; // non-stack value for testing JSGCProtect()
/* 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);
......@@ -593,7 +593,7 @@ int main(int argc, char* argv[])
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.
......
......@@ -261,7 +261,7 @@ __ZNK3KJS8JSObject9classInfoEv
__ZNK3KJS8JSObject9classNameEv
__ZNK3KJS8JSObject9toBooleanEPNS_9ExecStateE
__ZNK3KJS9ExecState18lexicalInterpreterEv
__ZNK3KJS9Reference15getPropertyNameEPNS_9ExecStateE
__ZNK3KJS9Reference15getPropertyNameEv
__ZTVN3KJS19InternalFunctionImpE
__ZTVN3KJS8JSObjectE
_kJSObjectCallbacksNone
......
......@@ -251,7 +251,7 @@ void ArrayInstance::setLength(unsigned newLength, ExecState *exec)
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);
}
......@@ -373,7 +373,7 @@ unsigned ArrayInstance::pushUndefinedObjectsToEnd(ExecState *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++;
}
......
......@@ -1883,7 +1883,7 @@ Completion ForInNode::execute(ExecState *exec)
ReferenceListIterator propIt = propertyList.begin();
while (propIt != propertyList.end()) {
Identifier name = propIt->getPropertyName(exec);
Identifier name = propIt->getPropertyName();
if (!v->hasProperty(exec, name)) {
propIt++;
continue;
......
......@@ -43,7 +43,7 @@ Reference::Reference(JSObject *b, unsigned p)
{
}
Identifier Reference::getPropertyName(ExecState*) const
Identifier Reference::getPropertyName() const
{
if (propertyNameIsNumber && prop.isNull())
prop = Identifier::from(propertyNameAsNumber);
......@@ -55,7 +55,7 @@ JSValue *Reference::getValue(ExecState *exec) const
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");
}
......
......@@ -40,7 +40,7 @@ namespace KJS {
* 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
......
......@@ -48,7 +48,7 @@ void ScopeChain::print(ExecState* exec)
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");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment