You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
15 KiB

  1. From 1a5aadcd66e85c63d228bfd811a521d617c22a38 Mon Sep 17 00:00:00 2001
  2. From: Patrick Schneider <patrick.schneider@meetnow.eu>
  3. Date: Thu, 13 Apr 2017 15:02:53 +0200
  4. Subject: [PATCH] Add Node 7.x aka V8 5.2+ support
  5. * Use WeakCallbackInfo instead of WeakCallbackData
  6. * Use GetPrivate instead of GetHiddenValue
  7. * Adopted new signature for SetWeak to support destructor calling
  8. * SetAccessor deprecation fixed
  9. * Proper version checks where applicable
  10. Upstream-Status: Submitted [https://github.com/swig/swig/pull/968]
  11. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
  12. ---
  13. Lib/javascript/v8/javascriptcode.swg | 27 +++++++++++++++++-----
  14. Lib/javascript/v8/javascripthelpers.swg | 29 +++++++++++++++++++++---
  15. Lib/javascript/v8/javascriptinit.swg | 16 +++++++++++--
  16. Lib/javascript/v8/javascriptrun.swg | 40 ++++++++++++++++++++++++++++-----
  17. 4 files changed, 95 insertions(+), 17 deletions(-)
  18. diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg
  19. index fb7d55c..b8c5089 100644
  20. --- a/Lib/javascript/v8/javascriptcode.swg
  21. +++ b/Lib/javascript/v8/javascriptcode.swg
  22. @@ -133,10 +133,13 @@ static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Value> object, v
  23. SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
  24. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  25. static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, SWIGV8_Proxy *proxy) {
  26. -#else
  27. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  28. static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
  29. v8::Local<v8::Object> object = data.GetValue();
  30. SWIGV8_Proxy *proxy = data.GetParameter();
  31. +#else
  32. + static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
  33. + SWIGV8_Proxy *proxy = data.GetParameter();
  34. #endif
  35. if(proxy->swigCMemOwn && proxy->swigCObject) {
  36. @@ -147,7 +150,9 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
  37. }
  38. delete proxy;
  39. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  40. object.Clear();
  41. +#endif
  42. #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
  43. object.Dispose();
  44. @@ -155,7 +160,7 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
  45. object.Dispose(isolate);
  46. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
  47. object->Dispose(isolate);
  48. -#else
  49. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  50. object->Dispose();
  51. #endif
  52. }
  53. @@ -177,10 +182,13 @@ static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Value> object, v
  54. SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
  55. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  56. static void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object> *object, SWIGV8_Proxy *proxy) {
  57. -#else
  58. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  59. static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
  60. v8::Local<v8::Object> object = data.GetValue();
  61. SWIGV8_Proxy *proxy = data.GetParameter();
  62. +#else
  63. +static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
  64. + SWIGV8_Proxy *proxy = data.GetParameter();
  65. #endif
  66. if(proxy->swigCMemOwn && proxy->swigCObject) {
  67. @@ -197,7 +205,7 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
  68. object->Dispose(isolate);
  69. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  70. object->Dispose();
  71. -#else
  72. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  73. object.Clear();
  74. #endif
  75. }
  76. @@ -211,7 +219,11 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
  77. * ----------------------------------------------------------------------------- */
  78. %fragment("js_getter", "templates")
  79. %{
  80. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  81. static SwigV8ReturnValue $jswrapper(v8::Local<v8::String> property, const SwigV8PropertyCallbackInfo &info) {
  82. +#else
  83. +static SwigV8ReturnValue $jswrapper(v8::Local<v8::Name> property, const SwigV8PropertyCallbackInfo &info) {
  84. +#endif
  85. SWIGV8_HANDLESCOPE();
  86. v8::Handle<v8::Value> jsresult;
  87. @@ -233,8 +245,11 @@ fail:
  88. * ----------------------------------------------------------------------------- */
  89. %fragment("js_setter", "templates")
  90. %{
  91. -static void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value,
  92. - const SwigV8PropertyCallbackInfoVoid &info) {
  93. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  94. +static void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
  95. +#else
  96. +static void $jswrapper(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
  97. +#endif
  98. SWIGV8_HANDLESCOPE();
  99. $jslocals
  100. diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg
  101. index 091467d..7461079 100644
  102. --- a/Lib/javascript/v8/javascripthelpers.swg
  103. +++ b/Lib/javascript/v8/javascripthelpers.swg
  104. @@ -6,11 +6,16 @@ typedef v8::InvocationCallback SwigV8FunctionCallback;
  105. typedef v8::AccessorGetter SwigV8AccessorGetterCallback;
  106. typedef v8::AccessorSetter SwigV8AccessorSetterCallback;
  107. typedef v8::AccessorInfo SwigV8PropertyCallbackInfoVoid;
  108. -#else
  109. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  110. typedef v8::FunctionCallback SwigV8FunctionCallback;
  111. typedef v8::AccessorGetterCallback SwigV8AccessorGetterCallback;
  112. typedef v8::AccessorSetterCallback SwigV8AccessorSetterCallback;
  113. typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
  114. +#else
  115. +typedef v8::FunctionCallback SwigV8FunctionCallback;
  116. +typedef v8::AccessorNameGetterCallback SwigV8AccessorGetterCallback;
  117. +typedef v8::AccessorNameSetterCallback SwigV8AccessorSetterCallback;
  118. +typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
  119. #endif
  120. /**
  121. @@ -65,18 +70,36 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char
  122. */
  123. SWIGRUNTIME void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol,
  124. SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
  125. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  126. obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter);
  127. +#else
  128. + obj->SetAccessor(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW(symbol), getter, setter);
  129. +#endif
  130. }
  131. -SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value,
  132. - const SwigV8PropertyCallbackInfoVoid& info)
  133. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  134. +SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid& info)
  135. +#else
  136. +SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid& info)
  137. +#endif
  138. {
  139. char buffer[256];
  140. char msg[512];
  141. int res;
  142. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  143. property->WriteUtf8(buffer, 256);
  144. res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
  145. +#else
  146. + v8::Local<v8::String> sproperty;
  147. + if (property->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocal(&sproperty)) {
  148. + sproperty->WriteUtf8(buffer, 256);
  149. + res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
  150. + }
  151. + else {
  152. + res = -1;
  153. + }
  154. +#endif
  155. if(res<0) {
  156. SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
  157. diff --git a/Lib/javascript/v8/javascriptinit.swg b/Lib/javascript/v8/javascriptinit.swg
  158. index 34befa7..86008d9 100644
  159. --- a/Lib/javascript/v8/javascriptinit.swg
  160. +++ b/Lib/javascript/v8/javascriptinit.swg
  161. @@ -7,15 +7,27 @@ SWIG_V8_SetModule(void *, swig_module_info *swig_module) {
  162. v8::Local<v8::Object> global_obj = SWIGV8_CURRENT_CONTEXT()->Global();
  163. v8::Local<v8::External> mod = SWIGV8_EXTERNAL_NEW(swig_module);
  164. assert(!mod.IsEmpty());
  165. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  166. global_obj->SetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"), mod);
  167. +#else
  168. + v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data"));
  169. + global_obj->SetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey, mod);
  170. +#endif
  171. }
  172. SWIGRUNTIME swig_module_info *
  173. SWIG_V8_GetModule(void *) {
  174. v8::Local<v8::Object> global_obj = SWIGV8_CURRENT_CONTEXT()->Global();
  175. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  176. v8::Local<v8::Value> moduleinfo = global_obj->GetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"));
  177. +#else
  178. + v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data"));
  179. + v8::Local<v8::Value> moduleinfo;
  180. + if (!global_obj->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&moduleinfo))
  181. + return 0;
  182. +#endif
  183. - if (moduleinfo.IsEmpty())
  184. + if (moduleinfo.IsEmpty() || moduleinfo->IsNull() || moduleinfo->IsUndefined())
  185. {
  186. // It's not yet loaded
  187. return 0;
  188. @@ -23,7 +35,7 @@ SWIG_V8_GetModule(void *) {
  189. v8::Local<v8::External> moduleinfo_extern = v8::Local<v8::External>::Cast(moduleinfo);
  190. - if (moduleinfo_extern.IsEmpty())
  191. + if (moduleinfo_extern.IsEmpty() || moduleinfo_extern->IsNull() || moduleinfo_extern->IsUndefined())
  192. {
  193. // Something's not right
  194. return 0;
  195. diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg
  196. index 5ac52a5..30002c0 100644
  197. --- a/Lib/javascript/v8/javascriptrun.swg
  198. +++ b/Lib/javascript/v8/javascriptrun.swg
  199. @@ -193,8 +193,10 @@ public:
  200. void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Value> object, void *parameter);
  201. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  202. void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy);
  203. -#else
  204. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  205. void (*dtor) (const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data);
  206. +#else
  207. + void (*dtor) (const v8::WeakCallbackInfo<SWIGV8_Proxy> &data);
  208. #endif
  209. };
  210. @@ -241,9 +243,12 @@ SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Val
  211. SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
  212. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  213. SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) {
  214. -#else
  215. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  216. SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
  217. SWIGV8_Proxy *proxy = data.GetParameter();
  218. +#else
  219. +SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
  220. + SWIGV8_Proxy *proxy = data.GetParameter();
  221. #endif
  222. delete proxy;
  223. @@ -312,12 +317,18 @@ SWIGRUNTIME void SWIGV8_SetPrivateData(v8::Handle<v8::Object> obj, void *ptr, sw
  224. } else {
  225. cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
  226. }
  227. -#else
  228. +#elifif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  229. if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
  230. cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
  231. } else {
  232. cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor);
  233. }
  234. +#else
  235. + if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
  236. + cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor, v8::WeakCallbackType::kParameter);
  237. + } else {
  238. + cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor, v8::WeakCallbackType::kParameter);
  239. + }
  240. #endif
  241. #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
  242. @@ -470,7 +481,14 @@ int SwigV8Packed_Check(v8::Handle<v8::Value> valRef) {
  243. v8::Handle<v8::Object> objRef = valRef->ToObject();
  244. if(objRef->InternalFieldCount() < 1) return false;
  245. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  246. v8::Handle<v8::Value> flag = objRef->GetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"));
  247. +#else
  248. + v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__"));
  249. + v8::Local<v8::Value> flag;
  250. + if (!objRef->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&flag))
  251. + return false;
  252. +#endif
  253. return (flag->IsBoolean() && flag->BooleanValue());
  254. }
  255. @@ -519,10 +537,13 @@ SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persist
  256. SwigV8PackedData *cdata = static_cast<SwigV8PackedData *>(parameter);
  257. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  258. SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, SwigV8PackedData *cdata) {
  259. -#else
  260. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  261. SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData<v8::Object, SwigV8PackedData> &data) {
  262. v8::Local<v8::Object> object = data.GetValue();
  263. SwigV8PackedData *cdata = data.GetParameter();
  264. +#else
  265. +SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackInfo<SwigV8PackedData> &data) {
  266. + SwigV8PackedData *cdata = data.GetParameter();
  267. #endif
  268. delete cdata;
  269. @@ -537,7 +558,7 @@ SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData<v8::Ob
  270. object->Dispose(isolate);
  271. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  272. object->Dispose();
  273. -#else
  274. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  275. object.Clear();
  276. #endif
  277. }
  278. @@ -550,7 +571,12 @@ v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf
  279. // v8::Handle<v8::Object> obj = SWIGV8_OBJECT_NEW();
  280. v8::Local<v8::Object> obj = SWIGV8_OBJECT_NEW();
  281. +#if (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  282. obj->SetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"), SWIGV8_BOOLEAN_NEW(true));
  283. +#else
  284. + v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__"));
  285. + obj->SetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey, SWIGV8_BOOLEAN_NEW(true));
  286. +#endif
  287. #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
  288. obj->SetPointerInInternalField(0, cdata);
  289. @@ -573,9 +599,11 @@ v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf
  290. cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete);
  291. #elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
  292. cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
  293. -#else
  294. +#elif (V8_MAJOR_VERSION-0) < 5 || (V8_MAJOR_VERSION == 5 && V8_MINOR_VERSION < 2)
  295. cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete);
  296. // v8::V8::SetWeak(&cdata->handle, cdata, _wrap_SwigV8PackedData_delete);
  297. +#else
  298. + cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete, v8::WeakCallbackType::kParameter);
  299. #endif
  300. #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
  301. --
  302. 2.9.5