@auto_js/v8_exports 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CMakeLists.txt CHANGED
@@ -56,15 +56,32 @@ if(NPM_PACKAGE_NAME STREQUAL @auto_js/isolated_v8_exports)
56
56
  message(STATUS "Using v8 library type '${V8_LIBRARY_TYPE}'")
57
57
 
58
58
  # Preprocessor macros which enable dual v8 in the same process
59
- target_compile_definitions(${google_v8} PUBLIC
60
- cppgc=zppgc
61
- unibrow=znibrow
62
- v8_crdtp=z8_crdtp
63
- V8_Dcheck=Z8_Dcheck
64
- V8_Fatal=Z8_Fatal
65
- v8_inspector=z8_inspector
66
- v8=z8
67
- )
59
+ if(NOT DEFINED V8_TRICKSHOT)
60
+ if(DEFINED ENV{V8_TRICKSHOT})
61
+ set(V8_TRICKSHOT "$ENV{V8_TRICKSHOT}" CACHE STRING "")
62
+ else()
63
+ # nb: For older bundles where it was not defined
64
+ set(V8_TRICKSHOT blam)
65
+ endif()
66
+ endif()
67
+ if(V8_TRICKSHOT)
68
+ target_compile_definitions(${google_v8} PUBLIC
69
+ cppgc=yppgc
70
+ unibrow=ynibrow
71
+ v8_crdtp=y8_crdtp
72
+ V8_Dcheck=Y8_Dcheck
73
+ V8_Fatal=Y8_Fatal
74
+ v8_inspector=y8_inspector
75
+ v8=y8
76
+ )
77
+ endif()
78
+
79
+ # P3034R1 workaround for gcc
80
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
81
+ set(v8 y8)
82
+ else()
83
+ set(v8 v8)
84
+ endif()
68
85
 
69
86
  # Link against v8, which is built elsewhere
70
87
  if(V8_LIBRARY_TYPE STREQUAL static)
@@ -87,6 +104,7 @@ if(NPM_PACKAGE_NAME STREQUAL @auto_js/isolated_v8_exports)
87
104
  message(FATAL_ERROR "Unknown v8 library type")
88
105
  endif()
89
106
  else()
107
+ set(v8 v8)
90
108
  # Header files (nodejs)
91
109
  if(NOT DEFINED NODE_DIST_DIR)
92
110
  message(FATAL_ERROR "'NODE_DIST_DIR' is not set")
@@ -96,16 +114,24 @@ else()
96
114
  message(FATAL_ERROR "Missing '${V8_INCLUDE_DIR}/v8.h'")
97
115
  endif()
98
116
  message(STATUS "Using v8 headers from '${V8_INCLUDE_DIR}'")
117
+
118
+ # nodejs v8 is linked as a shared library
119
+ target_compile_definitions(${google_v8} PRIVATE USING_V8_SHARED)
99
120
  endif()
100
121
 
122
+ # These need to be public, for version detection. I was hoping I could do it with constexpr but
123
+ # apparently not:
124
+ # https://github.com/llvm/llvm-project/issues/203372
125
+
101
126
  # version.h
