libproxy-0.4.15-mozjs52.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. From f594720280b2e40d81fa6e286a0ef8868687ef7e Mon Sep 17 00:00:00 2001
  2. From: Pierre Lejeune <superheron@gmail.com>
  3. Date: Sat, 30 Jun 2018 21:10:06 +0200
  4. Subject: [PATCH] Build with mozjs-52
  5. Fixes #71
  6. ---
  7. libproxy/cmake/modules/pacrunner_mozjs.cmk | 2 +-
  8. libproxy/modules/pacrunner_mozjs.cpp | 19 +++++++------------
  9. 2 files changed, 8 insertions(+), 13 deletions(-)
  10. diff --git a/libproxy/cmake/modules/pacrunner_mozjs.cmk b/libproxy/cmake/modules/pacrunner_mozjs.cmk
  11. index c2ae3db..20857fb 100644
  12. --- a/libproxy/cmake/modules/pacrunner_mozjs.cmk
  13. +++ b/libproxy/cmake/modules/pacrunner_mozjs.cmk
  14. @@ -9,7 +9,7 @@ if(WIN32)
  15. elseif(NOT APPLE)
  16. option(WITH_MOZJS "Search for MOZJS package" ON)
  17. if (WITH_MOZJS)
  18. - pkg_search_module(MOZJS mozjs-38)
  19. + pkg_search_module(MOZJS mozjs-52)
  20. if(MOZJS_FOUND)
  21. include_directories(${MOZJS_INCLUDE_DIRS})
  22. link_directories(${MOZJS_LIBRARY_DIRS})
  23. diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
  24. index a70b2e9..ed07c69 100644
  25. --- a/libproxy/modules/pacrunner_mozjs.cpp
  26. +++ b/libproxy/modules/pacrunner_mozjs.cpp
  27. @@ -35,6 +35,7 @@ using namespace libproxy;
  28. #pragma GCC diagnostic ignored "-Winvalid-offsetof"
  29. #include <jsapi.h>
  30. #pragma GCC diagnostic error "-Winvalid-offsetof"
  31. +#include <js/Initialization.h>
  32. #include <js/CallArgs.h>
  33. #include "pacutils.h"
  34. @@ -111,17 +112,14 @@ class mozjs_pacrunner : public pacrunner {
  35. mozjs_pacrunner(string pac, const url& pacurl) throw (bad_alloc) : pacrunner(pac, pacurl) {
  36. // Set defaults
  37. - this->jsrun = nullptr;
  38. this->jsctx = nullptr;
  39. JS_Init();
  40. - // Initialize Javascript runtime environment
  41. - if (!(this->jsrun = JS_NewRuntime(1024 * 1024))) goto error;
  42. - if (!(this->jsctx = JS_NewContext(this->jsrun, 1024 * 1024))) goto error;
  43. + // Initialize Javascript context
  44. + if (!(this->jsctx = JS_NewContext(1024 * 1024))) goto error;
  45. {
  46. JS::RootedValue rval(this->jsctx);
  47. JS::CompartmentOptions compart_opts;
  48. - compart_opts.setVersion(JSVERSION_LATEST);
  49. this->jsglb = new JS::Heap<JSObject*>(JS_NewGlobalObject(
  50. this->jsctx, &cls,
  51. @@ -139,16 +137,15 @@ class mozjs_pacrunner : public pacrunner {
  52. JS::CompileOptions options(this->jsctx);
  53. options.setUTF8(true);
  54. - JS::Evaluate(this->jsctx, global, options, JAVASCRIPT_ROUTINES,
  55. - strlen(JAVASCRIPT_ROUTINES), &rval);
  56. + JS::Evaluate(this->jsctx, options, JAVASCRIPT_ROUTINES,
  57. + strlen(JAVASCRIPT_ROUTINES), JS::MutableHandleValue(&rval));
  58. // Add PAC to the environment
  59. - JS::Evaluate(this->jsctx, global, options, pac.c_str(), pac.length(), &rval);
  60. + JS::Evaluate(this->jsctx, options, pac.c_str(), pac.length(), JS::MutableHandleValue(&rval));
  61. return;
  62. }
  63. error:
  64. if (this->jsctx) JS_DestroyContext(this->jsctx);
  65. - if (this->jsrun) JS_DestroyRuntime(this->jsrun);
  66. throw bad_alloc();
  67. }
  68. @@ -156,7 +153,6 @@ class mozjs_pacrunner : public pacrunner {
  69. if (this->jsac) delete this->jsac;
  70. if (this->jsglb) delete this->jsglb;
  71. if (this->jsctx) JS_DestroyContext(this->jsctx);
  72. - if (this->jsrun) JS_DestroyRuntime(this->jsrun);
  73. JS_ShutDown();
  74. }
  75. @@ -178,7 +174,7 @@ class mozjs_pacrunner : public pacrunner {
  76. JS::RootedObject global(this->jsctx,this->jsglb->get());
  77. bool result = JS_CallFunctionName(this->jsctx, global, "FindProxyForURL", args, &rval);
  78. if (!result) return "";
  79. -
  80. +
  81. char * tmpanswer = JS_EncodeString(this->jsctx, rval.toString());
  82. string answer = string(tmpanswer);
  83. JS_free(this->jsctx, tmpanswer);
  84. @@ -188,7 +184,6 @@ class mozjs_pacrunner : public pacrunner {
  85. }
  86. private:
  87. - JSRuntime *jsrun;
  88. JSContext *jsctx;
  89. JS::Heap<JSObject*> *jsglb;
  90. JSAutoCompartment *jsac;
  91. From a9b052c6e30101fb0b702917f245a3e2a2f08366 Mon Sep 17 00:00:00 2001
  92. From: Laurent Bigonville <bigon@bigon.be>
  93. Date: Tue, 2 Oct 2018 10:22:56 +0200
  94. Subject: [PATCH] Add call to JS::InitSelfHostedCode()
  95. This is needed otherwise mozjs crashes
  96. ---
  97. libproxy/modules/pacrunner_mozjs.cpp | 2 ++
  98. 1 file changed, 2 insertions(+)
  99. diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
  100. index ed07c69..38e7d46 100644
  101. --- a/libproxy/modules/pacrunner_mozjs.cpp
  102. +++ b/libproxy/modules/pacrunner_mozjs.cpp
  103. @@ -118,6 +118,8 @@ class mozjs_pacrunner : public pacrunner {
  104. // Initialize Javascript context
  105. if (!(this->jsctx = JS_NewContext(1024 * 1024))) goto error;
  106. {
  107. + if (!JS::InitSelfHostedCode(this->jsctx)) goto error;
  108. +
  109. JS::RootedValue rval(this->jsctx);
  110. JS::CompartmentOptions compart_opts;