summaryrefslogtreecommitdiff
path: root/libproxy-0.4.15-mozjs52.patch
blob: a9e2ce921a36a91cf3428c9bcb2aeceb24ced3a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
From f594720280b2e40d81fa6e286a0ef8868687ef7e Mon Sep 17 00:00:00 2001
From: Pierre Lejeune <superheron@gmail.com>
Date: Sat, 30 Jun 2018 21:10:06 +0200
Subject: [PATCH] Build with mozjs-52

Fixes #71
---
 libproxy/cmake/modules/pacrunner_mozjs.cmk |  2 +-
 libproxy/modules/pacrunner_mozjs.cpp       | 19 +++++++------------
 2 files changed, 8 insertions(+), 13 deletions(-)

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

This is needed otherwise mozjs crashes
---
 libproxy/modules/pacrunner_mozjs.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
index ed07c69..38e7d46 100644
--- a/libproxy/modules/pacrunner_mozjs.cpp
+++ b/libproxy/modules/pacrunner_mozjs.cpp
@@ -118,6 +118,8 @@ class mozjs_pacrunner : public pacrunner {
 		// Initialize Javascript context
 		if (!(this->jsctx = JS_NewContext(1024 * 1024)))     goto error;
 		{
+			if (!JS::InitSelfHostedCode(this->jsctx)) goto error;
+
 			JS::RootedValue  rval(this->jsctx);
 			JS::CompartmentOptions compart_opts;