From ddcc04b33ed41b9daf1103563beb3229e6d7a244 Mon Sep 17 00:00:00 2001 From: rjw Date: Fri, 21 Jan 2005 00:41:59 +0000 Subject: [PATCH] Fixed undefined property value from binding seems to evaluate to true in an if statement The comprehensive fix for this problem requires new API, as described in 3965326. However, given that we can't add new API at this point, the 'ObjcFallbackObjectImp' will behave like and Undefined object if invokeUndefinedMethodFromWebScript:withArguments: isn't implemented on the bound object. Reviewed by Chris. * bindings/objc/objc_runtime.h: * bindings/objc/objc_runtime.mm: (ObjcFallbackObjectImp::type): (ObjcFallbackObjectImp::implementsCall): (ObjcFallbackObjectImp::toBoolean): * bindings/testbindings.mm: (+[MyFirstInterface isSelectorExcludedFromWebScript:]): (+[MyFirstInterface isKeyExcludedFromWebScript:]): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8418 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- JavaScriptCore/ChangeLog | 20 +++++++++++++++ JavaScriptCore/bindings/objc/objc_runtime.h | 3 +++ JavaScriptCore/bindings/objc/objc_runtime.mm | 26 +++++++++++++++++++- JavaScriptCore/bindings/testbindings.mm | 14 +++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index d593ffb1f5f8..721409405277 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,3 +1,23 @@ +2005-01-20 Richard Williamson + + Fixed undefined property value from binding seems to evaluate to true in an if statement + + The comprehensive fix for this problem requires new API, as described in 3965326. However, + given that we can't add new API at this point, the 'ObjcFallbackObjectImp' will behave + like and Undefined object if invokeUndefinedMethodFromWebScript:withArguments: isn't + implemented on the bound object. + + Reviewed by Chris. + + * bindings/objc/objc_runtime.h: + * bindings/objc/objc_runtime.mm: + (ObjcFallbackObjectImp::type): + (ObjcFallbackObjectImp::implementsCall): + (ObjcFallbackObjectImp::toBoolean): + * bindings/testbindings.mm: + (+[MyFirstInterface isSelectorExcludedFromWebScript:]): + (+[MyFirstInterface isKeyExcludedFromWebScript:]): + === Safari-180 === 2005-01-19 Richard Williamson diff --git a/JavaScriptCore/bindings/objc/objc_runtime.h b/JavaScriptCore/bindings/objc/objc_runtime.h index fd4a81335de1..e8e69c968eb2 100644 --- a/JavaScriptCore/bindings/objc/objc_runtime.h +++ b/JavaScriptCore/bindings/objc/objc_runtime.h @@ -188,6 +188,9 @@ public: virtual Value defaultValue(ExecState *exec, Type hint) const; + virtual Type type() const; + virtual bool toBoolean(ExecState *exec) const; + private: static const ClassInfo info; diff --git a/JavaScriptCore/bindings/objc/objc_runtime.mm b/JavaScriptCore/bindings/objc/objc_runtime.mm index 8c83e5796305..bcc00da113a5 100644 --- a/JavaScriptCore/bindings/objc/objc_runtime.mm +++ b/JavaScriptCore/bindings/objc/objc_runtime.mm @@ -283,9 +283,24 @@ bool ObjcFallbackObjectImp::canPut(ExecState *exec, const Identifier &propertyNa } +Type ObjcFallbackObjectImp::type() const +{ + id targetObject = _instance->getObject(); + + if ([targetObject respondsToSelector:@selector(invokeUndefinedMethodFromWebScript:withArguments:)]) + return ObjectType; + + return UndefinedType; +} + bool ObjcFallbackObjectImp::implementsCall() const { - return true; + id targetObject = _instance->getObject(); + + if ([targetObject respondsToSelector:@selector(invokeUndefinedMethodFromWebScript:withArguments:)]) + return true; + + return false; } Value ObjcFallbackObjectImp::call(ExecState *exec, Object &thisObj, const List &args) @@ -334,3 +349,12 @@ Value ObjcFallbackObjectImp::defaultValue(ExecState *exec, Type hint) const return _instance->getValueOfUndefinedField(exec, _item, hint); } +bool ObjcFallbackObjectImp::toBoolean(ExecState *exec) const +{ + id targetObject = _instance->getObject(); + + if ([targetObject respondsToSelector:@selector(invokeUndefinedMethodFromWebScript:withArguments:)]) + return true; + + return false; +} diff --git a/JavaScriptCore/bindings/testbindings.mm b/JavaScriptCore/bindings/testbindings.mm index 3a950214c0dd..8a9d4b3a7794 100644 --- a/JavaScriptCore/bindings/testbindings.mm +++ b/JavaScriptCore/bindings/testbindings.mm @@ -91,6 +91,17 @@ return nil; } ++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector +{ + return NO; +} + ++ (BOOL)isKeyExcludedFromWebScript:(const char *)name +{ + return NO; +} + +/* - (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)args; { NSLog (@"Call to undefined method %@", name); @@ -101,12 +112,15 @@ } return @"success"; } +*/ +/* - (id)valueForUndefinedKey:(NSString *)key { NSLog (@"%s: key = %@", __PRETTY_FUNCTION__, key); return @"aValue"; } +*/ - (void)setValue:(id)value forUndefinedKey:(NSString *)key { -- 2.36.0