[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
rjw
rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:29:27 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 0f68b3865e529f112bc16ef0d9b20733f81088f2
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Mar 12 00:23:44 2004 +0000
Stitched together the NP stuff to our language independent
JavaScript binding stuff. Very close to being done.
Added program to test C bindings (and NP stuff). Just tests
properties. Will add methods and JavaScript access, etc.
Updated Makefile.am to account for new bindings/c directory.
Change NP_UTF8 from "const char *" to "char" to allow for
declarations like "const NP_UTF8 *" and "NP_UTF8 *". Ditto
for NP_UTF16.
Added NP_IsValidIdentifier().
Reviewed by Chris.
* JavaScriptCore.pbproj/project.pbxproj:
* Makefile.am:
* bindings/NP_jsobject.cpp:
(identiferFromNPIdentifier):
(NP_Evaluate):
* bindings/NP_runtime.cpp:
(NP_IdentifierFromUTF8):
(NP_IsValidIdentifier):
(NP_GetIdentifiers):
(NP_UTF8FromIdentifier):
(NP_SetExceptionWithUTF8):
(NP_SetException):
(NP_CreateStringWithUTF8):
(NP_CreateStringWithUTF16):
(NP_UTF8FromString):
(NP_UTF16FromString):
* bindings/NP_runtime.h:
* bindings/c/c_class.cpp: Added.
(CClass::_commonDelete):
(CClass::_commonCopy):
(CClass::_commonInit):
(_createClassesByIsAIfNecessary):
(CClass::classForIsA):
(CClass::CClass):
(CClass::name):
(CClass::methodsNamed):
(CClass::fieldNamed):
* bindings/c/c_class.h: Added.
(KJS::Bindings::CClass::~CClass):
(KJS::Bindings::CClass::CClass):
(KJS::Bindings::CClass::operator=):
(KJS::Bindings::CClass::constructorAt):
(KJS::Bindings::CClass::numConstructors):
* bindings/c/c_instance.cpp: Added.
(CInstance::CInstance):
(CInstance::~CInstance):
(CInstance::operator=):
(CInstance::getClass):
(CInstance::begin):
(CInstance::end):
(CInstance::invokeMethod):
(CInstance::defaultValue):
(CInstance::stringValue):
(CInstance::numberValue):
(CInstance::booleanValue):
(CInstance::valueOf):
* bindings/c/c_instance.h: Added.
(KJS::Bindings::CInstance::getObject):
* bindings/c/c_runtime.cpp: Added.
(CField::valueFromInstance):
(CField::setValueToInstance):
* bindings/c/c_runtime.h: Added.
(KJS::Bindings::CField::CField):
(KJS::Bindings::CField::name):
(KJS::Bindings::CField::type):
(KJS::Bindings::CMethod::CMethod):
(KJS::Bindings::CMethod::name):
(KJS::Bindings::CMethod::numParameters):
* bindings/c/c_utility.cpp: Added.
(coerceValueToNPValueType):
(convertValueToNPValueType):
(convertNPValueTypeToValue):
* bindings/c/c_utility.h: Added.
* bindings/make_testbindings:
* bindings/runtime.cpp:
(Instance::createBindingForLanguageInstance):
* bindings/runtime.h:
(KJS::Bindings::Instance::):
* bindings/testbindings.cpp: Added.
(initializeIdentifiers):
(myInterfaceHasProperty):
(myInterfaceHasMethod):
(myInterfaceGetProperty):
(myInterfaceSetProperty):
(myInterfaceInvoke):
(myInterfaceAllocate):
(myInterfaceInvalidate):
(myInterfaceDeallocate):
(GlobalImp::className):
(readJavaScriptFromFile):
(main):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6212 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index bd360d4..ec39b5f 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,103 @@
+2004-03-11 Richard Williamson <rjw at apple.com>
+
+ Stitched together the NP stuff to our language independent
+ JavaScript binding stuff. Very close to being done.
+
+ Added program to test C bindings (and NP stuff). Just tests
+ properties. Will add methods and JavaScript access, etc.
+
+ Updated Makefile.am to account for new bindings/c directory.
+
+ Change NP_UTF8 from "const char *" to "char" to allow for
+ declarations like "const NP_UTF8 *" and "NP_UTF8 *". Ditto
+ for NP_UTF16.
+
+ Added NP_IsValidIdentifier().
+
+ Reviewed by Chris.
+
+ * JavaScriptCore.pbproj/project.pbxproj:
+ * Makefile.am:
+ * bindings/NP_jsobject.cpp:
+ (identiferFromNPIdentifier):
+ (NP_Evaluate):
+ * bindings/NP_runtime.cpp:
+ (NP_IdentifierFromUTF8):
+ (NP_IsValidIdentifier):
+ (NP_GetIdentifiers):
+ (NP_UTF8FromIdentifier):
+ (NP_SetExceptionWithUTF8):
+ (NP_SetException):
+ (NP_CreateStringWithUTF8):
+ (NP_CreateStringWithUTF16):
+ (NP_UTF8FromString):
+ (NP_UTF16FromString):
+ * bindings/NP_runtime.h:
+ * bindings/c/c_class.cpp: Added.
+ (CClass::_commonDelete):
+ (CClass::_commonCopy):
+ (CClass::_commonInit):
+ (_createClassesByIsAIfNecessary):
+ (CClass::classForIsA):
+ (CClass::CClass):
+ (CClass::name):
+ (CClass::methodsNamed):
+ (CClass::fieldNamed):
+ * bindings/c/c_class.h: Added.
+ (KJS::Bindings::CClass::~CClass):
+ (KJS::Bindings::CClass::CClass):
+ (KJS::Bindings::CClass::operator=):
+ (KJS::Bindings::CClass::constructorAt):
+ (KJS::Bindings::CClass::numConstructors):
+ * bindings/c/c_instance.cpp: Added.
+ (CInstance::CInstance):
+ (CInstance::~CInstance):
+ (CInstance::operator=):
+ (CInstance::getClass):
+ (CInstance::begin):
+ (CInstance::end):
+ (CInstance::invokeMethod):
+ (CInstance::defaultValue):
+ (CInstance::stringValue):
+ (CInstance::numberValue):
+ (CInstance::booleanValue):
+ (CInstance::valueOf):
+ * bindings/c/c_instance.h: Added.
+ (KJS::Bindings::CInstance::getObject):
+ * bindings/c/c_runtime.cpp: Added.
+ (CField::valueFromInstance):
+ (CField::setValueToInstance):
+ * bindings/c/c_runtime.h: Added.
+ (KJS::Bindings::CField::CField):
+ (KJS::Bindings::CField::name):
+ (KJS::Bindings::CField::type):
+ (KJS::Bindings::CMethod::CMethod):
+ (KJS::Bindings::CMethod::name):
+ (KJS::Bindings::CMethod::numParameters):
+ * bindings/c/c_utility.cpp: Added.
+ (coerceValueToNPValueType):
+ (convertValueToNPValueType):
+ (convertNPValueTypeToValue):
+ * bindings/c/c_utility.h: Added.
+ * bindings/make_testbindings:
+ * bindings/runtime.cpp:
+ (Instance::createBindingForLanguageInstance):
+ * bindings/runtime.h:
+ (KJS::Bindings::Instance::):
+ * bindings/testbindings.cpp: Added.
+ (initializeIdentifiers):
+ (myInterfaceHasProperty):
+ (myInterfaceHasMethod):
+ (myInterfaceGetProperty):
+ (myInterfaceSetProperty):
+ (myInterfaceInvoke):
+ (myInterfaceAllocate):
+ (myInterfaceInvalidate):
+ (myInterfaceDeallocate):
+ (GlobalImp::className):
+ (readJavaScriptFromFile):
+ (main):
+
2004-03-10 Richard Williamson <rjw at apple.com>
Made changes to support new asychronous approach to calls from
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index ee91c4c..284f672 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -250,6 +250,10 @@
7084D99505DD6211007E4C0E,
5114F47E05E4426200D1BBBD,
515B876B05F532B900EABBF9,
+ 5182A45B05FFCF4B00CBD2F2,
+ 5182A47105FFD45000CBD2F2,
+ 5182A48E05FFFDC500CBD2F2,
+ 5182A53D06012C3000CBD2F2,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@@ -318,6 +322,10 @@
5114F47D05E4426200D1BBBD,
515B879305F535B300EABBF9,
51532CC805F7FD2C00EC779C,
+ 5182A45A05FFCF4B00CBD2F2,
+ 5182A48D05FFFDC500CBD2F2,
+ 5182A4FC06010F8200CBD2F2,
+ 5182A53C06012C3000CBD2F2,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@@ -642,6 +650,126 @@
);
};
};
+ 5182A45605FFCF4B00CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.cpp.cpp;
+ name = c_instance.cpp;
+ path = bindings/c/c_instance.cpp;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A45705FFCF4B00CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ name = c_instance.h;
+ path = bindings/c/c_instance.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A45A05FFCF4B00CBD2F2 = {
+ fileRef = 5182A45605FFCF4B00CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A45B05FFCF4B00CBD2F2 = {
+ fileRef = 5182A45705FFCF4B00CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A47005FFD45000CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ name = c_utility.h;
+ path = bindings/c/c_utility.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A47105FFD45000CBD2F2 = {
+ fileRef = 5182A47005FFD45000CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A48B05FFFDC400CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.cpp.cpp;
+ name = c_runtime.cpp;
+ path = bindings/c/c_runtime.cpp;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A48C05FFFDC400CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ name = c_runtime.h;
+ path = bindings/c/c_runtime.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A48D05FFFDC500CBD2F2 = {
+ fileRef = 5182A48B05FFFDC400CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A48E05FFFDC500CBD2F2 = {
+ fileRef = 5182A48C05FFFDC400CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A4FB06010F8200CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.cpp.cpp;
+ name = c_utility.cpp;
+ path = bindings/c/c_utility.cpp;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A4FC06010F8200CBD2F2 = {
+ fileRef = 5182A4FB06010F8200CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A53A06012C3000CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.cpp.cpp;
+ name = c_class.cpp;
+ path = bindings/c/c_class.cpp;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A53B06012C3000CBD2F2 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ name = c_class.h;
+ path = bindings/c/c_class.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 5182A53C06012C3000CBD2F2 = {
+ fileRef = 5182A53A06012C3000CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 5182A53D06012C3000CBD2F2 = {
+ fileRef = 5182A53B06012C3000CBD2F2;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
51856D8F0562EE95008B9D83 = {
fileEncoding = 30;
isa = PBXFileReference;
@@ -674,6 +802,14 @@
};
51856D950562EE9C008B9D83 = {
children = (
+ 5182A53A06012C3000CBD2F2,
+ 5182A53B06012C3000CBD2F2,
+ 5182A45605FFCF4B00CBD2F2,
+ 5182A45705FFCF4B00CBD2F2,
+ 5182A48B05FFFDC400CBD2F2,
+ 5182A48C05FFFDC400CBD2F2,
+ 5182A4FB06010F8200CBD2F2,
+ 5182A47005FFD45000CBD2F2,
51532CC705F7FD2C00EC779C,
515B876A05F532B900EABBF9,
515B879205F535B300EABBF9,
diff --git a/JavaScriptCore/Makefile.am b/JavaScriptCore/Makefile.am
index 2e6942a..346e0e0 100644
--- a/JavaScriptCore/Makefile.am
+++ b/JavaScriptCore/Makefile.am
@@ -9,7 +9,7 @@ kjs_testkjs_DEPENDENCIES = JavaScriptCore-stamp
kjs_testkjs_LDFLAGS = -F$(SYMROOTS) -framework JavaScriptCore
all-am: JavaScriptCore-stamp
-JavaScriptCore-stamp: kjs/*.cpp kjs/*.h pcre/*.c pcre/*.h bindings/*.h bindings/*.cpp bindings/jni/*.cpp bindings/jni/*.h bindings/objc/*.h bindings/objc/*.mm
+JavaScriptCore-stamp: kjs/*.cpp kjs/*.h pcre/*.c pcre/*.h bindings/*.h bindings/*.cpp bindings/jni/*.cpp bindings/jni/*.h bindings/objc/*.h bindings/objc/*.mm bindings/c/*.h bindings/c/*.cpp
xcodebuild -buildstyle $(BUILDSTYLE) OBJROOT=$(SYMROOTS) SYMROOT=$(SYMROOTS) DSTROOT=$(SYMROOTS) && touch $@
clean-am:
xcodebuild clean OBJROOT=$(SYMROOTS) SYMROOT=$(SYMROOTS) DSTROOT=$(SYMROOTS)
diff --git a/JavaScriptCore/bindings/NP_jsobject.cpp b/JavaScriptCore/bindings/NP_jsobject.cpp
index 81a1072..cadf71e 100644
--- a/JavaScriptCore/bindings/NP_jsobject.cpp
+++ b/JavaScriptCore/bindings/NP_jsobject.cpp
@@ -24,6 +24,8 @@
*/
#include <NP_runtime.h>
+#include <c_utility.h>
+
#include <runtime.h>
#include <runtime_object.h>
#include <runtime_root.h>
@@ -31,32 +33,6 @@
using namespace KJS;
using namespace KJS::Bindings;
-typedef enum
-{
- NP_NumberValueType,
- NP_StringValueType,
- NP_BooleanValueType,
- NP_NullValueType,
- NP_UndefinedValueType,
- NP_ObjectValueType,
- NP_InvalidValueType
-} NP_ValueType;
-
-NP_Object *coerceValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value, NP_ValueType type)
-{
- return 0;
-}
-
-NP_Object *convertValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value)
-{
- return 0;
-}
-
-Value convertNPValueTypeToValue (KJS::ExecState *exec, const NP_Object *obj)
-{
- return Undefined();
-}
-
static KJS::List listFromNPArray(KJS::ExecState *exec, NP_Object **args, unsigned argCount)
{
KJS::List aList;
@@ -98,11 +74,11 @@ NP_Class *NP_JavaScriptObjectClass = javascriptClass;
Identifier identiferFromNPIdentifier(NP_Identifier ident)
{
NP_String *string = NP_CreateStringWithUTF8 (NP_UTF8FromIdentifier (ident));
- NP_UTF16 methodName = NP_UTF16FromString (string);
+ NP_UTF16 *methodName = NP_UTF16FromString (string);
int32_t length = NP_StringLength (string);
NP_ReleaseObject (string);
Identifier identifier ((const KJS::UChar*)methodName, length);
- free (methodName);
+ free ((void *)methodName);
return identifier;
}
@@ -146,11 +122,11 @@ void NP_Evaluate (NP_JavaScriptObject *o, NP_String *s, NP_JavaScriptResultInter
ExecState *exec = obj->root->interpreter()->globalExec();
Object thisObj = Object(const_cast<ObjectImp*>(obj->imp));
Interpreter::lock();
- NP_UTF16 script = NP_UTF16FromString (s);
+ NP_UTF16 *script = NP_UTF16FromString (s);
int32_t length = NP_StringLength (s);
KJS::Value result = obj->root->interpreter()->evaluate(UString((const UChar *)script,length)).value();
Interpreter::unlock();
- free (script);
+ free ((void *)script);
NP_Object *npresult = convertValueToNPValueType(exec, result);
diff --git a/JavaScriptCore/bindings/c/c_class.cpp b/JavaScriptCore/bindings/c/c_class.cpp
new file mode 100644
index 0000000..aba7d0f
--- /dev/null
+++ b/JavaScriptCore/bindings/c/c_class.cpp
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <c_class.h>
+
+using namespace KJS::Bindings;
+
+void CClass::_commonDelete() {
+ CFRelease (_fields);
+ CFRelease (_methods);
+}
+
+
+void CClass::_commonCopy(const CClass &other) {
+ _isa = other._isa;
+ _methods = CFDictionaryCreateCopy (NULL, other._methods);
+ _fields = CFDictionaryCreateCopy (NULL, other._fields);
+}
+
+
+void CClass::_commonInit (NP_Class *aClass)
+{
+ _isa = aClass;
+ _methods = CFDictionaryCreateMutable(NULL, 16, &kCFTypeDictionaryKeyCallBacks, NULL);
+ _fields = CFDictionaryCreateMutable(NULL, 16, &kCFTypeDictionaryKeyCallBacks, NULL);
+}
+
+
+static CFMutableDictionaryRef classesByIsA = 0;
+
+static void _createClassesByIsAIfNecessary()
+{
+ if (classesByIsA == 0)
+ classesByIsA = CFDictionaryCreateMutable (NULL, 0, NULL, NULL);
+}
+
+CClass *CClass::classForIsA (NP_Class *isa)
+{
+ _createClassesByIsAIfNecessary();
+
+ CClass *aClass = (CClass *)CFDictionaryGetValue(classesByIsA, isa);
+ if (aClass == NULL) {
+ aClass = new CClass (isa);
+ CFDictionaryAddValue (classesByIsA, isa, aClass);
+ }
+
+ return aClass;
+}
+
+
+CClass::CClass (NP_Class *isa)
+{
+ _commonInit (isa);
+}
+
+const char *CClass::name() const
+{
+ return "";
+}
+
+MethodList CClass::methodsNamed(const char *_name) const
+{
+ MethodList methodList;
+
+ CFStringRef methodName = CFStringCreateWithCString(NULL, _name, kCFStringEncodingASCII);
+ Method *method = (Method *)CFDictionaryGetValue (_methods, methodName);
+ if (method) {
+ CFRelease (methodName);
+ methodList.addMethod(method);
+ return methodList;
+ }
+
+ if (NP_IsValidIdentifier (_name)) {
+ NP_Identifier ident = NP_IdentifierFromUTF8 (_name);
+ if (_isa->hasMethod && _isa->hasMethod (_isa, ident)){
+ Method *aMethod = new CMethod (ident);
+ CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, methodName, aMethod);
+ methodList.addMethod (aMethod);
+ }
+ }
+
+ CFRelease (methodName);
+
+ return methodList;
+}
+
+
+Field *CClass::fieldNamed(const char *name) const
+{
+ CFStringRef fieldName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
+ Field *aField = (Field *)CFDictionaryGetValue (_fields, fieldName);
+ if (aField) {
+ CFRelease (fieldName);
+ return aField;
+ }
+
+ if (NP_IsValidIdentifier (name)) {
+ NP_Identifier ident = NP_IdentifierFromUTF8 (name);
+ if (_isa->hasProperty && _isa->hasProperty (_isa, ident)){
+ aField = new CField (ident);
+ CFDictionaryAddValue ((CFMutableDictionaryRef)_fields, fieldName, aField);
+ }
+ }
+
+ CFRelease (fieldName);
+
+ return aField;
+};
diff --git a/JavaScriptCore/bindings/objc/objc_class.h b/JavaScriptCore/bindings/c/c_class.h
similarity index 82%
copy from JavaScriptCore/bindings/objc/objc_class.h
copy to JavaScriptCore/bindings/c/c_class.h
index 1ca73e1..c59f40b 100644
--- a/JavaScriptCore/bindings/objc/objc_class.h
+++ b/JavaScriptCore/bindings/c/c_class.h
@@ -29,38 +29,38 @@
#include <runtime.h>
-#include <objc_header.h>
-#include <objc_runtime.h>
+#include <NP_runtime.h>
+#include <c_runtime.h>
namespace KJS {
namespace Bindings {
-class ObjcClass : public KJS::Bindings::Class
+class CClass : public KJS::Bindings::Class
{
// Use the public static factory methods to get instances of JavaClass.
protected:
- void _commonInit (ClassStructPtr aClass);
- void _commonCopy(const ObjcClass &other);
+ void _commonInit (NP_Class *aClass);
+ void _commonCopy(const CClass &other);
void _commonDelete();
-
- ObjcClass (ClassStructPtr aClass);
-
+
public:
+ CClass (NP_Class *aClass);
+
// Return the cached ObjC of the specified name.
- //static ObjcClass *classForName (const char *name);
- static ObjcClass *classForIsA (ClassStructPtr aClass);
+ //static CClass *classForName (const char *name);
+ static CClass *classForIsA (NP_Class *aClass);
- ~ObjcClass () {
+ ~CClass () {
_commonDelete();
}
- ObjcClass (const ObjcClass &other) : Class() {
+ CClass (const CClass &other) : Class() {
_commonCopy (other);
};
- ObjcClass &operator=(const ObjcClass &other)
+ CClass &operator=(const CClass &other)
{
if (this == &other)
return *this;
@@ -84,7 +84,7 @@ public:
virtual long numConstructors() const { return 0; };
private:
- ClassStructPtr _isa;
+ NP_Class *_isa;
CFDictionaryRef _methods;
CFDictionaryRef _fields;
};
diff --git a/JavaScriptCore/bindings/c/c_instance.cpp b/JavaScriptCore/bindings/c/c_instance.cpp
new file mode 100644
index 0000000..5e49c0d
--- /dev/null
+++ b/JavaScriptCore/bindings/c/c_instance.cpp
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <c_class.h>
+#include <c_instance.h>
+#include <c_runtime.h>
+#include <c_utility.h>
+
+#ifdef NDEBUG
+#define C_LOG(formatAndArgs...) ((void)0)
+#else
+#define C_LOG(formatAndArgs...) { \
+ fprintf (stderr, "%s:%d -- %s: ", __FILE__, __LINE__, __FUNCTION__); \
+ fprintf(stderr, formatAndArgs); \
+}
+#endif
+
+using namespace KJS::Bindings;
+using namespace KJS;
+
+CInstance::CInstance (NP_Object *o)
+{
+ _object = NP_RetainObject (o);
+};
+
+CInstance::~CInstance ()
+{
+ NP_ReleaseObject (_object);
+ delete _class;
+}
+
+
+CInstance::CInstance (const CInstance &other) : Instance()
+{
+ _object = NP_RetainObject (other._object);
+};
+
+CInstance &CInstance::operator=(const CInstance &other){
+ if (this == &other)
+ return *this;
+
+ NP_Object *_oldObject = _object;
+ _object= NP_RetainObject (other._object);
+ NP_ReleaseObject (_oldObject);
+
+ return *this;
+};
+
+Class *CInstance::getClass() const
+{
+ if (!_class) {
+ _class = new CClass (_object->_class);
+ }
+ return _class;
+}
+
+
+void CInstance::begin()
+{
+ // Do nothing.
+}
+
+void CInstance::end()
+{
+ // Do nothing.
+}
+
+Value CInstance::invokeMethod (KJS::ExecState *exec, const MethodList &methodList, const List &args)
+{
+ Value resultValue;
+
+ // Overloading methods are not allowed by NP_Objects. Should only be one
+ // name match for a particular method.
+ assert (methodList.length() == 1);
+
+ CMethod *method = 0;
+ method = static_cast<CMethod*>(methodList.methodAt(0));
+
+ NP_Identifier ident = NP_IdentifierFromUTF8 (method->name());
+ if (!_object->_class->hasMethod (_object->_class, ident))
+ return Undefined();
+
+ unsigned i, count = args.size();
+ NP_Object **cArgs;
+ NP_Object *localBuffer[128];
+ if (count > 128)
+ cArgs = (NP_Object **)malloc (sizeof(NP_Object *)*count);
+ else
+ cArgs = localBuffer;
+
+ for (i = 0; i < count; i++) {
+ cArgs[i] = convertValueToNPValueType (exec, args.at(i));
+ }
+
+ // Invoke the 'C' method.
+ NP_Object *result = _object->_class->invoke (_object, ident, cArgs, count);
+
+ resultValue = convertNPValueTypeToValue (exec, result);
+
+ if (cArgs != localBuffer)
+ free ((void *)cArgs);
+
+ NP_ReleaseObject (result);
+
+ return resultValue;
+}
+
+
+KJS::Value CInstance::defaultValue (KJS::Type hint) const
+{
+ if (hint == KJS::StringType) {
+ return stringValue();
+ }
+ else if (hint == KJS::NumberType) {
+ return numberValue();
+ }
+ else if (hint == KJS::BooleanType) {
+ return booleanValue();
+ }
+ else if (hint == KJS::UnspecifiedType) {
+ if (NP_IsKindOfClass (_object, NP_StringClass)) {
+ return stringValue();
+ }
+ else if (NP_IsKindOfClass (_object, NP_NumberClass)) {
+ return numberValue();
+ }
+ else if (NP_IsKindOfClass (_object, NP_BooleanClass)) {
+ return booleanValue();
+ }
+ else if (NP_IsKindOfClass (_object, NP_NullClass)) {
+ return Null();
+ }
+ else if (NP_IsKindOfClass (_object, NP_UndefinedClass)) {
+ return Undefined();
+ }
+ }
+
+ return valueOf();
+}
+
+KJS::Value CInstance::stringValue() const
+{
+ // FIXME: Implement something sensible, like calling toString...
+ KJS::String v("");
+ return v;
+}
+
+KJS::Value CInstance::numberValue() const
+{
+ // FIXME: Implement something sensible
+ KJS::Number v(0);
+ return v;
+}
+
+KJS::Value CInstance::booleanValue() const
+{
+ // FIXME: Implement something sensible
+ KJS::Boolean v((bool)0);
+ return v;
+}
+
+KJS::Value CInstance::valueOf() const
+{
+ return stringValue();
+};
diff --git a/JavaScriptCore/bindings/objc/objc_instance.h b/JavaScriptCore/bindings/c/c_instance.h
similarity index 76%
copy from JavaScriptCore/bindings/objc/objc_instance.h
copy to JavaScriptCore/bindings/c/c_instance.h
index 9ac1f8b..d6ea666 100644
--- a/JavaScriptCore/bindings/objc/objc_instance.h
+++ b/JavaScriptCore/bindings/c/c_instance.h
@@ -22,33 +22,31 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _BINDINGS_OBJC_INSTANCE_H_
-#define _BINDINGS_OBJC_INSTANCE_H_
+#ifndef _BINDINGS_C_INSTANCE_H_
+#define _BINDINGS_C_INSTANCE_H_
-#include <CoreFoundation/CoreFoundation.h>
+#include <NP_runtime.h>
-#include <objc_class.h>
-#include <objc_runtime.h>
-#include <objc_utility.h>
+#include <runtime.h>
namespace KJS {
namespace Bindings {
-class ObjcClass;
+class CClass;
-class ObjcInstance : public Instance
+class CInstance : public Instance
{
public:
- ObjcInstance (ObjectStructPtr instance);
+ CInstance (NP_Object *instance);
- ~ObjcInstance ();
+ ~CInstance ();
virtual Class *getClass() const;
- ObjcInstance (const ObjcInstance &other);
+ CInstance (const CInstance &other);
- ObjcInstance &operator=(const ObjcInstance &other);
+ CInstance &operator=(const CInstance &other);
virtual void begin();
virtual void end();
@@ -58,17 +56,15 @@ public:
virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args);
- ObjectStructPtr getObject() const { return _instance; }
-
KJS::Value stringValue() const;
KJS::Value numberValue() const;
KJS::Value booleanValue() const;
+ NP_Object *getObject() const { return _object; }
+
private:
- ObjectStructPtr _instance;
- mutable ObjcClass *_class;
- ObjectStructPtr _pool;
- long _beginCount;
+ mutable CClass *_class;
+ NP_Object *_object;
};
} // namespace Bindings
diff --git a/WebCore/kwq/KWQEditCommand.mm b/JavaScriptCore/bindings/c/c_runtime.cpp
similarity index 55%
copy from WebCore/kwq/KWQEditCommand.mm
copy to JavaScriptCore/bindings/c/c_runtime.cpp
index fffbe24..d98fa3a 100644
--- a/WebCore/kwq/KWQEditCommand.mm
+++ b/JavaScriptCore/bindings/c/c_runtime.cpp
@@ -22,40 +22,41 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <JavaScriptCore/internal.h>
-#import "KWQEditCommand.h"
+#include <c_instance.h>
+#include <c_runtime.h>
+#include <c_utility.h>
-#import "KWQAssertions.h"
-#import "htmlediting_impl.h"
+#include <runtime_array.h>
+#include <runtime_object.h>
-using khtml::EditCommandImpl;
- at implementation KWQEditCommand
+using namespace KJS;
+using namespace KJS::Bindings;
-- (id)initWithEditCommandImpl:(EditCommandImpl *)impl
-{
- ASSERT(impl);
- [super init];
- m_impl = impl;
- impl->ref();
- return self;
-}
+// ---------------------- CMethod ----------------------
-- (void)dealloc
-{
- if (m_impl)
- m_impl->deref();
- [super dealloc];
-}
-+ (KWQEditCommand *)commandWithEditCommandImpl:(EditCommandImpl *)impl
+
+// ---------------------- CField ----------------------
+
+Value CField::valueFromInstance(KJS::ExecState *exec, const Instance *inst) const
{
- return [[[KWQEditCommand alloc] initWithEditCommandImpl:impl] autorelease];
+ const CInstance *instance = static_cast<const CInstance*>(inst);
+ NP_Object *obj = instance->getObject();
+ NP_Object *property = obj->_class->getProperty (obj, _fieldIdentifier);
+ Value aValue = convertNPValueTypeToValue (exec, property);
+ return aValue;
}
-- (EditCommandImpl *)impl
+void CField::setValueToInstance(KJS::ExecState *exec, const Instance *inst, const KJS::Value &aValue) const
{
- return m_impl;
+ const CInstance *instance = static_cast<const CInstance*>(inst);
+ NP_Object *obj = instance->getObject();
+ NP_Object *value = convertValueToNPValueType (exec, aValue);
+ obj->_class->setProperty (obj, _fieldIdentifier, value);
}
- at end
\ No newline at end of file
+// ---------------------- CArray ----------------------
+
diff --git a/JavaScriptCore/bindings/objc/objc_runtime.h b/JavaScriptCore/bindings/c/c_runtime.h
similarity index 57%
copy from JavaScriptCore/bindings/objc/objc_runtime.h
copy to JavaScriptCore/bindings/c/c_runtime.h
index 2e1bc94..1e67f7b 100644
--- a/JavaScriptCore/bindings/objc/objc_runtime.h
+++ b/JavaScriptCore/bindings/c/c_runtime.h
@@ -27,11 +27,11 @@
#include <CoreFoundation/CoreFoundation.h>
+#include <NP_runtime.h>
+
#include <runtime.h>
#include <ustring.h>
-#include <objc_header.h>
-
namespace KJS
{
class Value;
@@ -39,94 +39,58 @@ class Value;
namespace Bindings
{
-class ObjcField : public Field
+class CField : public Field
{
public:
- ObjcField(Ivar ivar);
-
- ~ObjcField() {};
-
- ObjcField(const ObjcField &other) : Field() {
- _ivar = other._ivar;
+ CField(NP_Identifier ident) : Field() {
+ _fieldIdentifier = ident;
};
- ObjcField &operator=(const ObjcField &other) {
- if (this == &other)
- return *this;
-
- _ivar = other._ivar;
-
- return *this;
- };
-
virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;
virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;
- virtual const char *name() const;
- virtual RuntimeType type() const;
+ virtual const char *name() const { return NP_UTF8FromIdentifier(_fieldIdentifier); }
+ virtual RuntimeType type() const { return ""; }
private:
- Ivar _ivar;
+ NP_Identifier _fieldIdentifier;
};
-class ObjcMethod : public Method
+class CMethod : public Method
{
public:
- ObjcMethod() : Method(), _objcClass(0), _selector(0) {};
-
- ObjcMethod(struct objc_class *aClass, const char *_selector);
- ~ObjcMethod () {
- };
+ CMethod() : Method(), _methodIdentifier(0) {};
- ObjcMethod(const ObjcMethod &other) : Method() {
- _objcClass = other._objcClass;
- _selector = other._selector;
- };
+ CMethod(NP_Identifier ident) : Method(), _methodIdentifier(ident) {};
- ObjcMethod &operator=(const ObjcMethod &other) {
- if (this == &other)
- return *this;
-
- _objcClass = other._objcClass;
- _selector = other._selector;
-
- return *this;
- }
+ virtual const char *name() const { return NP_UTF8FromIdentifier(_methodIdentifier); };
- virtual const char *name() const;
+ virtual long numParameters() const { return 0; };
- virtual long numParameters() const;
-
- NSMethodSignature *getMethodSignature() const;
-
private:
- struct objc_class *_objcClass;
- const char *_selector;
+ NP_Identifier _methodIdentifier;
};
-class ObjcArray : public Array
+#if 0
+class CArray : public Array
{
public:
- ObjcArray (ObjectStructPtr a);
+ CArray (ObjectStructPtr a);
- ObjcArray (const ObjcArray &other);
+ CArray (const CArray &other);
- ObjcArray &operator=(const ObjcArray &other);
+ CArray &operator=(const CArray &other);
virtual void setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;
virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;
virtual unsigned int getLength() const;
- virtual ~ObjcArray();
-
- ObjectStructPtr getObjcArray() const { return _array; }
-
- static KJS::Value convertObjcArrayToArray (KJS::ExecState *exec, ObjectStructPtr anObject);
+ virtual ~CArray();
private:
- ObjectStructPtr _array;
};
+#endif
} // namespace Bindings
diff --git a/WebCore/kwq/KWQEditCommand.h b/JavaScriptCore/bindings/c/c_utility.cpp
similarity index 78%
copy from WebCore/kwq/KWQEditCommand.h
copy to JavaScriptCore/bindings/c/c_utility.cpp
index 676eb03..062afb0 100644
--- a/WebCore/kwq/KWQEditCommand.h
+++ b/JavaScriptCore/bindings/c/c_utility.cpp
@@ -22,15 +22,22 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <c_utility.h>
-#include "htmlediting.h"
+using namespace KJS;
- at interface KWQEditCommand : NSObject
+NP_Object *coerceValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value, NP_ValueType type)
{
- khtml::EditCommandImpl *m_impl;
+ return 0;
}
-+ (KWQEditCommand *)commandWithEditCommandImpl:(khtml::EditCommandImpl *)impl;
-- (khtml::EditCommandImpl *)impl;
+NP_Object *convertValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value)
+{
+ return 0;
+}
+
+Value convertNPValueTypeToValue (KJS::ExecState *exec, const NP_Object *obj)
+{
+ return Undefined();
+}
- at end
\ No newline at end of file
diff --git a/JavaScriptCore/bindings/objc/objc_header.h b/JavaScriptCore/bindings/c/c_utility.h
similarity index 68%
copy from JavaScriptCore/bindings/objc/objc_header.h
copy to JavaScriptCore/bindings/c/c_utility.h
index 2dd7a26..7f2230c 100644
--- a/JavaScriptCore/bindings/objc/objc_header.h
+++ b/JavaScriptCore/bindings/c/c_utility.h
@@ -22,26 +22,29 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _BINDINGS_OBJC_HEADER_H_
-#define _BINDINGS_OBJC_HEADER_H_
+#ifndef _C_UTILITY_H_
+#define _C_UTILITY_H_
-#ifdef __OBJC__
-#include <objc/objc-class.h>
-#include <objc/objc-runtime.h>
+#include <NP_runtime.h>
-typedef struct objc_class *ClassStructPtr;
-typedef struct objc_object *ObjectStructPtr;
+#include <runtime.h>
+#include <runtime_object.h>
+#include <runtime_root.h>
- at class NSMethodSignature;
+typedef enum
+{
+ NP_NumberValueType,
+ NP_StringValueType,
+ NP_BooleanValueType,
+ NP_NullValueType,
+ NP_UndefinedValueType,
+ NP_ObjectValueType,
+ NP_InvalidValueType
+} NP_ValueType;
-#else
-typedef struct objc_ivar {} *Ivar;
-typedef struct objc_class {} *ClassStructPtr;
-typedef struct objc_object {} *ObjectStructPtr;
-
-class NSMethodSignature;
+extern NP_Object *coerceValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value, NP_ValueType type);
+extern NP_Object *convertValueToNPValueType (KJS::ExecState *exec, const KJS::Value &value);
+extern KJS::Value convertNPValueTypeToValue (KJS::ExecState *exec, const NP_Object *obj);
#endif
-
-#endif
\ No newline at end of file
diff --git a/JavaScriptCore/bindings/make_testbindings b/JavaScriptCore/bindings/make_testbindings
index 228862b..1f528fe 100755
--- a/JavaScriptCore/bindings/make_testbindings
+++ b/JavaScriptCore/bindings/make_testbindings
@@ -1,2 +1,2 @@
-cc -g -o testbindings testbindings.mm -I../kjs -F$SYMROOTS -framework JavaScriptCore -framework Foundation -lstdc++
-cc -g -o testbindings testbindings.cpp -I../kjs -F$SYMROOTS -framework JavaScriptCore -framework Foundation -lstdc++
+cc -g -o testbindingsM testbindings.mm -I../kjs -F$SYMROOTS -framework JavaScriptCore -framework Foundation -lstdc++
+cc -g -o testbindingsC testbindings.cpp -I../kjs -F$SYMROOTS -framework JavaScriptCore -framework Foundation -lstdc++
diff --git a/JavaScriptCore/bindings/npruntime.cpp b/JavaScriptCore/bindings/npruntime.cpp
index c59037c..6dffade 100644
--- a/JavaScriptCore/bindings/npruntime.cpp
+++ b/JavaScriptCore/bindings/npruntime.cpp
@@ -76,7 +76,7 @@ static const char **identifierNames = 0;
static unsigned int maxIdentifierNames;
static NP_Identifier identifierCount = 1;
-NP_Identifier NP_IdentifierFromUTF8 (NP_UTF8 name)
+NP_Identifier NP_IdentifierFromUTF8 (const NP_UTF8 *name)
{
NP_Identifier identifier = 0;
@@ -105,16 +105,26 @@ NP_Identifier NP_IdentifierFromUTF8 (NP_UTF8 name)
return identifier;
}
-void NP_GetIdentifiers (NP_UTF8 *names, int nameCount, NP_Identifier *identifiers)
+bool NP_IsValidIdentifier (const NP_UTF8 *name)
{
+ return CFDictionaryGetValue (getIdentifierDictionary(), (const void *)name) == 0 ? false : true;
}
-NP_UTF8 NP_UTF8FromIdentifier (NP_Identifier identifier)
+void NP_GetIdentifiers (const NP_UTF8 **names, int nameCount, NP_Identifier *identifiers)
+{
+ int i;
+
+ for (i = 0; i < nameCount; i++) {
+ identifiers[i] = NP_IdentifierFromUTF8 (names[i]);
+ }
+}
+
+const NP_UTF8 *NP_UTF8FromIdentifier (NP_Identifier identifier)
{
if (identifier == 0 || identifier >= identifierCount)
return NULL;
- return (NP_UTF8)identifierNames[identifier];
+ return (const NP_UTF8 *)identifierNames[identifier];
}
NP_Object *NP_CreateObject (NP_Class *aClass)
@@ -163,7 +173,15 @@ bool NP_IsKindOfClass (NP_Object *obj, NP_Class *aClass)
return false;
}
-void NP_SetException (NP_Object *obj, NP_String *message)
+void NP_SetExceptionWithUTF8 (NP_Object *obj, const NP_UTF8 *message)
+{
+ NP_String *m = NP_CreateStringWithUTF8(message);
+ NP_SetException (obj, m);
+ NP_ReleaseObject (m);
+}
+
+
+void NP_SetException (NP_Object *obj, NP_String *message)
{
}
@@ -245,7 +263,7 @@ double NP_DoubleFromNumber (NP_Number *obj)
typedef struct
{
NP_Object object;
- NP_UTF16 string;
+ NP_UTF16 *string;
int32_t length;
} StringObject;
@@ -277,14 +295,14 @@ NP_Class *NP_StringClass = stringClass;
#define LOCAL_CONVERSION_BUFFER_SIZE 4096
-NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String)
+NP_String *NP_CreateStringWithUTF8 (const NP_UTF8 *utf8String)
{
StringObject *string = (StringObject *)NP_CreateObject (stringClass);
CFStringRef stringRef = CFStringCreateWithCString (NULL, utf8String, kCFStringEncodingUTF8);
string->length = CFStringGetLength (stringRef);
- string->string = (NP_UTF16)malloc(sizeof(int16_t)*string->length);
+ string->string = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*string->length);
// Convert the string to UTF16.
CFRange range = { 0, string->length };
@@ -295,18 +313,18 @@ NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String)
}
-NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String, int32_t len)
+NP_String *NP_CreateStringWithUTF16 (const NP_UTF16 *utf16String, int32_t len)
{
StringObject *string = (StringObject *)NP_CreateObject (stringClass);
string->length = len;
- string->string = (NP_UTF16)malloc(sizeof(int16_t)*string->length);
- memcpy (string->string, utf16String, sizeof(int16_t)*string->length);
+ string->string = (NP_UTF16 *)malloc(sizeof(NP_UTF16)*string->length);
+ memcpy ((void *)string->string, utf16String, sizeof(NP_UTF16)*string->length);
return (NP_String *)string;
}
-NP_UTF8 NP_UTF8FromString (NP_String *obj)
+NP_UTF8 *NP_UTF8FromString (NP_String *obj)
{
assert (NP_IsKindOfClass (obj, stringClass));
@@ -332,9 +350,10 @@ NP_UTF8 NP_UTF8FromString (NP_String *obj)
CFRange range = { 0, string->length };
CFStringGetBytes (stringRef, range, kCFStringEncodingUTF8, 0, false, buffer, maxBufferLength, &usedBufferLength);
- NP_UTF8 resultString = (NP_UTF8)malloc (usedBufferLength+1);
- strncpy (resultString, (const char *)buffer, usedBufferLength);
- resultString[usedBufferLength] = 0;
+ NP_UTF8 *resultString = (NP_UTF8 *)malloc (usedBufferLength+1);
+ strncpy ((char *)resultString, (const char *)buffer, usedBufferLength);
+ char *cp = (char *)resultString;
+ cp[usedBufferLength] = 0;
CFRelease (stringRef);
if (buffer != _localBuffer)
@@ -343,14 +362,14 @@ NP_UTF8 NP_UTF8FromString (NP_String *obj)
return resultString;
}
-NP_UTF16 NP_UTF16FromString (NP_String *obj)
+NP_UTF16 *NP_UTF16FromString (NP_String *obj)
{
assert (NP_IsKindOfClass (obj, stringClass));
StringObject *string = (StringObject *)obj;
- NP_UTF16 resultString = (NP_UTF16)malloc(sizeof(int16_t)*string->length);
- memcpy (resultString, string->string, sizeof(int16_t)*string->length);
+ NP_UTF16 *resultString = (NP_UTF16*)malloc(sizeof(int16_t)*string->length);
+ memcpy ((void *)resultString, string->string, sizeof(int16_t)*string->length);
return resultString;
}
diff --git a/JavaScriptCore/bindings/npruntime.h b/JavaScriptCore/bindings/npruntime.h
index 2e8a499..eb223aa 100644
--- a/JavaScriptCore/bindings/npruntime.h
+++ b/JavaScriptCore/bindings/npruntime.h
@@ -29,6 +29,15 @@
* All calls into JavaScript were made asynchronous. Results are
* provided via the NP_JavaScriptResultInterface callback.
*
+ * Revision 3 (March 10, 2004):
+ * Corrected comments to not refer to class retain/release interfaces.
+ *
+ * Revision 4 (March 11, 2004):
+ * Added additional convenience NP_SetExceptionWithUTF8().
+ * Changed NP_HasPropertyInterface and NP_HasMethodInterface to take NP_Class
+ * pointers instead of objects.
+ * Added NP_IsValidIdentifier().
+ *
*/
#ifndef _NP_RUNTIME_H_
#define _NP_RUNTIME_H_
@@ -56,8 +65,10 @@ extern "C" {
/*
Data passed between 'C' and JavaScript is always wrapped in an NP_Object.
+ The interface on an NP_Object is described by an NP_Class.
*/
typedef struct NP_Object NP_Object;
+typedef struct NP_Class NP_Class;
/*
A NP_JavaScriptObject wraps a JavaScript Object in an NP_Object.
@@ -90,20 +101,24 @@ typedef NP_Object NP_JavaScriptObject;
*/
typedef uint32_t NP_Identifier;
-typedef char *NP_UTF8;
-typedef int16_t *NP_UTF16;
+typedef char NP_UTF8;
+typedef uint16_t NP_UTF16;
/*
NP_Objects have methods and properties. Methods and properties are named with NP_Identifiers.
These identifiers may be reflected in JavaScript. NP_Identifiers can be compared using ==.
+
+ NP_IsValidIdentifier will return true if an identifier for the name has already been
+ assigned with either NP_IdentifierFromUTF8() or NP_GetIdentifiers();
*/
-NP_Identifier NP_IdentifierFromUTF8 (NP_UTF8 name);
-void NP_GetIdentifiers (NP_UTF8 *names, int nameCount, NP_Identifier *identifiers);
+NP_Identifier NP_IdentifierFromUTF8 (const NP_UTF8 *name);
+bool NP_IsValidIdentifier (const NP_UTF8 *name);
+void NP_GetIdentifiers (const NP_UTF8 **names, int nameCount, NP_Identifier *identifiers);
/*
- The returned NP_UTF8 should be freed.
+ The returned NP_UTF8 should NOT be freed.
*/
-NP_UTF8 NP_UTF8FromIdentifier (NP_Identifier identifier);
+const NP_UTF8 *NP_UTF8FromIdentifier (NP_Identifier identifier);
/*
NP_Object behavior is implemented using the following set of callback interfaces.
@@ -111,10 +126,10 @@ NP_UTF8 NP_UTF8FromIdentifier (NP_Identifier identifier);
typedef NP_Object *(*NP_AllocateInterface)();
typedef void (*NP_DeallocateInterface)(NP_Object *obj);
typedef void (*NP_InvalidateInterface)();
-typedef bool (*NP_HasMethodInterface)(NP_Object *obj, NP_Identifier name);
+typedef bool (*NP_HasMethodInterface)(NP_Class *theClass, NP_Identifier name);
typedef NP_Object *(*NP_InvokeInterface)(NP_Object *obj, NP_Identifier name, NP_Object **args, unsigned argCount);
-typedef bool (*NP_HasPropertyInterface)(NP_Object *obj, NP_Identifier name);
-typedef NP_Object (*NP_GetPropertyInterface)(NP_Object *obj, NP_Identifier name);
+typedef bool (*NP_HasPropertyInterface)(NP_Class *theClass, NP_Identifier name);
+typedef NP_Object *(*NP_GetPropertyInterface)(NP_Object *obj, NP_Identifier name);
typedef void (*NP_SetPropertyInterface)(NP_Object *obj, NP_Identifier name, NP_Object *value);
/*
@@ -141,13 +156,13 @@ struct NP_Class
NP_HasMethodInterface hasMethod;
NP_InvokeInterface invoke;
NP_HasPropertyInterface hasProperty;
- NP_SetPropertyInterface setProperty;
NP_GetPropertyInterface getProperty;
+ NP_SetPropertyInterface setProperty;
};
typedef struct NP_Class NP_Class;
-#define kNP_ClassStructVersion1 1
-#define kNP_ClassStructVersionCurrent kNP_ClassStructVersionCurrent
+#define kNP_ClassStructVersion1 1
+#define kNP_ClassStructVersionCurrent kNP_ClassStructVersion1
struct NP_Object {
NP_Class *_class;
@@ -162,17 +177,14 @@ struct NP_Object {
NP_Object *NP_CreateObject (NP_Class *aClass);
/*
- If the class has a retain interface this function invokes that interface,
- otherwise the NP_Object's reference count is incremented.
+ Increment the NP_Object's reference count.
*/
NP_Object *NP_RetainObject (NP_Object *obj);
/*
- If the class has a release interface this function invokes that interface,
- otherwise the NP_Object's reference count is decremented and if the reference
- count goes to zero, the class's destroy interface is invoke. Note,
- that if a class implements it's own retain/release interfaces it must also
- call the destroy interface.
+ Decremented the NP_Object's reference count. If the reference
+ count goes to zero, the class's destroy interface is invoke if
+ specified, otherwise the object is free()ed directly.
*/
void NP_ReleaseObject (NP_Object *obj);
@@ -226,14 +238,14 @@ int NP_IntFromNumber (NP_Number *obj);
float NP_FloatFromNumber (NP_Number *obj);
double NP_DoubleFromNumber (NP_Number *obj);
-NP_String *NP_CreateStringWithUTF8 (NP_UTF8 utf8String);
-NP_String *NP_CreateStringWithUTF16 (NP_UTF16 utf16String, unsigned int len);
+NP_String *NP_CreateStringWithUTF8 (const NP_UTF8 *utf8String);
+NP_String *NP_CreateStringWithUTF16 (const NP_UTF16 *utf16String, unsigned int len);
/*
Memory returned from NP_UTF8FromString and NP_UTF16FromString must be freed by the caller.
*/
-NP_UTF8 NP_UTF8FromString (NP_String *obj);
-NP_UTF16 NP_UTF16FromString (NP_String *obj);
+NP_UTF8 *NP_UTF8FromString (NP_String *obj);
+NP_UTF16 *NP_UTF16FromString (NP_String *obj);
int32_t NP_StringLength (NP_String *obj);
NP_Boolean *NP_CreateBoolean (bool f);
@@ -278,9 +290,12 @@ bool NP_IsKindOfClass (NP_Object *obj, NP_Class *aClass);
from entry points into NP_Objects. A reference count of the message passes
to the callee. Typical usage:
- NP_SetException (obj, NP_CreateStringWithUTF8("invalid type"));
+ NP_String *message = NP_CreateStringWithUTF8("invalid type");
+ NP_SetException (obj, mesage);
+ NP_ReleaseObject (message);
*/
-void NP_SetException (NP_Object *obj, NP_String *message);
+void NP_SetExceptionWithUTF8 (NP_Object *obj, const NP_UTF8 *message);
+void NP_SetException (NP_Object *obj, NP_String *message);
/*
Example usage:
@@ -321,7 +336,7 @@ void NP_SetException (NP_Object *obj, NP_String *message);
static NP_Identifier getChapterIdentifier;
static NP_Identifier numChaptersIdentifier;
- static initializeIdentifiers()
+ static void initializeIdentifiers()
{
stopIdentifier = NP_IdentifierFromUTF8 ("stop");
startIdentifier = NP_IdentifierFromUTF8 ("start");
@@ -357,12 +372,11 @@ void NP_SetException (NP_Object *obj, NP_String *message);
return 0;
}
- void myInterfaceSetProperty (MyInterfaceObject *obj, NP_Identifier name, NP_Object *obj)
+ void myInterfaceSetProperty (MyInterfaceObject *obj, NP_Identifier name, NP_Object *value)
{
if (name == numChaptersIdentifier){
obj->numChapters = NP_IntFromNumber(obj)
}
- return 0;
}
NP_Object *myInterfaceInvoke (MyInterfaceObject *obj, NP_Identifier name, NP_Object **args, unsigned argCount)
@@ -394,6 +408,8 @@ void NP_SetException (NP_Object *obj, NP_String *message);
if (stopIdentifier == 0)
initializeIdentifiers();
+
+ return (NP_Object *)newInstance;
}
void myInterfaceInvalidate ()
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index fe900a7..73994ff 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -27,6 +27,7 @@
#include <runtime_object.h>
#include <jni_instance.h>
#include <objc_instance.h>
+#include <c_instance.h>
using namespace KJS;
using namespace KJS::Bindings;
@@ -96,10 +97,10 @@ Instance *Instance::createBindingForLanguageInstance (BindingLanguage language,
return new Bindings::JavaInstance ((jobject)instance);
else if (language == Instance::ObjectiveCLanguage)
return new Bindings::ObjcInstance ((struct objc_object *)instance);
-#if 0
+
else if (language == Instance::CLanguage)
- return new Bindings::CInstance ((struct objc_object *)instance);
-#endif
+ return new Bindings::CInstance ((NP_Object *)instance);
+
return 0;
}
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index f12db7d..7a83924 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -124,7 +124,8 @@ class Instance
public:
typedef enum {
JavaLanguage,
- ObjectiveCLanguage
+ ObjectiveCLanguage,
+ CLanguage
} BindingLanguage;
static Instance *createBindingForLanguageInstance (BindingLanguage language, void *instance);
diff --git a/JavaScriptCore/bindings/testbindings.cpp b/JavaScriptCore/bindings/testbindings.cpp
new file mode 100644
index 0000000..8eb6572
--- /dev/null
+++ b/JavaScriptCore/bindings/testbindings.cpp
@@ -0,0 +1,304 @@
+// -*- c-basic-offset: 2 -*-
+/*
+ * This file is part of the KDE libraries
+ * Copyright (C) 1999-2000 Harri Porten (porten at kde.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+
+#include "value.h"
+#include "object.h"
+#include "types.h"
+#include "interpreter.h"
+
+#include "NP_runtime.h"
+
+#include "runtime.h"
+#include "runtime_object.h"
+
+
+#define LOG(formatAndArgs...) { \
+ fprintf (stderr, "%s: ", __PRETTY_FUNCTION__); \
+ fprintf(stderr, formatAndArgs); \
+}
+
+
+// ------------------ NP Interface definition --------------------
+typedef struct
+{
+ NP_Object object;
+ double doubleValue;
+ int intValue;
+ const char *stringValue;
+ bool boolValue;
+} MyInterfaceObject;
+
+
+static bool identifiersInitialized = false;
+
+#define ID_DOUBLE_VALUE 0
+#define ID_INT_VALUE 1
+#define ID_STRING_VALUE 2
+#define ID_BOOLEAN_VALUE 3
+#define ID_NULL_VALUE 4
+#define ID_UNDEFINED_VALUE 5
+#define NUM_PROPERTY_IDENTIFIERS 6
+
+static NP_Identifier myPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
+static const NP_UTF8 *myPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
+ "doubleValue",
+ "intValue",
+ "stringValue",
+ "booleanValue",
+ "nullValue",
+ "undefinedValue"
+};
+
+#define NUM_METHOD_IDENTIFIERS 0
+
+static NP_Identifier myMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
+static const NP_UTF8 *myMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
+};
+
+static void initializeIdentifiers()
+{
+ NP_GetIdentifiers (myPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, myPropertyIdentifiers);
+ NP_GetIdentifiers (myMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, myMethodIdentifiers);
+};
+
+bool myInterfaceHasProperty (NP_Class *theClass, NP_Identifier name)
+{
+ int i;
+ for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) {
+ if (name == myPropertyIdentifiers[i]){
+ return true;
+ }
+ }
+ return false;
+}
+
+bool myInterfaceHasMethod (NP_Class *theClass, NP_Identifier name)
+{
+ int i;
+ for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++) {
+ if (name == myMethodIdentifiers[i]){
+ return true;
+ }
+ }
+ return false;
+}
+
+NP_Object *myInterfaceGetProperty (MyInterfaceObject *obj, NP_Identifier name)
+{
+ if (name == myPropertyIdentifiers[ID_DOUBLE_VALUE]){
+ return NP_CreateNumberWithDouble (obj->doubleValue);
+ }
+ else if (name == myPropertyIdentifiers[ID_INT_VALUE]){
+ return NP_CreateNumberWithInt (obj->intValue);
+ }
+ else if (name == myPropertyIdentifiers[ID_STRING_VALUE]){
+ return NP_CreateStringWithUTF8 (obj->stringValue);
+ }
+ else if (name == myPropertyIdentifiers[ID_BOOLEAN_VALUE]){
+ return NP_CreateBoolean (obj->boolValue);
+ }
+ else if (name == myPropertyIdentifiers[ID_NULL_VALUE]){
+ return NP_GetNull ();
+ }
+ else if (name == myPropertyIdentifiers[ID_UNDEFINED_VALUE]){
+ return NP_GetUndefined ();
+ }
+
+ return NP_GetUndefined();
+}
+
+void myInterfaceSetProperty (MyInterfaceObject *obj, NP_Identifier name, NP_Object *value)
+{
+ if (name == myPropertyIdentifiers[ID_DOUBLE_VALUE]) {
+ if (NP_IsKindOfClass (value, NP_NumberClass)) {
+ obj->doubleValue = NP_DoubleFromNumber (value);
+ }
+ else {
+ NP_SetExceptionWithUTF8 ((NP_Object *)obj, "Attempt to set a double value with a non-number type.");
+ }
+ }
+ else if (name == myPropertyIdentifiers[ID_INT_VALUE]) {
+ if (NP_IsKindOfClass (value, NP_NumberClass)) {
+ obj->intValue = NP_IntFromNumber (value);
+ }
+ else {
+ NP_SetExceptionWithUTF8 ((NP_Object *)obj, "Attempt to set a int value with a non-number type.");
+ }
+ }
+ else if (name == myPropertyIdentifiers[ID_STRING_VALUE]) {
+ if (NP_IsKindOfClass (value, NP_StringClass)) {
+ if (obj->stringValue)
+ free((void *)obj->stringValue);
+ obj->stringValue = NP_UTF8FromString (value);
+ }
+ else {
+ NP_SetExceptionWithUTF8 ((NP_Object *)obj, "Attempt to set a string value with a non-string type.");
+ }
+ }
+ else if (name == myPropertyIdentifiers[ID_BOOLEAN_VALUE]) {
+ if (NP_IsKindOfClass (value, NP_StringClass)) {
+ obj->boolValue = NP_BoolFromBoolean (value);
+ }
+ else {
+ NP_SetExceptionWithUTF8 ((NP_Object *)obj, "Attempt to set a bool value with a non-boolean type.");
+ }
+ }
+ else if (name == myPropertyIdentifiers[ID_NULL_VALUE]) {
+ // Do nothing!
+ }
+ else if (name == myPropertyIdentifiers[ID_UNDEFINED_VALUE]) {
+ // Do nothing!
+ }
+}
+
+NP_Object *myInterfaceInvoke (MyInterfaceObject *obj, NP_Identifier name, NP_Object **args, unsigned argCount)
+{
+ return NP_GetUndefined();
+}
+
+NP_Object *myInterfaceAllocate ()
+{
+ MyInterfaceObject *newInstance = (MyInterfaceObject *)malloc (sizeof(MyInterfaceObject));
+
+ if (!identifiersInitialized) {
+ identifiersInitialized = true;
+ initializeIdentifiers();
+ }
+
+ return (NP_Object *)newInstance;
+}
+
+void myInterfaceInvalidate ()
+{
+ // Make sure we've released any remainging references to JavaScript
+ // objects.
+}
+
+void myInterfaceDeallocate (MyInterfaceObject *obj)
+{
+ free ((void *)obj);
+}
+
+static NP_Class _myInterface = {
+ kNP_ClassStructVersionCurrent,
+ (NP_AllocateInterface) myInterfaceAllocate,
+ (NP_DeallocateInterface) myInterfaceDeallocate,
+ (NP_InvalidateInterface) myInterfaceInvalidate,
+ (NP_HasMethodInterface) myInterfaceHasMethod,
+ (NP_InvokeInterface) myInterfaceInvoke,
+ (NP_HasPropertyInterface) myInterfaceHasProperty,
+ (NP_GetPropertyInterface) myInterfaceGetProperty,
+ (NP_SetPropertyInterface) myInterfaceSetProperty,
+};
+static NP_Class *myInterface = &_myInterface;
+
+// --------------------------------------------------------
+
+using namespace KJS;
+using namespace KJS::Bindings;
+
+class GlobalImp : public ObjectImp {
+public:
+ virtual UString className() const { return "global"; }
+};
+
+#define BufferSize 200000
+static char code[BufferSize];
+
+const char *readJavaScriptFromFile (const char *file)
+{
+ FILE *f = fopen(file, "r");
+ if (!f) {
+ fprintf(stderr, "Error opening %s.\n", file);
+ return 0;
+ }
+
+ int num = fread(code, 1, BufferSize, f);
+ code[num] = '\0';
+ if(num >= BufferSize)
+ fprintf(stderr, "Warning: File may have been too long.\n");
+
+ fclose(f);
+
+ return code;
+}
+
+int main(int argc, char **argv)
+{
+ // expecting a filename
+ if (argc < 2) {
+ fprintf(stderr, "You have to specify at least one filename\n");
+ return -1;
+ }
+
+ bool ret = true;
+ {
+ Interpreter::lock();
+
+ // create interpreter w/ global object
+ Object global(new GlobalImp());
+ Interpreter interp(global);
+ ExecState *exec = interp.globalExec();
+
+ MyInterfaceObject *myInterfaceObject = (MyInterfaceObject *)NP_CreateObject (myInterface);
+
+ global.put(exec, Identifier("myInterface"), Instance::createRuntimeObject(Instance::CLanguage, (void *)myInterfaceObject));
+
+ for (int i = 1; i < argc; i++) {
+ const char *code = readJavaScriptFromFile(argv[i]);
+
+ if (code) {
+ // run
+ Completion comp(interp.evaluate(code));
+
+ if (comp.complType() == Throw) {
+ Value exVal = comp.value();
+ char *msg = exVal.toString(exec).ascii();
+ int lineno = -1;
+ if (exVal.type() == ObjectType) {
+ Value lineVal = Object::dynamicCast(exVal).get(exec,Identifier("line"));
+ if (lineVal.type() == NumberType)
+ lineno = int(lineVal.toNumber(exec));
+ }
+ if (lineno != -1)
+ fprintf(stderr,"Exception, line %d: %s\n",lineno,msg);
+ else
+ fprintf(stderr,"Exception: %s\n",msg);
+ ret = false;
+ }
+ else if (comp.complType() == ReturnValue) {
+ char *msg = comp.value().toString(interp.globalExec()).ascii();
+ fprintf(stderr,"Return value: %s\n",msg);
+ }
+ }
+ }
+
+ NP_ReleaseObject ((NP_Object *)myInterfaceObject);
+
+ Interpreter::unlock();
+
+ } // end block, so that Interpreter and global get deleted
+
+ return ret ? 0 : 3;
+}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list