Commit Graph

82 Commits

Author SHA1 Message Date
William S Fulton dce0f9012b [JavaScript] Fix the v8 and node engines for v8 13.x (Node.js 24)
v8 12.6 deprecated FunctionCallbackInfo::Holder() and 13.5 removed it, so the
generated code did not compile with Node.js 24. This() has been available for
as long as SWIG has supported v8 and is the documented replacement, so it is
used unconditionally via the new SWIGV8_ARGS_THIS macro.

PropertyCallbackInfo needs a version check as its Holder() replacement,
HolderV2(), was only added in v8 12.7 - SWIGV8_INFO_HOLDER handles this.

v8 13.3 added Utf8LengthV2 and WriteUtf8V2 and deprecated Utf8Length and
WriteUtf8, which is fatal as the examples are compiled with -Werror. The
existing SWIGV8_UTF8_LENGTH and SWIGV8_WRITE_UTF8 macros now select between
them. The buffer size passed to SWIGV8_WRITE_UTF8 now always includes room
for the NUL and the returned count includes the NUL, matching WriteUtf8V2
with WriteFlags::kNullTerminate.

The ARGC/ARGV typemap relied on the old behaviour of passing a buffer size
excluding the NUL. With WriteUtf8V2 that silently truncates the last
character while still returning the expected count, so the length check
would have passed for a corrupted string.

Node.js 24 is added to the CI test matrix for both the node and napi engines.

The minimum supported v8 version is unchanged at 7.4.

Assisted-by: Claude Code (Opus 5)
2026-08-01 09:42:44 +01:00
Olly Betts 7274c3f9b7 Make minimum supported v8 version 7.4
This is the oldest we are able to test in CI, and only then via it being
the version use by the oldest node.js we can test in CI.  We have no
direct testing with v8 in CI currently, and it seems hard to
v8_shell.cxx no longer building with more recent v8 versions.

See #2537
2024-09-19 08:25:44 +12:00
Momtchil Momtchev 721a4808b8 remove hacks and implement default arguments 2023-05-31 13:22:35 +02:00
Olly Betts 7c97bd5ab3 [js] Remove code to handle v8 < 5.0
We require at least node v6 which means v8 5.0, so code to handle
older v8 is no longer useful.
2021-12-02 14:04:25 +13:00
Andy Polyakov b56814ce08 Lib/javascript/v8/javascriptrun.swg: clean up pre-processor conditions.
Harmonize javascriptcode.swg javascripthelpers.swg and clarify
documentation.
2021-03-10 14:51:08 +01:00
Andy Polyakov b0c01ea851 Lib/javascript/v8: use context-aware initialization.
Context-aware initialization allows to instantiate add-ons multiple
times, most importantly in multiple Workers' contexts. Workers made
first appearance in v10.5. Context-aware initialization was option
earlier than that, even before supported minimum v6.x, yet condition
is chosen more conservatively as NODE_MODULE_VERSION >= 64, a.k.a.
v10.0.
2021-03-02 15:31:28 +01:00
William S Fulton 30216c4fb8 Merge branch 'js-fix-626'
* js-fix-626:
  Added check to prevent crash on illegal constructor call