102
- target_include_directories(${google_v8} SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
127
+ target_include_directories(${google_v8} SYSTEM PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
103
128
 
104
129
  # v8 headers
105
- target_include_directories(${google_v8} SYSTEM PRIVATE "${V8_INCLUDE_DIR}")
130
+ target_include_directories(${google_v8} SYSTEM PUBLIC "${V8_INCLUDE_DIR}")
106
131
 
107
- # Sources
108
- target_sources(${google_v8}
132
+ # Sources which may be preprocessed by `expand_def`
133
+ include(./PreprocessedSources.cmake)
134
+ target_preprocessed_sources(${google_v8} v8 ${v8}
109
135
  PUBLIC FILE_SET CXX_MODULES FILES
110
136
  v8.cc
111
137
  )
@@ -0,0 +1,37 @@
1
+ # Generate lightly preprocessed C++ source files, to workaround P3034R1
2
+ function(target_preprocessed_sources TARGET SEARCH REPLACE)
3
+ set(FILE_SET ${ARGV})
4
+ list(POP_FRONT FILE_SET) # TARGET
5
+ list(POP_FRONT FILE_SET) # SEARCH
6
+ list(POP_FRONT FILE_SET) # REPLACE
7
+
8
+ if("${SEARCH}" STREQUAL "${REPLACE}")
9
+ # No-op replacement directly uses original sources
10
+ target_sources(${TARGET} ${FILE_SET})
11
+ else()
12
+ # Generated sources with macro replacement
13
+ set(GEN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.${REPLACE}")
14
+ file(MAKE_DIRECTORY "${GEN_DIR}")
15
+ file(WRITE "${GEN_DIR}/.clang-tidy" "Checks: '-*'")
16
+ set(SCOPE)
17
+ set(NEXT_SCOPE)
18
+ foreach(FILE ${FILE_SET})
19
+ # Uppercase "files" are actually scope keywords
20
+ if("${FILE}" MATCHES "^[A-Z_]+$")
21
+ list(APPEND NEXT_SCOPE "${FILE}")
22
+ continue()
23
+ elseif(NEXT_SCOPE)
24
+ set(SCOPE ${NEXT_SCOPE})
25
+ set(NEXT_SCOPE)
26
+ endif()
27
+ # Add generator command
28
+ add_custom_command(
29
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}"
30
+ OUTPUT "${GEN_DIR}/${FILE}"
31
+ COMMAND sh -c "${CMAKE_CURRENT_LIST_DIR}/expand_def ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} -D${SEARCH}=${REPLACE} >${GEN_DIR}/${FILE}"
32
+ )
33
+ set_source_files_properties("${GEN_DIR}/${FILE}" PROPERTIES GENERATED TRUE)
34
+ target_sources(${TARGET} ${SCOPE} "${GEN_DIR}/${FILE}")
35
+ endforeach()
36
+ endif()
37
+ endfunction()
package/expand_def ADDED
@@ -0,0 +1,23 @@
1
+ #!/bin/sh
2
+ # Use the c preprocessor to expand command-line macros. This works around the draconian P3034R1
3
+ # standard.
4
+ # Usage: expand_def source.cc -Dfrom=to
5
+ set -eu
6
+ FILE="$1"
7
+ shift
8
+
9
+ replace() {
10
+ sed -E -e "s/(\s*#)/__REMOVE_PRE__\1/" -e "s/^\s*\/\/([A-Za-z0-9 ()_\-]+$)/__COMMENT__\1/" | \
11
+ cpp -E "$@" | \
12
+ sed -E -e "s/__REMOVE_PRE__//" -e "s/__COMMENT__/\/\//" | \
13
+ grep -Ev "^# [01]"
14
+ }
15
+
16
+ # nb: First line *must* be the module declaration, if it exists. So the `#line` directive happens
17
+ # after that.
18
+ CONTENT=$(cat "$FILE")
19
+ echo "$CONTENT" | head -n1 | replace "$@"
20
+ echo "// NOLINTBEGIN(google-readability-namespace-comments)"
21
+ echo "#line 2 \"$FILE\""
22
+ echo "$CONTENT" | tail -n+2 | replace "$@"
23
+ echo "// NOLINTEND(google-readability-namespace-comments)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auto_js/v8_exports",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "C++ module exports for v8",
5
5
  "author": "https://github.com/laverdet/",
6
6
  "homepage": "https://github.com/laverdet/isolated-vm/tree/experimental/packages/third_party/v8",
package/v8.cc CHANGED
@@ -1,6 +1,16 @@
1
1
  module;
2
+ // Pull in `V8_EXPORT`
3
+ #include "v8config.h"
4
+
5
+ // Redefine `V8_EXPORT` with weak attribute
6
+ #if USING_V8_SHARED
7
+ #undef V8_EXPORT
8
+ #include "v8_js/extern.h"
9
+ #endif
10
+
11
+ // Continue with the rest of the include chain
2
12
  #include "v8.h"
3
- #include "version.h"
13
+ #include "v8_js/version.h"
4
14
  #ifdef INCLUDE_V8_PLATFORM
5
15
  #include "libplatform/libplatform.h"
6
16
  #include "v8-platform.h"
@@ -61,6 +71,9 @@ using v8::V8FatalErrorCallback;
61
71
 
62
72
  // v8-isolate.h
63
73
  using v8::Isolate;
74
+ using v8::IsolateGroup;
75
+ using v8::MemoryPressureLevel;
76
+ using v8::ResourceConstraints;
64
77
 
65
78
  // v8-local-handle.h
66
79
  using v8::EscapableHandleScope;
@@ -140,25 +153,13 @@ using v8::AccessCheckCallback;
140
153
  using v8::ConstructorBehavior;
141
154
  using v8::DictionaryTemplate;
142
155
  using v8::FunctionTemplate;
143
- using v8::GenericNamedPropertyDefinerCallback;
144
- using v8::GenericNamedPropertyDeleterCallback;
145
- using v8::GenericNamedPropertyDescriptorCallback;
146
- using v8::GenericNamedPropertyEnumeratorCallback;
147
- using v8::GenericNamedPropertyQueryCallback;
148
- using v8::GenericNamedPropertySetterCallback;
149
- using v8::IndexedPropertyDefinerCallback;
150
156
  using v8::IndexedPropertyDefinerCallbackV2;
151
- using v8::IndexedPropertyDeleterCallback;
152
157
  using v8::IndexedPropertyDeleterCallbackV2;
153
- using v8::IndexedPropertyDescriptorCallback;
154
158
  using v8::IndexedPropertyDescriptorCallbackV2;
155
159
  using v8::IndexedPropertyEnumeratorCallback;
156
- using v8::IndexedPropertyGetterCallback;
157
160
  using v8::IndexedPropertyGetterCallbackV2;
158
161
  using v8::IndexedPropertyHandlerConfiguration;
159
- using v8::IndexedPropertyQueryCallback;
160
162
  using v8::IndexedPropertyQueryCallbackV2;
161
- using v8::IndexedPropertySetterCallback;
162
163
  using v8::IndexedPropertySetterCallbackV2;
163
164
  using v8::Intercepted;
164
165
  using v8::NamedPropertyDefinerCallback;
package/v8_js/extern.h ADDED
@@ -0,0 +1,9 @@
1
+ #if __linux__
2
+ #define V8_EXPORT __attribute__((weak))
3
+ #elif __APPLE__
4
+ #define V8_EXPORT __attribute__((weak))
5
+ #elif _WIN64
6
+ #define V8_EXPORT __declspec(dllimport) __attribute__((weak))
7
+ #else
8
+ #define V8_EXPORT
9
+ #endif
@@ -9,3 +9,9 @@
9
9
 
10
10
  // https://github.com/v8/v8/commit/4f8d4447533bc8d119048961c2f103d9875674e0
11
11
  #define V8_HAS_NUMERIC V8_AT_LEAST(11, 7, 352)
12
+
13
+ // e1aadd4b3ec
14
+ #define V8_HAS_TAGGED_EXTERNAL V8_AT_LEAST(14, 3, 30)
15
+
16
+ // 7f7b4b9e4c8
17
+ #define V8_HAS_CONTEXT_FREE_FIXED_ARRAY V8_AT_LEAST(14, 4, 111)