1. Add class parameter to object allocation function. This is somewhat redundant, given that
the allocation function is in the class function vector, but people wanted to use the same
allocation function for different classes.
2. Renamed NPN_Class to NPN_Invoke to match the name in the function vector.
3. Add support for a default function on an object. This is a feature that ActiveX supports,
and will allow JavaScript code to be written that will look exactly the same for both ActiveX
plugins and Netscape or WebKit plugins. There are implementations included for the 'C' and
'Objective-C' bindings.
There bugs are covered by
<rdar://problem/
3776343> Support for default functions in the JavaScript bindings
<rdar://problem/
3779186> NPN_Call needs to be renamed to NPN_Invoke
<rdar://problem/
3674754> Need to implement latest npruntime.h
Reviewed by John.
* Plugins.subproj/WebNetscapePluginPackage.m:
(-[WebNetscapePluginPackage load]):
* Plugins.subproj/WebScriptObject.h:
* Plugins.subproj/npfunctions.h:
* Plugins.subproj/npruntime.h:
JavaScriptCore:
1. Add class parameter to object allocation function. This is somewhat redundant, given that
the allocation function is in the class function vector, but people wanted to use the same
allocation function for different classes.
2. Renamed NPN_Class to NPN_Invoke to match the name in the function vector.
3. Add support for a default function on an object. This is a feature that ActiveX supports,
and will allow JavaScript code to be written that will look exactly the same for both ActiveX
plugins and Netscape or WebKit plugins. There are implementations included for the 'C' and
'Objective-C' bindings.
There bugs are covered by
<rdar://problem/
3776343> Support for default functions in the JavaScript bindings
<rdar://problem/
3779186> NPN_Call needs to be renamed to NPN_Invoke
<rdar://problem/
3674754> Need to implement latest npruntime.h
Reviewed by John.
* bindings/NP_jsobject.cpp:
(jsAllocate):
(NPN_InvokeDefault):
(NPN_Invoke):
* bindings/c/c_class.cpp:
* bindings/c/c_instance.cpp:
(CInstance::CInstance):
(CInstance::operator=):
(CInstance::invokeMethod):
(CInstance::invokeDefaultMethod):
* bindings/c/c_instance.h:
* bindings/c/c_runtime.cpp:
* bindings/c/c_runtime.h:
* bindings/jni/jni_instance.cpp:
(JavaInstance::invokeDefaultMethod):
* bindings/jni/jni_instance.h:
* bindings/npruntime.cpp:
(NPN_CreateObject):
* bindings/npruntime.h:
* bindings/objc/WebScriptObject.h:
* bindings/objc/objc_class.mm:
(ObjcClass::fallbackObject):
* bindings/objc/objc_instance.h:
* bindings/objc/objc_instance.mm:
(ObjcInstance::invokeDefaultMethod):
* bindings/objc/objc_runtime.h:
* bindings/objc/objc_runtime.mm:
(ObjcFallbackObjectImp::ObjcFallbackObjectImp):
(ObjcFallbackObjectImp::get):
(ObjcFallbackObjectImp::put):
(ObjcFallbackObjectImp::canPut):
(ObjcFallbackObjectImp::implementsCall):
(ObjcFallbackObjectImp::call):
(ObjcFallbackObjectImp::hasProperty):
(ObjcFallbackObjectImp::deleteProperty):
(ObjcFallbackObjectImp::defaultValue):
* bindings/runtime.h:
(KJS::Bindings::Class::fallbackObject):
(KJS::Bindings::Instance::getValueOfUndefinedField):
(KJS::Bindings::Instance::setValueOfUndefinedField):
(KJS::Bindings::Instance::valueOf):
* bindings/runtime_object.cpp:
(RuntimeObjectImp::implementsCall):
(RuntimeObjectImp::call):
* bindings/runtime_object.h:
WebKitExamples:
Reworked NetscapeMoviePlugIn to better test and illustrate
scripting APIs.
Reviewed by John.
* CarbonWeb/MyWebUIAdapter.m:
(-[MyWebUIAdapter webView:runJavaScriptAlertPanelWithMessage:]):
(-[MyWebUIAdapter webView:runJavaScriptConfirmPanelWithMessage:]):
(-[MyWebUIAdapter webView:runJavaScriptTextInputPanelWithPrompt:defaultText:]):
* CarbonWeb/TWebWindow.cp:
* NetscapeMoviePlugIn/MovieObject.c: Added.
(getMovieClass):
(initializeIdentifiers):
(movieHasProperty):
(movieHasMethod):
(movieGetProperty):
(movieSetProperty):
(movieInvoke):
(movieInvokeDefault):
(movieInvalidate):
(movieAllocate):
(movieDeallocate):
(LoadMovieFromFile):
(CreateMovieController):
(UpdateMovieFrame):
(PlayMovie):
(PauseMovie):
(IsMovieMuted):
(SetMovieMuted):
(DestroyMovie):
(HandleMovieEvent):
* NetscapeMoviePlugIn/MovieObject.h: Added.
* NetscapeMoviePlugIn/NetscapeMoviePlugIn.xcode/project.pbxproj:
* NetscapeMoviePlugIn/PluginObject.c: Added.
(getPluginClass):
(initializeIdentifiers):
(pluginHasProperty):
(pluginHasMethod):
(pluginGetProperty):
(pluginSetProperty):
(pluginInvoke):
(pluginInvokeDefault):
(pluginInvalidate):
(pluginAllocate):
(pluginDeallocate):
* NetscapeMoviePlugIn/PluginObject.h: Added.
* NetscapeMoviePlugIn/main.c:
(NP_Initialize):
(NPP_New):
(NPP_Destroy):
(NPP_SetWindow):
(NPP_StreamAsFile):
(NPP_HandleEvent):
(NPP_GetValue):
(NPP_SetValue):
* NetscapeMoviePlugIn/movie.h: Added.
* NetscapeMoviePlugIn/movie.html:
* makefile:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7565
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2004-09-14 Richard Williamson <rjw@apple.com>
+
+ 1. Add class parameter to object allocation function. This is somewhat redundant, given that
+ the allocation function is in the class function vector, but people wanted to use the same
+ allocation function for different classes.
+
+ 2. Renamed NPN_Class to NPN_Invoke to match the name in the function vector.
+
+ 3. Add support for a default function on an object. This is a feature that ActiveX supports,
+ and will allow JavaScript code to be written that will look exactly the same for both ActiveX
+ plugins and Netscape or WebKit plugins. There are implementations included for the 'C' and
+ 'Objective-C' bindings.
+
+ There bugs are covered by
+
+ <rdar://problem/3776343> Support for default functions in the JavaScript bindings
+ <rdar://problem/3779186> NPN_Call needs to be renamed to NPN_Invoke
+ <rdar://problem/3674754> Need to implement latest npruntime.h
+
+ Reviewed by John.
+
+ * bindings/NP_jsobject.cpp:
+ (jsAllocate):
+ (NPN_InvokeDefault):
+ (NPN_Invoke):
+ * bindings/c/c_class.cpp:
+ * bindings/c/c_instance.cpp:
+ (CInstance::CInstance):
+ (CInstance::operator=):
+ (CInstance::invokeMethod):
+ (CInstance::invokeDefaultMethod):
+ * bindings/c/c_instance.h:
+ * bindings/c/c_runtime.cpp:
+ * bindings/c/c_runtime.h:
+ * bindings/jni/jni_instance.cpp:
+ (JavaInstance::invokeDefaultMethod):
+ * bindings/jni/jni_instance.h:
+ * bindings/npruntime.cpp:
+ (NPN_CreateObject):
+ * bindings/npruntime.h:
+ * bindings/objc/WebScriptObject.h:
+ * bindings/objc/objc_class.mm:
+ (ObjcClass::fallbackObject):
+ * bindings/objc/objc_instance.h:
+ * bindings/objc/objc_instance.mm:
+ (ObjcInstance::invokeDefaultMethod):
+ * bindings/objc/objc_runtime.h:
+ * bindings/objc/objc_runtime.mm:
+ (ObjcFallbackObjectImp::ObjcFallbackObjectImp):
+ (ObjcFallbackObjectImp::get):
+ (ObjcFallbackObjectImp::put):
+ (ObjcFallbackObjectImp::canPut):
+ (ObjcFallbackObjectImp::implementsCall):
+ (ObjcFallbackObjectImp::call):
+ (ObjcFallbackObjectImp::hasProperty):
+ (ObjcFallbackObjectImp::deleteProperty):
+ (ObjcFallbackObjectImp::defaultValue):
+ * bindings/runtime.h:
+ (KJS::Bindings::Class::fallbackObject):
+ (KJS::Bindings::Instance::getValueOfUndefinedField):
+ (KJS::Bindings::Instance::setValueOfUndefinedField):
+ (KJS::Bindings::Instance::valueOf):
+ * bindings/runtime_object.cpp:
+ (RuntimeObjectImp::implementsCall):
+ (RuntimeObjectImp::call):
+ * bindings/runtime_object.h:
+
2004-09-13 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin.
return aList;
}
-static NPObject *jsAllocate(NPP npp)
+static NPObject *jsAllocate(NPP npp, NPClass *aClass)
{
return (NPObject *)malloc(sizeof(JavaScriptObject));
}
0,
0,
0,
+ 0,
0
};
return (NPObject *)obj;
}
-bool NPN_Call (NPP npp, NPObject *o, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result)
+bool NPN_InvokeDefault (NPP npp, NPObject *o, const NPVariant *args, uint32_t argCount, NPVariant *result)
+{
+ if (o->_class == NPScriptObjectClass) {
+ // No notion of a default function on JS objects. Just return false, can't handle.
+ return false;
+ }
+ else {
+ if (o->_class->invokeDefault) {
+ return o->_class->invokeDefault (o, args, argCount, result);
+ }
+ }
+
+ return true;
+}
+
+bool NPN_Invoke (NPP npp, NPObject *o, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject *obj = (JavaScriptObject *)o;
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <c_class.h>
+#include <c_instance.h>
+#include <c_runtime.h>
using namespace KJS::Bindings;
CInstance::CInstance (NPObject *o)
{
_object = NPN_RetainObject (o);
+ _class = 0;
};
CInstance::~CInstance ()
CInstance::CInstance (const CInstance &other) : Instance()
{
_object = NPN_RetainObject (other._object);
+ _class = 0;
};
CInstance &CInstance::operator=(const CInstance &other){
NPObject *_oldObject = _object;
_object= NPN_RetainObject (other._object);
NPN_ReleaseObject (_oldObject);
+ _class = 0;
return *this;
};
NPN_ReleaseVariantValue (&cArgs[i]);
}
+ if (cArgs != localBuffer)
+ free ((void *)cArgs);
+
if (!NPVARIANT_IS_VOID(resultVariant)) {
resultValue = convertNPVariantToValue (exec, &resultVariant);
- if (cArgs != localBuffer)
- free ((void *)cArgs);
-
NPN_ReleaseVariantValue (&resultVariant);
return resultValue;
}
+Value CInstance::invokeDefaultMethod (KJS::ExecState *exec, const List &args)
+{
+ Value resultValue;
+
+ if (_object->_class->invokeDefault) {
+ unsigned i, count = args.size();
+ NPVariant *cArgs;
+ NPVariant localBuffer[128];
+ if (count > 128)
+ cArgs = (NPVariant *)malloc (sizeof(NPVariant)*count);
+ else
+ cArgs = localBuffer;
+
+ for (i = 0; i < count; i++) {
+ convertValueToNPVariant (exec, args.at(i), &cArgs[i]);
+ }
+
+ // Invoke the 'C' method.
+ NPVariant resultVariant;
+ _object->_class->invokeDefault (_object, cArgs, count, &resultVariant);
+
+ for (i = 0; i < count; i++) {
+ NPN_ReleaseVariantValue (&cArgs[i]);
+ }
+
+ if (cArgs != localBuffer)
+ free ((void *)cArgs);
+
+ if (!NPVARIANT_IS_VOID(resultVariant)) {
+ resultValue = convertNPVariantToValue (exec, &resultVariant);
+
+ NPN_ReleaseVariantValue (&resultVariant);
+
+ return resultValue;
+ }
+ }
+
+ return Undefined();
+}
+
+
KJS::Value CInstance::defaultValue (KJS::Type hint) const
{
if (hint == KJS::StringType) {
virtual void begin();
virtual void end();
- virtual KJS::Value valueOf() const;
- virtual KJS::Value defaultValue (KJS::Type hint) const;
+ virtual Value valueOf() const;
+ virtual Value defaultValue (KJS::Type hint) const;
- virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args);
+ virtual Value invokeMethod (ExecState *exec, const MethodList &method, const List &args);
+ virtual Value invokeDefaultMethod (ExecState *exec, const List &args);
- KJS::Value stringValue() const;
- KJS::Value numberValue() const;
- KJS::Value booleanValue() const;
+ Value stringValue() const;
+ Value numberValue() const;
+ Value booleanValue() const;
NPObject *getObject() const { return _object; }
}
// ---------------------- CArray ----------------------
-
namespace Bindings
{
+class CInstance;
+
class CField : public Field
{
public:
};
#endif
+
} // namespace Bindings
} // namespace KJS
return resultValue;
}
+KJS::Value JavaInstance::invokeDefaultMethod (KJS::ExecState *exec, const KJS::List &args)
+{
+ return Undefined();
+}
+
KJS::Value JavaInstance::defaultValue (KJS::Type hint) const
{
virtual void begin();
virtual void end();
- virtual KJS::Value valueOf() const;
- virtual KJS::Value defaultValue (KJS::Type hint) const;
+ virtual Value valueOf() const;
+ virtual Value defaultValue (Type hint) const;
- virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args);
+ virtual Value invokeMethod (ExecState *exec, const MethodList &method, const List &args);
+ virtual Value invokeDefaultMethod (ExecState *exec, const List &args);
virtual void setExecutionContext (RootObject *r);
virtual const RootObject *executionContext() const;
jobject javaInstance() const { return _instance->_instance; }
- KJS::Value stringValue() const;
- KJS::Value numberValue() const;
- KJS::Value booleanValue() const;
+ Value stringValue() const;
+ Value numberValue() const;
+ Value booleanValue() const;
private:
JObjectWrapper *_instance;
NPObject *obj;
if (aClass->allocate != NULL)
- obj = aClass->allocate (npp);
+ obj = aClass->allocate (npp, aClass);
else
obj = (NPObject *)malloc (sizeof(NPObject));
The NPVariant *result argument of these functions (where
applicable) should be released using NPN_ReleaseVariantValue().
*/
-typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp);
+typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass);
typedef void (*NPDeallocateFunctionPtr)(NPObject *obj);
typedef void (*NPInvalidateFunctionPtr)(NPObject *obj);
typedef bool (*NPHasMethodFunctionPtr)(NPClass *theClass, NPIdentifier name);
-typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);
+typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result);
typedef bool (*NPHasPropertyFunctionPtr)(NPClass *theClass, NPIdentifier name);
typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
typedef bool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
NPInvalidateFunctionPtr invalidate;
NPHasMethodFunctionPtr hasMethod;
NPInvokeFunctionPtr invoke;
+ NPInvokeDefaultFunctionPtr invokeDefault;
NPHasPropertyFunctionPtr hasProperty;
NPGetPropertyFunctionPtr getProperty;
NPSetPropertyFunctionPtr setProperty;
Calls made from plugin code to script must be made from the thread
on which the plugin was initialized.
*/
-bool NPN_Call(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result);
bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, NPVariant *result);
bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result);
bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value);
*/
- (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)args;
+/*!
+ @method invokeDefaultMethodWithArguments:
+ @param args The args to pass the method.
+ @discussion If a script attempts to invoke a method on an exposed object
+ directory this method will be called.
+*/
+- (id)invokeDefaultMethodWithArguments:(NSArray *)args;
+
/*!
@method finalizeForWebScript
@discussion finalizeForScript is called on objects exposed to the script
KJS::Value ObjcClass::fallbackObject (ExecState *exec, Instance *instance, const Identifier &propertyName)
{
- return Object (new FallbackObjectImp(static_cast<ObjcInstance*>(instance), propertyName));
+ return Object (new ObjcFallbackObjectImp(static_cast<ObjcInstance*>(instance), propertyName));
}
virtual void begin();
virtual void end();
- virtual KJS::Value valueOf() const;
- virtual KJS::Value defaultValue (KJS::Type hint) const;
+ virtual Value valueOf() const;
+ virtual Value defaultValue (Type hint) const;
- virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args);
+ virtual Value invokeMethod (ExecState *exec, const MethodList &method, const List &args);
+ virtual Value invokeDefaultMethod (ExecState *exec, const List &args);
- virtual void setValueOfField (KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const;
- virtual void setValueOfUndefinedField (KJS::ExecState *exec, const KJS::Identifier &property, const KJS::Value &aValue);
+ virtual void setValueOfField (ExecState *exec, const Field *aField, const Value &aValue) const;
+ virtual void setValueOfUndefinedField (ExecState *exec, const Identifier &property, const Value &aValue);
- virtual Value ObjcInstance::getValueOfField (KJS::ExecState *exec, const Field *aField) const;
- virtual KJS::Value getValueOfUndefinedField (KJS::ExecState *exec, const KJS::Identifier &property, KJS::Type hint) const;
+ virtual Value ObjcInstance::getValueOfField (ExecState *exec, const Field *aField) const;
+ virtual Value getValueOfUndefinedField (ExecState *exec, const Identifier &property, Type hint) const;
ObjectStructPtr getObject() const { return _instance; }
- KJS::Value stringValue() const;
- KJS::Value numberValue() const;
- KJS::Value booleanValue() const;
+ Value stringValue() const;
+ Value numberValue() const;
+ Value booleanValue() const;
void setExecutionContext (RootObject *r) { _root = r; }
const RootObject *executionContext() const { return _root; }
return resultValue;
}
+Value ObjcInstance::invokeDefaultMethod (KJS::ExecState *exec, const List &args)
+{
+ Value resultValue;
+
+NS_DURING
+
+ if (![_instance respondsToSelector:@selector(invokeDefaultMethodWithArguments:)])
+ return Undefined();
+
+ NSMethodSignature *signature = [_instance methodSignatureForSelector:@selector(invokeDefaultMethodWithArguments:)];
+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
+ [invocation setSelector:@selector(invokeDefaultMethodWithArguments:)];
+ [invocation setTarget:_instance];
+ unsigned i, count = args.size();
+
+ // invokeDefaultMethodWithArguments: implementation must return an
+ // object.
+ if (strcmp ([signature methodReturnType], "@") != 0) {
+ OBJC_LOG ("incorrect signature for invokeDefaultMethodWithArguments:, expected object return type");
+ return Undefined();
+ }
+
+ NSMutableArray *objcArgs = [NSMutableArray array];
+ for (i = 0; i < count; i++) {
+ ObjcValue value = convertValueToObjcValue (exec, args.at(i), ObjcObjectType);
+ [objcArgs addObject:value.objectValue];
+ }
+ [invocation setArgument:&objcArgs atIndex:2];
+
+ // Invoke the ObjectiveC method.
+ [invocation invoke];
+
+ // Get the return value type, should always be "@" because of
+ // check above.
+ const char *type = [signature methodReturnType];
+ ObjcValueType objcValueType = objcValueTypeForType (type);
+
+ // Get the return value and convert it to a KJS::Value. Length
+ // of return value will never exceed the size of a pointer, so we're
+ // OK we 32 here.
+ char buffer[32];
+ [invocation getReturnValue:buffer];
+ resultValue = convertObjcValueToValue (exec, buffer, objcValueType);
+
+NS_HANDLER
+
+ resultValue = Undefined();
+
+NS_ENDHANDLER
+
+ return resultValue;
+}
+
void ObjcInstance::setValueOfField (KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const
{
aField->setValueToInstance (exec, this, aValue);
ObjectStructPtr _array;
};
-class FallbackObjectImp : public KJS::ObjectImp {
+class ObjcFallbackObjectImp : public KJS::ObjectImp {
public:
- FallbackObjectImp(ObjectImp *proto);
+ ObjcFallbackObjectImp(ObjectImp *proto);
- FallbackObjectImp(ObjcInstance *i, const KJS::Identifier propertyName);
+ ObjcFallbackObjectImp(ObjcInstance *i, const KJS::Identifier propertyName);
const ClassInfo *classInfo() const { return &info; }
}
-const ClassInfo FallbackObjectImp::info = {"FallbackObject", 0, 0, 0};
+const ClassInfo ObjcFallbackObjectImp::info = {"ObjcFallbackObject", 0, 0, 0};
-FallbackObjectImp::FallbackObjectImp(ObjectImp *proto)
+ObjcFallbackObjectImp::ObjcFallbackObjectImp(ObjectImp *proto)
: ObjectImp(proto)
{
_instance = 0;
}
-FallbackObjectImp::FallbackObjectImp(ObjcInstance *i, const KJS::Identifier propertyName) : ObjectImp ((ObjectImp *)0)
+ObjcFallbackObjectImp::ObjcFallbackObjectImp(ObjcInstance *i, const KJS::Identifier propertyName) : ObjectImp ((ObjectImp *)0)
{
_instance = i;
_item = propertyName;
}
-Value FallbackObjectImp::get(ExecState *exec, const Identifier &propertyName) const
+Value ObjcFallbackObjectImp::get(ExecState *exec, const Identifier &propertyName) const
{
return Undefined();
}
-void FallbackObjectImp::put(ExecState *exec, const Identifier &propertyName,
+void ObjcFallbackObjectImp::put(ExecState *exec, const Identifier &propertyName,
const Value &value, int attr)
{
}
-bool FallbackObjectImp::canPut(ExecState *exec, const Identifier &propertyName) const
+bool ObjcFallbackObjectImp::canPut(ExecState *exec, const Identifier &propertyName) const
{
return false;
}
-bool FallbackObjectImp::implementsCall() const
+bool ObjcFallbackObjectImp::implementsCall() const
{
return true;
}
-Value FallbackObjectImp::call(ExecState *exec, Object &thisObj, const List &args)
+Value ObjcFallbackObjectImp::call(ExecState *exec, Object &thisObj, const List &args)
{
Value result = Undefined();
return result;
}
-bool FallbackObjectImp::hasProperty(ExecState *exec,
+bool ObjcFallbackObjectImp::hasProperty(ExecState *exec,
const Identifier &propertyName) const
{
return false;
}
-bool FallbackObjectImp::deleteProperty(ExecState *exec,
+bool ObjcFallbackObjectImp::deleteProperty(ExecState *exec,
const Identifier &propertyName)
{
return false;
}
-Value FallbackObjectImp::defaultValue(ExecState *exec, Type hint) const
+Value ObjcFallbackObjectImp::defaultValue(ExecState *exec, Type hint) const
{
return _instance->getValueOfUndefinedField(exec, _item, hint);
}
virtual const char *name() const = 0;
virtual RuntimeType type() const = 0;
- virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const = 0;
- virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const = 0;
+ virtual KJS::Value valueFromInstance(ExecState *exec, const Instance *instance) const = 0;
+ virtual void setValueToInstance(ExecState *exec, const Instance *instance, const Value &aValue) const = 0;
virtual ~Field() {};
};
virtual Field *fieldNamed(const char *name, Instance *instance) const = 0;
- virtual Value fallbackObject(KJS::ExecState *exec, Bindings::Instance *instance, const KJS::Identifier &propertyName) { return Undefined(); }
+ virtual Value fallbackObject(ExecState *exec, Bindings::Instance *instance, const Identifier &propertyName) { return Undefined(); }
virtual ~Class() {};
};
-typedef void (*KJSDidExecuteFunctionPtr)(KJS::ExecState *exec, KJS::ObjectImp *rootObject);
+typedef void (*KJSDidExecuteFunctionPtr)(ExecState *exec, ObjectImp *rootObject);
class Instance
{
virtual Class *getClass() const = 0;
- virtual KJS::Value getValueOfField (KJS::ExecState *exec, const Field *aField) const;
- virtual KJS::Value getValueOfUndefinedField (KJS::ExecState *exec, const KJS::Identifier &property, KJS::Type hint) const { return Undefined(); };
- virtual void setValueOfField (KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const;
- virtual void setValueOfUndefinedField (KJS::ExecState *exec, const KJS::Identifier &property, const KJS::Value &aValue) {};
+ virtual Value getValueOfField (ExecState *exec, const Field *aField) const;
+ virtual Value getValueOfUndefinedField (ExecState *exec, const Identifier &property, Type hint) const { return Undefined(); };
+ virtual void setValueOfField (ExecState *exec, const Field *aField, const Value &aValue) const;
+ virtual void setValueOfUndefinedField (ExecState *exec, const Identifier &property, const Value &aValue) {};
- virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args) = 0;
+ virtual Value invokeMethod (ExecState *exec, const MethodList &method, const List &args) = 0;
+ virtual Value invokeDefaultMethod (ExecState *exec, const List &args) = 0;
- virtual KJS::Value defaultValue (KJS::Type hint) const = 0;
+ virtual Value defaultValue (Type hint) const = 0;
- virtual KJS::Value valueOf() const { return KJS::String(getClass()->name()); };
+ virtual Value valueOf() const { return String(getClass()->name()); };
virtual void setExecutionContext (RootObject *r) = 0;
virtual const RootObject *executionContext () const = 0;
class Array
{
public:
- virtual void setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const = 0;
- virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const = 0;
+ virtual void setValueAt(ExecState *exec, unsigned int index, const Value &aValue) const = 0;
+ virtual Value valueAt(ExecState *exec, unsigned int index) const = 0;
virtual unsigned int getLength() const = 0;
virtual ~Array() {};
};
return aValue;
}
+bool RuntimeObjectImp::implementsCall() const
+{
+ // Only true for default functions.
+ return true;
+}
+
+Value RuntimeObjectImp::call(ExecState *exec, Object &thisObj, const List &args)
+{
+ instance->begin();
+
+ Value aValue = getInternalInstance()->invokeDefaultMethod(exec, args);
+
+ instance->end();
+
+ return aValue;
+}
+
void setInternalInstance (Bindings::Instance *i) { instance = i; }
Bindings::Instance *getInternalInstance() const { return instance; }
+ virtual bool implementsCall() const;
+ virtual Value call(ExecState *exec, Object &thisObj, const List &args);
+
private:
static const ClassInfo info;
+2004-09-14 Richard Williamson <rjw@apple.com>
+
+ 1. Add class parameter to object allocation function. This is somewhat redundant, given that
+ the allocation function is in the class function vector, but people wanted to use the same
+ allocation function for different classes.
+
+ 2. Renamed NPN_Class to NPN_Invoke to match the name in the function vector.
+
+ 3. Add support for a default function on an object. This is a feature that ActiveX supports,
+ and will allow JavaScript code to be written that will look exactly the same for both ActiveX
+ plugins and Netscape or WebKit plugins. There are implementations included for the 'C' and
+ 'Objective-C' bindings.
+
+ There bugs are covered by
+
+ <rdar://problem/3776343> Support for default functions in the JavaScript bindings
+ <rdar://problem/3779186> NPN_Call needs to be renamed to NPN_Invoke
+ <rdar://problem/3674754> Need to implement latest npruntime.h
+
+ Reviewed by John.
+
+ * Plugins.subproj/WebNetscapePluginPackage.m:
+ (-[WebNetscapePluginPackage load]):
+ * Plugins.subproj/WebScriptObject.h:
+ * Plugins.subproj/npfunctions.h:
+ * Plugins.subproj/npruntime.h:
+
2004-09-13 Richard Williamson <rjw@apple.com>
D'oh. How many times can I screw up a simple fix!
browserFuncs.createobject = (NPN_CreateObjectProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_CreateObject);
browserFuncs.retainobject = (NPN_RetainObjectProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_RetainObject);
browserFuncs.releaseobject = (NPN_ReleaseObjectProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_ReleaseObject);
- browserFuncs.call = (NPN_CallProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_Call);
+ browserFuncs.invoke = (NPN_InvokeProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_Invoke);
+ browserFuncs.invokeDefault = (NPN_InvokeDefaultProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_InvokeDefault);
browserFuncs.evaluate = (NPN_EvaluateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_Evaluate);
browserFuncs.getproperty = (NPN_GetPropertyProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_GetProperty);
browserFuncs.setproperty = (NPN_SetPropertyProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_SetProperty);
browserFuncs.createobject = NPN_CreateObject;
browserFuncs.retainobject = NPN_RetainObject;
browserFuncs.releaseobject = NPN_ReleaseObject;
- browserFuncs.call = NPN_Call;
+ browserFuncs.invoke = NPN_Invoke;
+ browserFuncs.invokeDefault = NPN_InvokeDefault;
browserFuncs.evaluate = NPN_Evaluate;
browserFuncs.getproperty = NPN_GetProperty;
browserFuncs.setproperty = NPN_SetProperty;
*/
- (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)args;
+/*!
+ @method invokeDefaultMethodWithArguments:
+ @param args The args to pass the method.
+ @discussion If a script attempts to invoke a method on an exposed object
+ directory this method will be called.
+*/
+- (id)invokeDefaultMethodWithArguments:(NSArray *)args;
+
/*!
@method finalizeForWebScript
@discussion finalizeForScript is called on objects exposed to the script
typedef NPObject* (*NPN_CreateObjectProcPtr) (NPP, NPClass *aClass);
typedef NPObject* (*NPN_RetainObjectProcPtr) (NPObject *obj);
typedef void (*NPN_ReleaseObjectProcPtr) (NPObject *obj);
-typedef bool (*NPN_CallProcPtr) (NPP npp, NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPN_InvokeProcPtr) (NPP npp, NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPN_InvokeDefaultProcPtr) (NPP npp, NPObject *obj, const NPVariant *args, unsigned argCount, NPVariant *result);
typedef bool (*NPN_EvaluateProcPtr) (NPP npp, NPObject *obj, NPString *script, NPVariant *result);
typedef bool (*NPN_GetPropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result);
typedef bool (*NPN_SetPropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
NPN_CreateObjectProcPtr createobject;
NPN_RetainObjectProcPtr retainobject;
NPN_ReleaseObjectProcPtr releaseobject;
- NPN_CallProcPtr call;
+ NPN_InvokeProcPtr invoke;
+ NPN_InvokeDefaultProcPtr invokeDefault;
NPN_EvaluateProcPtr evaluate;
NPN_GetPropertyProcPtr getproperty;
NPN_SetPropertyProcPtr setproperty;
The NPVariant *result argument of these functions (where
applicable) should be released using NPN_ReleaseVariantValue().
*/
-typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp);
+typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass);
typedef void (*NPDeallocateFunctionPtr)(NPObject *obj);
typedef void (*NPInvalidateFunctionPtr)(NPObject *obj);
typedef bool (*NPHasMethodFunctionPtr)(NPClass *theClass, NPIdentifier name);
-typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);
+typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result);
typedef bool (*NPHasPropertyFunctionPtr)(NPClass *theClass, NPIdentifier name);
typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
typedef bool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
NPInvalidateFunctionPtr invalidate;
NPHasMethodFunctionPtr hasMethod;
NPInvokeFunctionPtr invoke;
+ NPInvokeDefaultFunctionPtr invokeDefault;
NPHasPropertyFunctionPtr hasProperty;
NPGetPropertyFunctionPtr getProperty;
NPSetPropertyFunctionPtr setProperty;
Calls made from plugin code to script must be made from the thread
on which the plugin was initialized.
*/
-bool NPN_Call(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result);
bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, NPVariant *result);
bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result);
bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value);