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; }
/** * Called when the JavaObject is invoked as a function. * We ignore the JSObject* argument, which is the 'this' context, which is * usually the window object. The JavaObject instance is in argv[-2]. * * Returns a JS array, with the first element being a boolean indicating that * an exception occured, and the second element is either the return value or * the exception which was thrown. In this case, we always return false and * raise the exception ourselves. */ JSBool JavaObject::call(JSContext* ctx, JSObject*, uintN argc, jsval* argv, jsval* rval) { // Get the JavaObject called as a function JSObject* obj = JSVAL_TO_OBJECT(argv[-2]); if (argc < 2 || !JSVAL_IS_INT(argv[0]) || #ifdef JSVAL_IS_OBJECT !JSVAL_IS_OBJECT(argv[1])) { #else (JSVAL_IS_PRIMITIVE(argv[1]) && !JSVAL_IS_NULL(argv[1]))) { #endif Debug::log(Debug::Error) << "JavaObject::call incorrect arguments" << Debug::flush; return JS_FALSE; } int dispId = JSVAL_TO_INT(argv[0]); if (Debug::level(Debug::Spam)) { Debug::DebugStream& dbg = Debug::log(Debug::Spam) << "JavaObject::call oid=" << JavaObject::getObjectId(ctx, obj) << ",dispId=" << dispId << " ("; for (unsigned i = 2; i < argc; ++i) { if (i > 2) { dbg << ", "; } dbg << dumpJsVal(ctx, argv[i]); } dbg << ")" << Debug::flush; } SessionData* data = JavaObject::getSessionData(ctx, obj); if (!data) { *rval = JSVAL_VOID; return JS_TRUE; } Debug::log(Debug::Spam) << "Data = " << data << Debug::flush; gwt::Value javaThis; if (!JSVAL_IS_NULL(argv[1])) { JSObject* thisObj = JSVAL_TO_OBJECT(argv[1]); if (isJavaObject(ctx, thisObj)) { javaThis.setJavaObject(getObjectId(ctx, thisObj)); } else { data->makeValueFromJsval(javaThis, ctx, argv[1]); } } else { int oid = getObjectId(ctx, obj); javaThis.setJavaObject(oid); } return invokeJava(ctx, data, javaThis, dispId, argc - 2, &argv[2], rval); }