|
|
b51580 |
From f594720280b2e40d81fa6e286a0ef8868687ef7e Mon Sep 17 00:00:00 2001
|
|
|
b51580 |
From: Pierre Lejeune <superheron@gmail.com>
|
|
|
b51580 |
Date: Sat, 30 Jun 2018 21:10:06 +0200
|
|
|
b51580 |
Subject: [PATCH] Build with mozjs-52
|
|
|
b51580 |
|
|
|
b51580 |
Fixes #71
|
|
|
b51580 |
---
|
|
|
b51580 |
libproxy/cmake/modules/pacrunner_mozjs.cmk | 2 +-
|
|
|
b51580 |
libproxy/modules/pacrunner_mozjs.cpp | 19 +++++++------------
|
|
|
b51580 |
2 files changed, 8 insertions(+), 13 deletions(-)
|
|
|
b51580 |
|
|
|
b51580 |
diff --git a/libproxy/cmake/modules/pacrunner_mozjs.cmk b/libproxy/cmake/modules/pacrunner_mozjs.cmk
|
|
|
b51580 |
index c2ae3db..20857fb 100644
|
|
|
b51580 |
--- a/libproxy/cmake/modules/pacrunner_mozjs.cmk
|
|
|
b51580 |
+++ b/libproxy/cmake/modules/pacrunner_mozjs.cmk
|
|
|
b51580 |
@@ -9,7 +9,7 @@ if(WIN32)
|
|
|
b51580 |
elseif(NOT APPLE)
|
|
|
b51580 |
option(WITH_MOZJS "Search for MOZJS package" ON)
|
|
|
b51580 |
if (WITH_MOZJS)
|
|
|
b51580 |
- pkg_search_module(MOZJS mozjs-38)
|
|
|
b51580 |
+ pkg_search_module(MOZJS mozjs-52)
|
|
|
b51580 |
if(MOZJS_FOUND)
|
|
|
b51580 |
include_directories(${MOZJS_INCLUDE_DIRS})
|
|
|
b51580 |
link_directories(${MOZJS_LIBRARY_DIRS})
|
|
|
b51580 |
diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
|
|
|
b51580 |
index a70b2e9..ed07c69 100644
|
|
|
b51580 |
--- a/libproxy/modules/pacrunner_mozjs.cpp
|
|
|
b51580 |
+++ b/libproxy/modules/pacrunner_mozjs.cpp
|
|
|
b51580 |
@@ -35,6 +35,7 @@ using namespace libproxy;
|
|
|
b51580 |
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
|
|
b51580 |
#include <jsapi.h>
|
|
|
b51580 |
#pragma GCC diagnostic error "-Winvalid-offsetof"
|
|
|
b51580 |
+#include <js/Initialization.h>
|
|
|
b51580 |
#include <js/CallArgs.h>
|
|
|
b51580 |
|
|
|
b51580 |
#include "pacutils.h"
|
|
|
b51580 |
@@ -111,17 +112,14 @@ class mozjs_pacrunner : public pacrunner {
|
|
|
b51580 |
mozjs_pacrunner(string pac, const url& pacurl) throw (bad_alloc) : pacrunner(pac, pacurl) {
|
|
|
b51580 |
|
|
|
b51580 |
// Set defaults
|
|
|
b51580 |
- this->jsrun = nullptr;
|
|
|
b51580 |
this->jsctx = nullptr;
|
|
|
b51580 |
JS_Init();
|
|
|
b51580 |
|
|
|
b51580 |
- // Initialize Javascript runtime environment
|
|
|
b51580 |
- if (!(this->jsrun = JS_NewRuntime(1024 * 1024))) goto error;
|
|
|
b51580 |
- if (!(this->jsctx = JS_NewContext(this->jsrun, 1024 * 1024))) goto error;
|
|
|
b51580 |
+ // Initialize Javascript context
|
|
|
b51580 |
+ if (!(this->jsctx = JS_NewContext(1024 * 1024))) goto error;
|
|
|
b51580 |
{
|
|
|
b51580 |
JS::RootedValue rval(this->jsctx);
|
|
|
b51580 |
JS::CompartmentOptions compart_opts;
|
|
|
b51580 |
- compart_opts.setVersion(JSVERSION_LATEST);
|
|
|
b51580 |
|
|
|
b51580 |
this->jsglb = new JS::Heap<JSObject*>(JS_NewGlobalObject(
|
|
|
b51580 |
this->jsctx, &cls,
|
|
|
b51580 |
@@ -139,16 +137,15 @@ class mozjs_pacrunner : public pacrunner {
|
|
|
b51580 |
JS::CompileOptions options(this->jsctx);
|
|
|
b51580 |
options.setUTF8(true);
|
|
|
b51580 |
|
|
|
b51580 |
- JS::Evaluate(this->jsctx, global, options, JAVASCRIPT_ROUTINES,
|
|
|
b51580 |
- strlen(JAVASCRIPT_ROUTINES), &rval);
|
|
|
b51580 |
+ JS::Evaluate(this->jsctx, options, JAVASCRIPT_ROUTINES,
|
|
|
b51580 |
+ strlen(JAVASCRIPT_ROUTINES), JS::MutableHandleValue(&rval));
|
|
|
b51580 |
|
|
|
b51580 |
// Add PAC to the environment
|
|
|
b51580 |
- JS::Evaluate(this->jsctx, global, options, pac.c_str(), pac.length(), &rval);
|
|
|
b51580 |
+ JS::Evaluate(this->jsctx, options, pac.c_str(), pac.length(), JS::MutableHandleValue(&rval));
|
|
|
b51580 |
return;
|
|
|
b51580 |
}
|
|
|
b51580 |
error:
|
|
|
b51580 |
if (this->jsctx) JS_DestroyContext(this->jsctx);
|
|
|
b51580 |
- if (this->jsrun) JS_DestroyRuntime(this->jsrun);
|
|
|
b51580 |
throw bad_alloc();
|
|
|
b51580 |
}
|
|
|
b51580 |
|
|
|
b51580 |
@@ -156,7 +153,6 @@ class mozjs_pacrunner : public pacrunner {
|
|
|
b51580 |
if (this->jsac) delete this->jsac;
|
|
|
b51580 |
if (this->jsglb) delete this->jsglb;
|
|
|
b51580 |
if (this->jsctx) JS_DestroyContext(this->jsctx);
|
|
|
b51580 |
- if (this->jsrun) JS_DestroyRuntime(this->jsrun);
|
|
|
b51580 |
JS_ShutDown();
|
|
|
b51580 |
}
|
|
|
b51580 |
|
|
|
b51580 |
@@ -178,7 +174,7 @@ class mozjs_pacrunner : public pacrunner {
|
|
|
b51580 |
JS::RootedObject global(this->jsctx,this->jsglb->get());
|
|
|
b51580 |
bool result = JS_CallFunctionName(this->jsctx, global, "FindProxyForURL", args, &rval);
|
|
|
b51580 |
if (!result) return "";
|
|
|
b51580 |
-
|
|
|
b51580 |
+
|
|
|
b51580 |
char * tmpanswer = JS_EncodeString(this->jsctx, rval.toString());
|
|
|
b51580 |
string answer = string(tmpanswer);
|
|
|
b51580 |
JS_free(this->jsctx, tmpanswer);
|
|
|
b51580 |
@@ -188,7 +184,6 @@ class mozjs_pacrunner : public pacrunner {
|
|
|
b51580 |
}
|
|
|
b51580 |
|
|
|
b51580 |
private:
|
|
|
b51580 |
- JSRuntime *jsrun;
|
|
|
b51580 |
JSContext *jsctx;
|
|
|
b51580 |
JS::Heap<JSObject*> *jsglb;
|
|
|
b51580 |
JSAutoCompartment *jsac;
|
|
|
b51580 |
From a9b052c6e30101fb0b702917f245a3e2a2f08366 Mon Sep 17 00:00:00 2001
|
|
|
b51580 |
From: Laurent Bigonville <bigon@bigon.be>
|
|
|
b51580 |
Date: Tue, 2 Oct 2018 10:22:56 +0200
|
|
|
b51580 |
Subject: [PATCH] Add call to JS::InitSelfHostedCode()
|
|
|
b51580 |
|
|
|
b51580 |
This is needed otherwise mozjs crashes
|
|
|
b51580 |
---
|
|
|
b51580 |
libproxy/modules/pacrunner_mozjs.cpp | 2 ++
|
|
|
b51580 |
1 file changed, 2 insertions(+)
|
|
|
b51580 |
|
|
|
b51580 |
diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
|
|
|
b51580 |
index ed07c69..38e7d46 100644
|
|
|
b51580 |
--- a/libproxy/modules/pacrunner_mozjs.cpp
|
|
|
b51580 |
+++ b/libproxy/modules/pacrunner_mozjs.cpp
|
|
|
b51580 |
@@ -118,6 +118,8 @@ class mozjs_pacrunner : public pacrunner {
|
|
|
b51580 |
// Initialize Javascript context
|
|
|
b51580 |
if (!(this->jsctx = JS_NewContext(1024 * 1024))) goto error;
|
|
|
b51580 |
{
|
|
|
b51580 |
+ if (!JS::InitSelfHostedCode(this->jsctx)) goto error;
|
|
|
b51580 |
+
|
|
|
b51580 |
JS::RootedValue rval(this->jsctx);
|
|
|
b51580 |
JS::CompartmentOptions compart_opts;
|
|
|
b51580 |
|