diff options
author | dominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56> | 2011-03-22 19:53:30 +0000 |
---|---|---|
committer | dominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56> | 2011-03-22 19:53:30 +0000 |
commit | f04cfe4f41f087f6c0c476c97317437d544ff86b (patch) | |
tree | 4588f88eb4b5465dec155308005aad337b667a8f | |
parent | c1decf1bd7bbf49ad674873359b8e2a37831fe45 (diff) | |
download | libproxy-f04cfe4f41f087f6c0c476c97317437d544ff86b.tar.gz |
Revert r786 - This introduces more errors than needed - And even fails building on xul 1.9
git-svn-id: http://libproxy.googlecode.com/svn/trunk@789 c587cffe-e639-0410-9787-d7902ae8ed56
-rw-r--r-- | libproxy/modules/pacrunner_mozjs.cpp | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp index eae2a99..5fd12ed 100644 --- a/libproxy/modules/pacrunner_mozjs.cpp +++ b/libproxy/modules/pacrunner_mozjs.cpp @@ -42,12 +42,12 @@ using namespace libproxy; #define INET6_ADDRSTRLEN 46 #endif -static JSBool dnsResolve_(JSContext *cx, jsval hostname, jsval *vp) { +static JSBool dnsResolve(JSContext *cx, JSObject * /*obj*/, uintN /*argc*/, jsval *argv, jsval *rval) { // Get hostname argument - char *tmp = JS_EncodeString(cx, JS_ValueToString(cx, hostname)); + char *tmp = JS_strdup(cx, JS_GetStringBytes(JS_ValueToString(cx, argv[0]))); // Set the default return value - JS_SET_RVAL(cx, vp, JSVAL_NULL); + *rval = JSVAL_NULL; // Look it up struct addrinfo *info = NULL; @@ -66,7 +66,7 @@ static JSBool dnsResolve_(JSContext *cx, jsval hostname, jsval *vp) { NI_NUMERICHOST)) goto out; // We succeeded - JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyN(cx, tmp, strlen(tmp)))); + *rval = STRING_TO_JSVAL(JS_NewString(cx, tmp, strlen(tmp))); tmp = NULL; out: @@ -75,20 +75,15 @@ static JSBool dnsResolve_(JSContext *cx, jsval hostname, jsval *vp) { return true; } -static JSBool dnsResolve(JSContext *cx, uintN /*argc*/, jsval *vp) { - jsval *argv = JS_ARGV(cx, vp); - return dnsResolve_(cx, argv[0], vp); -} - -static JSBool myIpAddress(JSContext *cx, uintN /*argc*/, jsval *vp) { +static JSBool myIpAddress(JSContext *cx, JSObject *obj, uintN /*argc*/, jsval * /*argv*/, jsval *rval) { char *hostname = (char *) JS_malloc(cx, 1024); if (!gethostname(hostname, 1023)) { - JSString *myhost = JS_NewStringCopyN(cx, hostname, strlen(hostname)); + JSString *myhost = JS_NewString(cx, hostname, strlen(hostname)); jsval arg = STRING_TO_JSVAL(myhost); - return dnsResolve_(cx, 1, &arg); + return dnsResolve(cx, obj, 1, &arg, rval); } JS_free(cx, hostname); - JS_SET_RVAL(cx, vp, JSVAL_NULL); + *rval = JSVAL_NULL; return true; } @@ -116,11 +111,7 @@ public: //JS_SetOptions(this->jsctx, JSOPTION_VAROBJFIX); //JS_SetVersion(this->jsctx, JSVERSION_LATEST); //JS_SetErrorReporter(cx, reportError); - #ifdef HAVE_MOZJS_2 - if (!(this->jsglb = JS_NewCompartmentAndGlobalObject(this->jsctx, &cls, NULL))) goto error; - #else if (!(this->jsglb = JS_NewObject(this->jsctx, &cls, NULL, NULL))) goto error; - #endif if (!JS_InitStandardClasses(this->jsctx, this->jsglb)) goto error; // Define Javascript functions @@ -156,19 +147,15 @@ public: throw bad_alloc(); } jsval args[2] = { - STRING_TO_JSVAL(JS_NewStringCopyN(this->jsctx, tmpurl, strlen(tmpurl))), - STRING_TO_JSVAL(JS_NewStringCopyN(this->jsctx, tmphost, strlen(tmphost))) + STRING_TO_JSVAL(JS_NewString(this->jsctx, tmpurl, strlen(tmpurl))), + STRING_TO_JSVAL(JS_NewString(this->jsctx, tmphost, strlen(tmphost))) }; // Find the proxy (call FindProxyForURL()) jsval rval; JSBool result = JS_CallFunctionName(this->jsctx, this->jsglb, "FindProxyForURL", 2, args, &rval); if (!result) return ""; - - char * tmpanswer = JS_EncodeString(this->jsctx, JS_ValueToString(this->jsctx, rval)); - string answer = string(tmpanswer); - JS_free(this->jsctx, tmpanswer); - + string answer = string(JS_GetStringBytes(JS_ValueToString(this->jsctx, rval))); if (answer == "undefined") return ""; return answer; } |