Author: [EMAIL PROTECTED]
Date: Fri Sep 26 09:21:37 2008
New Revision: 3685
Added:
changes/jat/oophm-branch/plugins/xpcom/XpcomDebug.cpp
changes/jat/oophm-branch/plugins/xpcom/XpcomDebug.h
Modified:
changes/jat/oophm-branch/plugins/common/ByteOrder.h
changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.cpp
changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.h
changes/jat/oophm-branch/plugins/xpcom/JavaObject.cpp
changes/jat/oophm-branch/plugins/xpcom/Makefile
Log:
Portability and debug fixes.
Modified: changes/jat/oophm-branch/plugins/common/ByteOrder.h
==============================================================================
--- changes/jat/oophm-branch/plugins/common/ByteOrder.h (original)
+++ changes/jat/oophm-branch/plugins/common/ByteOrder.h Fri Sep 26 09:21:37
2008
@@ -57,8 +57,8 @@
#ifndef PLATFORM_FLOAT_ENDIANESS
DoubleUnion u;
memset(u.b, 0, sizeof(u.b));
- u.b[0] = 0x80;
- u.b[7] = 0x02;
+ u.b[0] = (char) 0x80;
+ u.b[7] = (char) 0x02;
// TODO(jat): add more tests here if we support other endianess
floatByteOrder = u.v > 0 ? FLOAT_LITTLE_ENDIAN : FLOAT_BIG_ENDIAN;
if (Debug::level(Debug::Debugging)) {
Modified: changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.cpp
==============================================================================
--- changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.cpp (original)
+++ changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.cpp Fri Sep 26
09:21:37 2008
@@ -19,6 +19,7 @@
#include "JavaObject.h"
#include "JSRunner.h"
#include "Debug.h"
+#include "XpcomDebug.h"
#include "scoped_ptr/scoped_ptr.h"
#include "RootedObject.h"
#include "InvokeMessage.h"
@@ -89,7 +90,7 @@
if (JS_GetPendingException(ctx, &exc)) {
Debug::log(Debug::Error)
<< "__gwt_makeTearOff(null,0,0) threw exception "
- << JS_ValueToString(ctx, exc) << Debug::flush;
+ << dumpJsVal(ctx, exc) << Debug::flush;
} else {
Debug::log(Debug::Error) << "Error creating toString tear-off"
<< Debug::flush;
@@ -157,8 +158,10 @@
Debug::log(Debug::Spam) << " using global object for this" <<
Debug::flush;
} else {
makeValueRef(jsThis, ctx, thisObj);
- Debug::log(Debug::Spam) << " obj=" << JS_ValueToString(ctx, jsThis)
- << Debug::flush;
+ if (Debug::level(Debug::Spam)) {
+ Debug::log(Debug::Spam) << " obj=" << dumpJsVal(ctx, jsThis)
+ << Debug::flush;
+ }
}
if (!JS_SetElement(ctx, argsRoot.get(), 0, &jsThis)) {
Debug::log(Debug::Error)
@@ -176,8 +179,10 @@
scoped_array<jsval> jsargs(new jsval[numArgs]);
for (int i = 0; i < numArgs; ++i) {
makeValueRef(jsargs[i], ctx, args[i]);
- Debug::log(Debug::Spam) << " arg[" << i << "] = " <<
JS_ValueToString(ctx,
- jsargs[i]) << Debug::flush;
+ if (Debug::level(Debug::Spam)) {
+ Debug::log(Debug::Spam) << " arg[" << i << "] = " << dumpJsVal(ctx,
+ jsargs[i]) << Debug::flush;
+ }
if (!JS_SetElement(ctx, argsRoot.get(), i + 1, &jsargs[i])) {
Debug::log(Debug::Error)
<< "FFSessionhandler::invoke - could not set args[" << (i + 1)
<< "]"
@@ -203,7 +208,7 @@
makeValue(*returnValue, ctx, rval);
Debug::log(Debug::Debugging) << "FFSessionHandler::invoke "
<< thisObj.toString() << "::" << methodName << " threw
exception "
- << JS_ValueToString(ctx, rval) << Debug::flush;
+ << dumpJsVal(ctx, rval) << Debug::flush;
} else {
Debug::log(Debug::Error) << "Non-exception failure invoking "
<< methodName << Debug::flush;
@@ -239,6 +244,7 @@
retVal.setBoolean(JSVAL_TO_BOOLEAN(value));
} else if (JSVAL_IS_STRING(value)) {
JSString* str = JSVAL_TO_STRING(value);
+ // TODO(jat): is this Unicode safe?
retVal.setString(JS_GetStringBytes(str), JS_GetStringLength(str));
} else if (JSVAL_IS_DOUBLE(value)) {
retVal.setDouble(*JSVAL_TO_DOUBLE(value));
@@ -249,6 +255,7 @@
} else if (JS_GET_CLASS(ctx, obj) == stringObjectClass) {
// JS String wrapper object, treat as a string primitive
JSString* str = JS_ValueToString(ctx, value);
+ // TODO(jat): is this Unicode safe?
retVal.setString(JS_GetStringBytes(str), JS_GetStringLength(str));
} else {
// It's a plain-old JavaScript Object
@@ -306,7 +313,8 @@
break;
case Value::STRING:
{
- JSString* str = JS_NewStringCopyN(ctx, value.getString().c_str(),
value.getString().length());
+ std::string strVal = value.getString();
+ JSString* str = JS_NewStringCopyN(ctx, strVal.c_str(),
strVal.length());
retVal = STRING_TO_JSVAL(str);
}
break;
Modified: changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.h
==============================================================================
--- changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.h (original)
+++ changes/jat/oophm-branch/plugins/xpcom/FFSessionHandler.h Fri Sep 26
09:21:37 2008
@@ -58,10 +58,10 @@
std::map<int, JSObject*> javaObjectsById;
std::set<int> javaObjectsToFree;
- JSClass* stringObjectClass;
-
// Array of JSObjects exposed to the host
JSObject* jsObjectsById;
+ JSClass* stringObjectClass;
+
std::map<JSObject*, int> jsIdsByObject;
//
// /*
Modified: changes/jat/oophm-branch/plugins/xpcom/JavaObject.cpp
==============================================================================
--- changes/jat/oophm-branch/plugins/xpcom/JavaObject.cpp (original)
+++ changes/jat/oophm-branch/plugins/xpcom/JavaObject.cpp Fri Sep 26
09:21:37 2008
@@ -19,6 +19,7 @@
#include "SessionData.h"
#include "ServerMethods.h"
#include "Debug.h"
+#include "XpcomDebug.h"
#include "HostChannel.h"
#include "InvokeMessage.h"
#include "ReturnMessage.h"
@@ -50,6 +51,22 @@
int JavaObject::getObjectId(JSContext* ctx, JSObject* obj) {
jsval val;
+ JSClass* jsClass = JS_GET_CLASS(ctx, obj);
+#if 1
+ if (jsClass != &JavaObjectClass) {
+ Debug::log(Debug::Error)
+ << "JavaObject::getObjectId called on non-JavaObject: " <<
jsClass->name
+ << Debug::flush;
+ return -1;
+ }
+ if (JSCLASS_RESERVED_SLOTS(jsClass) < 1) {
+ Debug::log(Debug::Error)
+ << "JavaObject::getObjectId -- " << static_cast<void*>(obj)
+ << " has only " << (JSCLASS_RESERVED_SLOTS(jsClass))
+ << " reserved slots, no objectId present" << Debug::flush;
+ return -1;
+ }
+#endif
if (!JS_GetReservedSlot(ctx, obj, 0, &val)) {
Debug::log(Debug::Error) << "Error getting reserved slot" <<
Debug::flush;
return -1;
@@ -59,7 +76,7 @@
}
SessionData* JavaObject::getSessionData(JSContext* ctx, JSObject* obj) {
- void* data = JS_GetPrivate(ctx, obj);
+ void* data = JS_GetInstancePrivate(ctx, obj, &JavaObjectClass, NULL);
return static_cast<SessionData*>(data);
}
@@ -115,12 +132,12 @@
}
#endif
Debug::log(Debug::Error) << "Getting unexpected string property "
- << JS_ValueToString(ctx, id) << Debug::flush;
+ << dumpJsVal(ctx, id) << Debug::flush;
return JS_FALSE;
}
if (!JSVAL_IS_INT(id)) {
Debug::log(Debug::Error) << "Getting non-int/non-string property "
- << JS_ValueToString(ctx, id) << Debug::flush;
+ << dumpJsVal(ctx, id) << Debug::flush;
return JS_FALSE;
}
int dispId = JSVAL_TO_INT(id);
@@ -272,7 +289,7 @@
if (i > 2) {
dbg << ", ";
}
- dbg << JS_ValueToString(ctx, argv[i]);
+ dbg << dumpJsVal(ctx, argv[i]);
}
dbg << ")" << Debug::flush;
@@ -318,7 +335,7 @@
scoped_array<Value> args(new Value[numArgs]);
for (int i = 0; i < numArgs; ++i) {
// Debug::log(Debug::Spam) << "making argv[" << i << + "]" <<
Debug::flush;
- // Debug::log(Debug::Spam) << " " << JS_ValueToString(ctx,
jsargs[i]) << Debug::flush;
+ // Debug::log(Debug::Spam) << " " << dumpJsVal(ctx, jsargs[i]) <<
Debug::flush;
data->makeValue(args[i], ctx, jsargs[i]);
}
if (!InvokeMessage::send(*channel, javaThis, dispId, numArgs,
args.get())) {
Modified: changes/jat/oophm-branch/plugins/xpcom/Makefile
==============================================================================
--- changes/jat/oophm-branch/plugins/xpcom/Makefile (original)
+++ changes/jat/oophm-branch/plugins/xpcom/Makefile Fri Sep 26 09:21:37 2008
@@ -1,8 +1,8 @@
XUL_SDK_PATH=../../../xulrunner-sdk
#GECKO_SDK_PATH=../../../gecko-sdk-1.8
GECKO_SDK_PATH=$(XUL_SDK_PATH)/sdk
-#GECKO_BINSDK_PATH=$(GECKO_SDK_PATH)
-GECKO_BINSDK_PATH=/usr/lib/xulrunner-devel-1.9.0.1/
+GECKO_BINSDK_PATH=$(GECKO_SDK_PATH)
+#GECKO_BINSDK_PATH=/usr/lib/xulrunner-devel-1.9.0.1/
INC=-I. -I../common -I$(GECKO_SDK_PATH)/include
-I$(XUL_SDK_PATH)/include/caps -I$(XUL_SDK_PATH)/include/dom
-I$(XUL_SDK_PATH)/include/js -I$(XUL_SDK_PATH)/include/necko
-I$(XUL_SDK_PATH)/include/string -I$(XUL_SDK_PATH)/include/widget
-I$(XUL_SDK_PATH)/include/xpcom -I$(XUL_SDK_PATH)/include/xpconnect
-I$(XUL_SDK_PATH)/include
RUN_PATH_FLAG=-rpath-link
LD_FLAGS=-L$(GECKO_BINSDK_PATH)/lib -L$(GECKO_BINSDK_PATH)/bin
-Wl,$(RUN_PATH_FLAG),$(GECKO_BINSDK_PATH)/bin -lxpcomglue_s -lxpcom -lnspr4
-lmozjs
@@ -19,9 +19,9 @@
ALL: oophm-xpcom.xpi
-OBJS= ExternalWrapper.o ModuleOOPHM.o FFSessionHandler.o JavaObject.o
JSRunner.o
+OBJS= ExternalWrapper.o ModuleOOPHM.o FFSessionHandler.o JavaObject.o
JSRunner.o XpcomDebug.o
-SRCS= ExternalWrapper.cpp ModuleOOPHM.cpp FFSessionHandler.cpp
JavaObject.cpp JSRunner.cpp
+SRCS= ExternalWrapper.cpp ModuleOOPHM.cpp FFSessionHandler.cpp
JavaObject.cpp JSRunner.cpp XpcomDebug.cpp
oophm-xpcom.xpi: arch extension $(INSTDIR)/liboophm.so \
extension/components/IOOPHM.xpt extension/install.rdf
Added: changes/jat/oophm-branch/plugins/xpcom/XpcomDebug.cpp
==============================================================================
--- (empty file)
+++ changes/jat/oophm-branch/plugins/xpcom/XpcomDebug.cpp Fri Sep 26
09:21:37 2008
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+
+#include <cstring>
+
+#include "XpcomDebug.h"
+#include "JavaObject.h"
+
+std::string dumpJsVal(JSContext* ctx, jsval v) {
+ char buf[30];
+ if (v == JSVAL_VOID) {
+ strcpy(buf, "undef");
+ } else if (v == JSVAL_NULL) {
+ strcpy(buf, "null");
+ } else {
+ switch (JSVAL_TAG(v)) {
+ case JSVAL_OBJECT:
+ {
+ JSObject* obj = JSVAL_TO_OBJECT(v);
+ if (JavaObject::isJavaObject(ctx, obj)) {
+ int oid = JavaObject::getObjectId(ctx, obj);
+ snprintf(buf, sizeof(buf), "JavaObj(%d)", oid);
+ } else {
+ JSClass* jsClass = JS_GET_CLASS(ctx, obj);
+ const char* name = jsClass->name ? jsClass->name : "<null>";
+ snprintf(buf, sizeof(buf), "Object(%.20s @ %p)", name, obj);
+ }
+ break;
+ }
+ case JSVAL_INT:
+ snprintf(buf, sizeof(buf), "int(%d)", JSVAL_TO_INT(v));
+ break;
+ case JSVAL_DOUBLE:
+ snprintf(buf, sizeof(buf), "double(%lf)", *JSVAL_TO_DOUBLE(v));
+ break;
+ case JSVAL_STRING:
+ {
+ JSString* str = JSVAL_TO_STRING(v);
+ int len = JS_GetStringLength(str);
+ if (len > 20) {
+ len = 20;
+ }
+ snprintf(buf, sizeof(buf), "string(%.*s)", len,
JS_GetStringBytes(str));
+ break;
+ }
+ case JSVAL_BOOLEAN:
+ snprintf(buf, sizeof(buf), "bool(%s)", JSVAL_TO_BOOLEAN(v) ? "true"
+ : " false");
+ break;
+ }
+ }
+ buf[sizeof(buf) - 1] = 0;
+ return std::string(buf);
+}
Added: changes/jat/oophm-branch/plugins/xpcom/XpcomDebug.h
==============================================================================
--- (empty file)
+++ changes/jat/oophm-branch/plugins/xpcom/XpcomDebug.h Fri Sep 26 09:21:37
2008
@@ -0,0 +1,26 @@
+#ifndef _H_XpcomDebug
+#define _H_XpcomDebug
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+
+#include <string>
+
+#include "mozincludes.h"
+#include "jsapi.h"
+
+std::string dumpJsVal(JSContext* ctx, jsval v);
+
+#endif
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---