From: Braden M. <br...@us...> - 2006-05-08 23:50:01
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5787/src/libopenvrml/openvrml Modified Files: script.cpp Log Message: Handle 0 or 1 argument calls to Browser.loadURL. Index: script.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/script.cpp,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** script.cpp 16 Apr 2006 08:22:18 -0000 1.69 --- script.cpp 8 May 2006 08:49:01 -0000 1.70 *************** *** 4280,4284 **** JSBool loadURL(JSContext * const cx, JSObject *, ! uintN, jsval * const argv, jsval *) --- 4280,4284 ---- JSBool loadURL(JSContext * const cx, JSObject *, ! const uintN argc, jsval * const argv, jsval *) *************** *** 4291,4322 **** *static_cast<js_::script *>(JS_GetContextPrivate(cx)); ! // ! // Make sure our first argument (the URL) is an MFString. ! // ! JSObject * arg0_obj; ! if (!JS_ValueToObject(cx, argv[0], &arg0_obj)) { return JS_FALSE; } ! if (!JS_InstanceOf(cx, arg0_obj, &MFString::jsclass, argv)) { ! return JS_FALSE; ! } ! auto_ptr<openvrml::mfstring> url = ! MFString::createFromJSObject(cx, arg0_obj); ! assert(url.get()); ! // ! // Make sure our second argument is an MFString ! // ! JSObject * arg1_obj; ! if (!JS_ValueToObject(cx, argv[1], &arg1_obj)) { return JS_FALSE; } ! if (!JS_InstanceOf(cx, arg1_obj, &MFString::jsclass, argv)) { return JS_FALSE; } - auto_ptr<openvrml::mfstring> parameters = - MFString::createFromJSObject(cx, arg1_obj); - assert(parameters.get()); - - script.script_node().scene()->browser().load_url(url->value(), - parameters->value()); return JS_TRUE; } --- 4291,4340 ---- *static_cast<js_::script *>(JS_GetContextPrivate(cx)); ! try { ! openvrml::mfstring url, parameter; ! if (argc > 0) { ! // ! // Make sure our first argument (the URL) is an MFString. ! // ! JSObject * arg0_obj; ! if (!JS_ValueToObject(cx, argv[0], &arg0_obj)) { return JS_FALSE; } ! if (!JS_InstanceOf(cx, arg0_obj, &MFString::jsclass, argv)) { ! return JS_FALSE; ! } ! auto_ptr<openvrml::mfstring> url_ptr = ! MFString::createFromJSObject(cx, arg0_obj); ! assert(url_ptr.get()); ! url = *url_ptr; ! } ! ! if (argc > 1) { ! // ! // Make sure our second argument is an MFString ! // ! JSObject * arg1_obj; ! if (!JS_ValueToObject(cx, argv[1], &arg1_obj)) { return JS_FALSE; } ! if (!JS_InstanceOf(cx, arg1_obj, &MFString::jsclass, argv)) { ! return JS_FALSE; ! } ! ! auto_ptr<openvrml::mfstring> parameter_ptr = ! MFString::createFromJSObject(cx, arg1_obj); ! assert(parameter_ptr.get()); ! parameter = *parameter_ptr; ! } ! ! script.script_node().scene()->browser().load_url(url.value(), ! parameter.value()); ! } catch (std::bad_alloc &) { ! JS_ReportOutOfMemory(cx); return JS_FALSE; + } catch (std::exception & ex) { + JS_ReportError(cx, ex.what()); + } catch (...) { + JS_ReportError(cx, "unexpected exception"); } return JS_TRUE; } |