Commit 89c5d677 authored by andersca's avatar andersca
Browse files

JavaScriptCore:

        Reviewed by Geoff.

        Make sure that bindings instances get correct root objects.
        
        * JavaScriptCore.exp:
        * bindings/NP_jsobject.cpp:
        (listFromVariantArgs):
        (_NPN_InvokeDefault):
        (_NPN_Invoke):
        (_NPN_SetProperty):
        * bindings/c/c_instance.cpp:
        (KJS::Bindings::CInstance::invokeMethod):
        (KJS::Bindings::CInstance::invokeDefaultMethod):
        * bindings/c/c_runtime.cpp:
        (KJS::Bindings::CField::valueFromInstance):
        * bindings/c/c_utility.cpp:
        (KJS::Bindings::convertNPVariantToValue):
        * bindings/c/c_utility.h:
        * bindings/objc/objc_instance.mm:
        (ObjcInstance::invokeMethod):
        (ObjcInstance::invokeDefaultMethod):
        (ObjcInstance::getValueOfUndefinedField):
        * bindings/objc/objc_runtime.mm:
        (ObjcField::valueFromInstance):
        (ObjcArray::valueAt):
        * bindings/objc/objc_utility.h:
        * bindings/objc/objc_utility.mm:
        (KJS::Bindings::convertObjcValueToValue):
        * bindings/runtime.h:

WebCore:

        Reviewed by Geoff.

        Pass the root object to methods that end up creating new ObjcInstance objects.
        
        * bindings/objc/WebScriptObject.mm:
        (listFromNSArray):
        (-[WebScriptObject callWebScriptMethod:withArguments:]):
        (-[WebScriptObject evaluateWebScript:]):
        (-[WebScriptObject setValue:forKey:]):
        (-[WebScriptObject valueForKey:]):
        (-[WebScriptObject removeWebScriptKey:]):
        (-[WebScriptObject setWebScriptValueAtIndex:value:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@23512 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8b2606e4
2007-06-13 Anders Carlsson <andersca@apple.com>
Reviewed by Geoff.
Make sure that bindings instances get correct root objects.
* JavaScriptCore.exp:
* bindings/NP_jsobject.cpp:
(listFromVariantArgs):
(_NPN_InvokeDefault):
(_NPN_Invoke):
(_NPN_SetProperty):
* bindings/c/c_instance.cpp:
(KJS::Bindings::CInstance::invokeMethod):
(KJS::Bindings::CInstance::invokeDefaultMethod):
* bindings/c/c_runtime.cpp:
(KJS::Bindings::CField::valueFromInstance):
* bindings/c/c_utility.cpp:
(KJS::Bindings::convertNPVariantToValue):
* bindings/c/c_utility.h:
* bindings/objc/objc_instance.mm:
(ObjcInstance::invokeMethod):
(ObjcInstance::invokeDefaultMethod):
(ObjcInstance::getValueOfUndefinedField):
* bindings/objc/objc_runtime.mm:
(ObjcField::valueFromInstance):
(ObjcArray::valueAt):
* bindings/objc/objc_utility.h:
* bindings/objc/objc_utility.mm:
(KJS::Bindings::convertObjcValueToValue):
* bindings/runtime.h:
2007-06-13 Simon Hausmann <hausmann@kde.org>
 
Reviewed by Lars.
......
......@@ -183,7 +183,7 @@ __ZN3KJS8Bindings10RootObject6createEPKvN3WTF10PassRefPtrINS_11InterpreterEEE
__ZN3KJS8Bindings10RootObject9gcProtectEPNS_8JSObjectE
__ZN3KJS8Bindings10RootObjectD1Ev
__ZN3KJS8Bindings10throwErrorEPNS_9ExecStateENS_9ErrorTypeEP8NSString
__ZN3KJS8Bindings23convertObjcValueToValueEPNS_9ExecStateEPvNS0_13ObjcValueTypeE
__ZN3KJS8Bindings23convertObjcValueToValueEPNS_9ExecStateEPvNS0_13ObjcValueTypeEPNS0_10RootObjectE
__ZN3KJS8Bindings23convertValueToObjcValueEPNS_9ExecStateEPNS_7JSValueENS0_13ObjcValueTypeE
__ZN3KJS8Bindings8Instance18didExecuteFunctionEv
__ZN3KJS8Bindings8Instance21setDidExecuteFunctionEPFvPNS_9ExecStateEPNS_8JSObjectEE
......
......@@ -1352,6 +1352,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject "JavaScriptCore" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
......
......@@ -36,11 +36,11 @@
using namespace KJS;
using namespace KJS::Bindings;
static List listFromVariantArgs(ExecState* exec, const NPVariant* args, unsigned argCount)
static List listFromVariantArgs(ExecState* exec, const NPVariant* args, unsigned argCount, RootObject* rootObject)
{
List aList;
for (unsigned i = 0; i < argCount; i++)
aList.append(convertNPVariantToValue(exec, &args[i]));
aList.append(convertNPVariantToValue(exec, &args[i], rootObject));
return aList;
}
......@@ -123,7 +123,7 @@ bool _NPN_InvokeDefault(NPP, NPObject* o, const NPVariant* args, uint32_t argCou
if (!funcImp->implementsCall())
return false;
List argList = listFromVariantArgs(exec, args, argCount);
List argList = listFromVariantArgs(exec, args, argCount, rootObject);
JSValue *resultV = funcImp->call (exec, funcImp, argList);
// Convert and return the result of the function call.
......@@ -176,7 +176,7 @@ bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant*
// Call the function object.
JSObject *funcImp = static_cast<JSObject*>(func);
JSObject *thisObj = const_cast<JSObject*>(obj->imp);
List argList = listFromVariantArgs(exec, args, argCount);
List argList = listFromVariantArgs(exec, args, argCount, rootObject);
JSValue *resultV = funcImp->call (exec, thisObj, argList);
// Convert and return the result of the function call.
......@@ -289,9 +289,9 @@ bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVaria
JSLock lock;
PrivateIdentifier* i = (PrivateIdentifier*)propertyName;
if (i->isString)
obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant));
obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant, rootObject));
else
obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant));
obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant, rootObject));
return true;
}
......
......@@ -104,7 +104,7 @@ JSValue* CInstance::invokeMethod(ExecState* exec, const MethodList& methodList,
for (i = 0; i < count; i++)
_NPN_ReleaseVariantValue(&cArgs[i]);
JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant);
JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get());
_NPN_ReleaseVariantValue(&resultVariant);
return resultValue;
}
......@@ -133,7 +133,7 @@ JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const List& args)
for (i = 0; i < count; i++)
_NPN_ReleaseVariantValue(&cArgs[i]);
JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant);
JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get());
_NPN_ReleaseVariantValue(&resultVariant);
return resultValue;
}
......
......@@ -63,7 +63,7 @@ JSValue* CField::valueFromInstance(ExecState* exec, const Instance* inst) const
result = obj->_class->getProperty(obj, _fieldIdentifier, &property);
}
if (result) {
JSValue* result = convertNPVariantToValue(exec, &property);
JSValue* result = convertNPVariantToValue(exec, &property, instance->rootObject());
_NPN_ReleaseVariantValue(&property);
return result;
}
......
......@@ -140,7 +140,7 @@ void convertValueToNPVariant(ExecState *exec, JSValue *value, NPVariant *result)
}
}
JSValue *convertNPVariantToValue(ExecState*, const NPVariant* variant)
JSValue *convertNPVariantToValue(ExecState*, const NPVariant* variant, RootObject* rootObject)
{
JSLock lock;
......@@ -172,7 +172,7 @@ JSValue *convertNPVariantToValue(ExecState*, const NPVariant* variant)
return ((JavaScriptObject *)obj)->imp;
// Wrap NPObject in a CInstance.
return Instance::createRuntimeObject(Instance::CLanguage, obj);
return Instance::createRuntimeObject(Instance::CLanguage, obj, rootObject);
}
return jsUndefined();
......
......@@ -36,6 +36,8 @@ class JSValue;
namespace Bindings {
class RootObject;
typedef uint16_t NPUTF16;
enum NP_ValueType {
......@@ -51,7 +53,7 @@ enum NP_ValueType {
void convertNPStringToUTF16(const NPString*, NPUTF16** UTF16Chars, unsigned int* UTF16Length);
void convertUTF8ToUTF16(const NPUTF8* UTF8Chars, int UTF8Length, NPUTF16** UTF16Chars, unsigned int* UTF16Length);
void convertValueToNPVariant(ExecState*, JSValue*, NPVariant* result);
JSValue* convertNPVariantToValue(ExecState*, const NPVariant*);
JSValue* convertNPVariantToValue(ExecState*, const NPVariant*, RootObject*);
Identifier identifierFromNPIdentifier(const NPUTF8* name);
struct PrivateIdentifier {
......
......@@ -201,7 +201,7 @@ JSValue* ObjcInstance::invokeMethod(ExecState* exec, const MethodList &methodLis
if (*type != 'v') {
[invocation getReturnValue:buffer];
result = convertObjcValueToValue(exec, buffer, objcValueType);
result = convertObjcValueToValue(exec, buffer, objcValueType, _rootObject.get());
}
} @catch(NSException* localException) {
}
......@@ -248,7 +248,7 @@ JSValue* ObjcInstance::invokeDefaultMethod(ExecState* exec, const List &args)
// OK with 32 here.
char buffer[32];
[invocation getReturnValue:buffer];
result = convertObjcValueToValue(exec, buffer, objcValueType);
result = convertObjcValueToValue(exec, buffer, objcValueType, _rootObject.get());
} @catch(NSException* localException) {
}
......@@ -297,7 +297,7 @@ JSValue* ObjcInstance::getValueOfUndefinedField(ExecState* exec, const Identifie
if ([targetObject respondsToSelector:@selector(valueForUndefinedKey:)]){
@try {
id objcValue = [targetObject valueForUndefinedKey:[NSString stringWithCString:property.ascii() encoding:NSASCIIStringEncoding]];
result = convertObjcValueToValue(exec, &objcValue, ObjcObjectType);
result = convertObjcValueToValue(exec, &objcValue, ObjcObjectType, _rootObject.get());
} @catch(NSException* localException) {
// Do nothing. Class did not override valueForUndefinedKey:.
}
......
......@@ -111,7 +111,7 @@ JSValue* ObjcField::valueFromInstance(ExecState* exec, const Instance* instance)
@try {
NSString* key = [NSString stringWithCString:name() encoding:NSASCIIStringEncoding];
if (id objcValue = [targetObject valueForKey:key])
result = convertObjcValueToValue(exec, &objcValue, ObjcObjectType);
result = convertObjcValueToValue(exec, &objcValue, ObjcObjectType, instance->rootObject());
} @catch(NSException* localException) {
JSLock::lock();
throwError(exec, GeneralError, [localException reason]);
......@@ -184,7 +184,7 @@ JSValue* ObjcArray::valueAt(ExecState* exec, unsigned int index) const
@try {
id obj = [_array.get() objectAtIndex:index];
if (obj)
return convertObjcValueToValue (exec, &obj, ObjcObjectType);
return convertObjcValueToValue (exec, &obj, ObjcObjectType, _rootObject.get());
} @catch(NSException* localException) {
return throwError(exec, GeneralError, "Objective-C exception.");
}
......
......@@ -74,7 +74,7 @@ class RootObject;
ObjcValue convertValueToObjcValue(ExecState *exec, JSValue *value, ObjcValueType type);
JSValue *convertNSStringToString(NSString *nsstring);
JSValue *convertObjcValueToValue(ExecState *exec, void *buffer, ObjcValueType type);
JSValue *convertObjcValueToValue(ExecState *exec, void *buffer, ObjcValueType type, RootObject*);
ObjcValueType objcValueTypeForType(const char *type);
bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSize);
......
......@@ -225,7 +225,7 @@ JSValue *convertNSStringToString(NSString *nsstring)
id object wrapper
other should not happen
*/
JSValue* convertObjcValueToValue(ExecState* exec, void* buffer, ObjcValueType type)
JSValue* convertObjcValueToValue(ExecState* exec, void* buffer, ObjcValueType type, RootObject* rootObject)
{
JSLock lock;
......@@ -243,14 +243,14 @@ JSValue* convertObjcValueToValue(ExecState* exec, void* buffer, ObjcValueType ty
if ([obj isKindOfClass:[NSNumber class]])
return jsNumber([obj doubleValue]);
if ([obj isKindOfClass:[NSArray class]])
return new RuntimeArray(exec, new ObjcArray(obj, 0));
return new RuntimeArray(exec, new ObjcArray(obj, rootObject));
if ([obj isKindOfClass:webScriptObjectClass()])
return [obj _imp];
if ([obj isKindOfClass:[NSNull class]])
return jsNull();
if (obj == 0)
return jsUndefined();
return Instance::createRuntimeObject(Instance::ObjectiveCLanguage, obj);
return Instance::createRuntimeObject(Instance::ObjectiveCLanguage, obj, rootObject);
}
case ObjcCharType:
return jsNumber(*(char *)buffer);
......
......@@ -47,6 +47,7 @@ namespace KJS { namespace Bindings {
Array::Array(PassRefPtr<RootObject> rootObject)
: _rootObject(rootObject)
{
ASSERT(_rootObject);
}
Array::~Array()
......@@ -57,6 +58,7 @@ Instance::Instance(PassRefPtr<RootObject> rootObject)
: _rootObject(rootObject)
, _refCount(0)
{
ASSERT(_rootObject);
}
Instance::~Instance()
......
......@@ -99,8 +99,8 @@ public:
static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func);
static KJSDidExecuteFunctionPtr didExecuteFunction();
static Instance* createBindingForLanguageInstance(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject> = 0);
static JSObject* createRuntimeObject(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject> = 0);
static Instance* createBindingForLanguageInstance(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject>);
static JSObject* createRuntimeObject(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject>);
void ref() { _refCount++; }
void deref()
......
2007-06-13 Anders Carlsson <andersca@apple.com>
Reviewed by Geoff.
Pass the root object to methods that end up creating new ObjcInstance objects.
* bindings/objc/WebScriptObject.mm:
(listFromNSArray):
(-[WebScriptObject callWebScriptMethod:withArguments:]):
(-[WebScriptObject evaluateWebScript:]):
(-[WebScriptObject setValue:forKey:]):
(-[WebScriptObject valueForKey:]):
(-[WebScriptObject removeWebScriptKey:]):
(-[WebScriptObject setWebScriptValueAtIndex:value:]):
2007-06-13 Anders Carlsson <andersca@apple.com>
 
Reviewed by Darin.
......@@ -11589,6 +11589,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
knownRegions = (
English,
......@@ -245,14 +245,14 @@ static void _didExecute(WebScriptObject *obj)
return NO;
}
static List listFromNSArray(ExecState *exec, NSArray *array)
static List listFromNSArray(ExecState *exec, NSArray *array, RootObject* rootObject)
{
int i, numObjects = array ? [array count] : 0;
List aList;
for (i = 0; i < numObjects; i++) {
id anObject = [array objectAtIndex:i];
aList.append(convertObjcValueToValue(exec, &anObject, ObjcObjectType));
aList.append(convertObjcValueToValue(exec, &anObject, ObjcObjectType, rootObject));
}
return aList;
}
......@@ -271,7 +271,7 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
JSLock lock;
JSValue *v = convertObjcValueToValue(exec, &name, ObjcObjectType);
JSValue *v = convertObjcValueToValue(exec, &name, ObjcObjectType, [self _rootObject]);
Identifier identifier(v->toString(exec));
JSValue *func = [self _imp]->get(exec, identifier);
......@@ -285,7 +285,7 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
return 0;
JSObject *thisObj = const_cast<JSObject*>([self _imp]);
List argList = listFromNSArray(exec, args);
List argList = listFromNSArray(exec, args, [self _rootObject]);
JSValue *result = funcImp->call(exec, thisObj, argList);
if (exec->hadException()) {
......@@ -316,7 +316,7 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
JSValue *result;
JSLock lock;
JSValue *v = convertObjcValueToValue(exec, &script, ObjcObjectType);
JSValue *v = convertObjcValueToValue(exec, &script, ObjcObjectType, [self _rootObject]);
Completion completion = [self _rootObject]->interpreter()->evaluate(UString(), 0, v->toString(exec));
ComplType type = completion.complType();
......@@ -352,8 +352,8 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
ASSERT(!exec->hadException());
JSLock lock;
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType);
[self _imp]->put(exec, Identifier(v->toString(exec)), convertObjcValueToValue(exec, &value, ObjcObjectType));
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType, [self _rootObject]);
[self _imp]->put(exec, Identifier(v->toString(exec)), convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject]));
if (exec->hadException()) {
LOG_EXCEPTION(exec);
......@@ -375,7 +375,7 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
ASSERT(!exec->hadException());
JSLock lock;
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType);
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType, [self _rootObject]);
JSValue *result = [self _imp]->get(exec, Identifier(v->toString(exec)));
if (exec->hadException()) {
......@@ -405,7 +405,7 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
ASSERT(!exec->hadException());
JSLock lock;
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType);
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType, [self _rootObject]);
[self _imp]->deleteProperty(exec, Identifier(v->toString(exec)));
if (exec->hadException()) {
......@@ -478,7 +478,7 @@ static List listFromNSArray(ExecState *exec, NSArray *array)
ASSERT(!exec->hadException());
JSLock lock;
[self _imp]->put(exec, index, convertObjcValueToValue(exec, &value, ObjcObjectType));
[self _imp]->put(exec, index, convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject]));
if (exec->hadException()) {
LOG_EXCEPTION(exec);
......
Markdown is supported
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