2021-02-28 22:00:55 +00:00
William S Fulton 0e36b5d6fd Fixes for node v12.0-12.5 2021-02-27 22:18:27 +00:00
William S Fulton 7cb719ee67 -Wunused-result fixes for Node < 12
Fix 0533fc26c which adds in calls to Check(), which was added in Node 12.
Also fix e6315eedd which calls the new Set() and Check() method.
2021-02-27 22:17:59 +00:00
William S Fulton 0533fc26ca Fix -Wunused-result warnings in node wrappers 2021-02-26 22:23:57 +00:00
tungpham25 36960396ba Revert "Merge pull request #3 from tungntpham/new-node-fixes-refactor"
This reverts commit 35f05bd541, reversing
changes made to 0ea6a3bdbf.
2021-01-28 21:48:45 +00:00
TungPham51D 4ce34742a7 OPTIM: Restructured the code where it checks for V8 version, removing duplicate code and potentially improving the readability. 2021-01-14 13:48:19 +00:00
Yegor Yefremov 113d78a083 Add support for Node.js v12 2020-04-07 15:23:31 +02:00
Yegor Yefremov 26fc996ad6 Replace Handle with Local depending on Node.js version
Use newly introduced macros like SWIGV8_VALUE to use v8::Handle or
v8::Local depending on the selected Node.js version where possible.
2020-04-07 14:13:12 +02:00
Patrick Schneider 9ce8d7e7c9 Remove warnings on Node 6.x aka V8 5.0 and 5.1
The proposed changes targetted at 5.2 (or 5.4 to be more precise, since there is no Node release with V8 5.2 or 5.3) work for lower versions as well and bust the deprecation warnings there.
2017-04-13 19:39:44 +02:00
Patrick Schneider f768fd2b9d Added check to prevent crash on illegal constructor call
Constructors not called as part of object instantiation (using "new" or via inheritance) will not crash the VM anymore.
2017-04-13 17:31:00 +02:00
Patrick Schneider f08d7a63a9 Add Node 7.x aka V8 5.2+ support
* Use WeakCallbackInfo instead of WeakCallbackData
* Use GetPrivate instead of GetHiddenValue
* Adopted new signature for SetWeak to support destructor calling
* SetAccessor deprecation fixed
* Proper version checks where applicable
2017-04-13 15:02:53 +02:00
Olly Betts b138f054e5 [Javascript] Fix SWIG_exception() macro (#792)
Fix SWIG_exception() macro to return from the current function.
Fixes #789, reported by Julien Dutriaux.
2016-09-17 17:29:42 +12:00
Olly Betts b3bedc210c [Javascript] For v8 >= 4.3.0, use V8_MAJOR_VERSION.
Fixes https://github.com/swig/swig/issues/561.
2016-01-12 09:33:13 +13:00
Richard 00457b6599 Making generated code more readable 2014-09-30 12:33:49 -03:00
Richard 0dfc1b090f Fix duplicate symbol linker errors for Javascript/v8 2014-09-09 10:08:30 -03:00
Richard 911fd761b0 Minor improvements 2014-08-28 19:46:52 -05:00
Richard eeb4b5497e Fixes for v8 3.24.17 (0x032417) 2014-08-28 19:46:51 -05:00
Richard fee5748499 Fixes for 3.23.18 (0x032318) 2014-08-28 19:46:51 -05:00
Richard d4920591d4 Fixes for v8 3.24.3 (0x032403) 2014-08-28 19:46:51 -05:00
Richard e0c0670540 Partially fixed for 3.25.30 (0x032530) - unfinished 2014-08-28 19:46:50 -05:00
Richard e98a659246 Fixes for v8 3.21.17 (0x032117) 2014-08-28 19:46:50 -05:00
Richard 013fb3d22d Fixes for v8 3.19.2 (0x031902) 2014-08-28 19:46:50 -05:00
Richard 8829230641 Fixes for v8 3.17.10 (0x031710) 2014-08-28 19:46:49 -05:00
William S Fulton 9587c133c5 Fix typo in Javascript exception 2014-04-19 15:55:12 +01:00
Oliver Buchtala 0528fd3ac3 Bugfix for Javascript generator. 2013-09-16 11:46:00 +02:00
Oliver Buchtala 1f07195812 Rearrange generation of init block to have custom init code within the initializer body. 2013-09-16 03:53:00 +02:00
Oliver Buchtala dd84e6f9e0 Some fixes and cleanup in Javascript generator.
- v8 generator uses the correct mangled name for class templates
- removed symbols for template variables in favor of using the string
  literals directly, as it is easier to understand when debugging.
2013-09-10 14:16:36 +03:00
Oliver Buchtala be35d94fdb Add support for PackedData to Javascript generator. 2013-09-10 11:53:12 +03:00
Oliver Buchtala 8408e9b193 Merge pull request #19 from whoozle/devel
fixed deprecation warnings for v8-3.21
2013-09-06 19:50:51 -07:00
Oliver Buchtala 29ccb270af Renamed object provided to JS initializers.
JSC initializer create a new module object.
V8 initializer fill a provided 'exports' object.
2013-09-06 00:40:29 +03:00
Vladimir Menshakov b49da78b0a fixed deprecation warnings for v8-3.21 2013-09-05 19:50:15 +04:00
Vladimir Menshakov 2a39abebb6 moved common swig v8 definitions in javascriptruntime.swg, fixed obsoleted api calls 2013-09-04 20:10:42 +04:00
Vladimir Menshakov b7db2a84c9 fixed return values and added missing newer v8 dtor wrapper. 2013-09-04 19:33:48 +04:00
Oliver Buchtala 14a137adca Fix regression. 2013-09-03 06:27:14 +02:00
Oliver Buchtala a48438c562 Better v8 version handling.
You should start to specify a version on command line, e.g.,

    swig -javascript -v8 -DSWIG_V8_VERSION=0x032007
2013-09-03 05:39:37 +02:00
Vladimir Menshakov cb5f4dc47e ported to newer, more efficient v8 api 2013-08-31 05:00:32 +02:00
Oliver Buchtala 32f9cce600 Merged whoozle branch with ewmailing branch.
Conflicts:
	Lib/javascript/v8/javascriptcode.swg
2013-08-31 03:47:43 +02:00
Oliver Buchtala 306b265af9 Merge branch 'devel' of git://github.com/oliver----/swig-v8 into devel
Conflicts:
	Lib/javascript/v8/javascriptcode.swg
2013-08-31 03:47:08 +02:00
Eric Wing 65a0be8876 v8: variable name bug fix in my template modifications for pointers to structs. 2013-08-31 03:46:07 +02:00
Eric Wing f8feeacb68 v8: Removed the extern "C" around the initialize function because it makes no sense since it requires a C++ templates object as a parameter. 2013-08-31 03:46:07 +02:00
Eric Wing ed729f7d3a This brings over the memory leak fixes for pointers to structs with a %extend destructor from my Neha fork. The generator was not generating and connecting the needed code for the requested destructor to the v8 dtor finalizer.
I did not realize this branch has some JavaScriptCore stuff in it too. Unfortunately, it seems to have its own unique problems (like creating C++ files when it should be generating C files). My changes are targeted for v8, and I don't think my JSCore changes fully reach in this JSCore implementation so more work would need to be done to get this branch working. I think my Neha fork is in better shape at the moment.

Also, I did port over the 'NULL out the dtor function pointer' in the %nodefaultdtor fix to v8.

Usage case:
struct MyData {
%extend {
~MyData() {
FreeData($self);
}
}
};
%newobject CreateData;
struct MyData* CreateData(void);
%delobject FreeData;
void FreeData(struct MyData* the_data);

where the use case is something like:
var my_data = example.CreateData();
my_data = null;
2013-08-31 03:46:07 +02:00
Eric Wing d5df0bb721 Added #if defined guard for V8_3_14 to allow users from the original SWIG v8 implementation to continue using the new changes. It works similarly to the BUILDING_NODE_EXTENSION in all but two places. This define must be explicitly set by users because there is no way to auto detect. (Perhaps a command line switch can be added to generate this on request?) 2013-08-31 03:46:06 +02:00
Jason Turner 046ca7686b Adjust for v8::Persistent API which was deprecated @ 3.19.16
https://groups.google.com/forum/#!topic/v8-users/oBE_DTpRC08
2013-08-31 03:46:06 +02:00
Jason Turner cf9b7e89ac Get memory updates working with Node.js again. 2013-08-31 03:46:06 +02:00