JSBool JavaObject::setProperty(JSContext* ctx, JSObject* obj, jsid id, JSBool strict, jsval* vp) { #endif //GECKO_VERSION Debug::log(Debug::Spam) << "JavaObject::setProperty obj=" << obj << Debug::flush; if (!JSID_IS_INT(id)) { Debug::log(Debug::Error) << " Error: setting string property id" << Debug::flush; // TODO: throw a better exception here return JS_FALSE; } SessionData* data = JavaObject::getSessionData(ctx, obj); if (!data) { return JS_TRUE; } int objectRef = JavaObject::getObjectId(ctx, obj); int dispId = JSID_TO_INT(id); Value value; data->makeValueFromJsval(value, ctx, *vp); HostChannel* channel = data->getHostChannel(); SessionHandler* handler = data->getSessionHandler(); if (!ServerMethods::setProperty(*channel, handler, objectRef, dispId, value)) { // TODO: throw a better exception here return JS_FALSE; } return JS_TRUE; }
JSBool JavaObject::getProperty(JSContext* ctx, JSObject* obj, jsid id, jsval* rval) { Debug::log(Debug::Spam) << "JavaObject::getProperty obj=" << obj << Debug::flush; SessionData* data = JavaObject::getSessionData(ctx, obj); if (!data) { // TODO: replace the frame with an error page instead? *rval = JSVAL_VOID; return JS_TRUE; } int objectRef = JavaObject::getObjectId(ctx, obj); if (JSID_IS_STRING(id)) { JSString* str = JSID_TO_STRING(id); if ((JS_GetStringEncodingLength(ctx, str) == 8) && !strncmp("toString", JS_EncodeString(ctx, str), 8)) { *rval = data->getToStringTearOff(); return JS_TRUE; } if ((JS_GetStringEncodingLength(ctx, str) == 2) && !strncmp("id", JS_EncodeString(ctx, str), 2)) { *rval = INT_TO_JSVAL(objectRef); return JS_TRUE; } if ((JS_GetStringEncodingLength(ctx, str) == 16) && !strncmp("__noSuchMethod__", JS_EncodeString(ctx, str), 16)) { // Avoid error spew if we are disconnected *rval = JSVAL_VOID; return JS_TRUE; } // TODO: dumpJsVal can no longer handle this case //Debug::log(Debug::Error) << "Getting unexpected string property " // << dumpJsVal(ctx, id) << Debug::flush; // TODO: throw a better exception here return JS_FALSE; } if (!JSID_IS_INT(id)) { // TODO: dumpJsVal can no longer handle this case //Debug::log(Debug::Error) << "Getting non-int/non-string property " // << dumpJsVal(ctx, id) << Debug::flush; // TODO: throw a better exception here return JS_FALSE; } int dispId = JSID_TO_INT(id); HostChannel* channel = data->getHostChannel(); SessionHandler* handler = data->getSessionHandler(); gwt::Value value = ServerMethods::getProperty(*channel, handler, objectRef, dispId); data->makeJsvalFromValue(*rval, ctx, value); return JS_TRUE; }