mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
deps: patch V8 to support compilation with MSVC
Co-Authored-By: Michaël Zasso <targos@protonmail.com> PR-URL: https://github.com/nodejs/node/pull/58070 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
parent
ffadf3561a
commit
0f98039268
21 changed files with 147 additions and 60 deletions
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
# Reset this number to 0 on major V8 upgrades.
|
# Reset this number to 0 on major V8 upgrades.
|
||||||
# Increment by one for each non-official patch applied to deps/v8.
|
# Increment by one for each non-official patch applied to deps/v8.
|
||||||
'v8_embedder_string': '-node.8',
|
'v8_embedder_string': '-node.9',
|
||||||
|
|
||||||
##### V8 defaults for Node.js #####
|
##### V8 defaults for Node.js #####
|
||||||
|
|
||||||
|
|
16
deps/v8/src/base/fpu.cc
vendored
16
deps/v8/src/base/fpu.cc
vendored
|
@ -57,13 +57,21 @@ void FPU::SetFlushDenormals(bool value) {
|
||||||
#elif defined(V8_HOST_ARCH_ARM64) || defined(V8_HOST_ARCH_ARM)
|
#elif defined(V8_HOST_ARCH_ARM64) || defined(V8_HOST_ARCH_ARM)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
#if defined(V8_HOST_ARCH_ARM64) && defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Bit 24 is the flush-to-zero mode control bit. Setting it to 1 flushes
|
// Bit 24 is the flush-to-zero mode control bit. Setting it to 1 flushes
|
||||||
// denormals to 0.
|
// denormals to 0.
|
||||||
constexpr int kFlushDenormToZeroBit = (1 << 24);
|
constexpr int kFlushDenormToZeroBit = (1 << 24);
|
||||||
int GetStatusWord() {
|
int GetStatusWord() {
|
||||||
int result;
|
int result;
|
||||||
#if defined(V8_HOST_ARCH_ARM64)
|
#if defined(V8_HOST_ARCH_ARM64)
|
||||||
asm volatile("mrs %x[result], FPCR" : [result] "=r"(result));
|
# if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
result = _ReadStatusReg(ARM64_FPCR);
|
||||||
|
# else
|
||||||
|
asm volatile("mrs %x[result], FPCR" : [result] "=r"(result));
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
asm volatile("vmrs %[result], FPSCR" : [result] "=r"(result));
|
asm volatile("vmrs %[result], FPSCR" : [result] "=r"(result));
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,7 +80,11 @@ int GetStatusWord() {
|
||||||
|
|
||||||
void SetStatusWord(int a) {
|
void SetStatusWord(int a) {
|
||||||
#if defined(V8_HOST_ARCH_ARM64)
|
#if defined(V8_HOST_ARCH_ARM64)
|
||||||
asm volatile("msr FPCR, %x[src]" : : [src] "r"(a));
|
# if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
_WriteStatusReg(ARM64_FPCR, a);
|
||||||
|
# else
|
||||||
|
asm volatile("msr FPCR, %x[src]" : : [src] "r"(a));
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
asm volatile("vmsr FPSCR, %[src]" : : [src] "r"(a));
|
asm volatile("vmsr FPSCR, %[src]" : : [src] "r"(a));
|
||||||
#endif
|
#endif
|
||||||
|
|
8
deps/v8/src/codegen/arm64/assembler-arm64.h
vendored
8
deps/v8/src/codegen/arm64/assembler-arm64.h
vendored
|
@ -168,14 +168,10 @@ class AssemblerZone {
|
||||||
public:
|
public:
|
||||||
explicit AssemblerZone(const MaybeAssemblerZone& zone)
|
explicit AssemblerZone(const MaybeAssemblerZone& zone)
|
||||||
// Create a fresh Zone unless one is already provided.
|
// Create a fresh Zone unless one is already provided.
|
||||||
: maybe_local_zone_(
|
: maybe_local_zone_(),
|
||||||
std::holds_alternative<Zone*>(zone)
|
|
||||||
? std::nullopt
|
|
||||||
: std::make_optional<Zone>(std::get<AccountingAllocator*>(zone),
|
|
||||||
ZONE_NAME)),
|
|
||||||
zone_(std::holds_alternative<Zone*>(zone)
|
zone_(std::holds_alternative<Zone*>(zone)
|
||||||
? std::get<Zone*>(zone)
|
? std::get<Zone*>(zone)
|
||||||
: &maybe_local_zone_.value()) {}
|
: &maybe_local_zone_.emplace(std::get<AccountingAllocator*>(zone), ZONE_NAME)) {}
|
||||||
|
|
||||||
Zone* get() const { return zone_; }
|
Zone* get() const { return zone_; }
|
||||||
|
|
||||||
|
|
2
deps/v8/src/compiler/js-heap-broker.cc
vendored
2
deps/v8/src/compiler/js-heap-broker.cc
vendored
|
@ -879,7 +879,7 @@ ElementAccessFeedback const& JSHeapBroker::ProcessFeedbackMapsForElementAccess(
|
||||||
Tagged<Map> transition_target;
|
Tagged<Map> transition_target;
|
||||||
|
|
||||||
// Don't generate elements kind transitions from stable maps.
|
// Don't generate elements kind transitions from stable maps.
|
||||||
if (!map.is_stable()) {
|
if (!map.is_stable() && possible_transition_targets.begin() != possible_transition_targets.end()) {
|
||||||
// The lock is needed for UnusedPropertyFields (called deep inside
|
// The lock is needed for UnusedPropertyFields (called deep inside
|
||||||
// FindElementsKindTransitionedMap).
|
// FindElementsKindTransitionedMap).
|
||||||
MapUpdaterGuardIfNeeded mumd_scope(this);
|
MapUpdaterGuardIfNeeded mumd_scope(this);
|
||||||
|
|
6
deps/v8/src/execution/frames.h
vendored
6
deps/v8/src/execution/frames.h
vendored
|
@ -1292,11 +1292,11 @@ class WasmFrame : public TypedFrame {
|
||||||
FrameSummaries Summarize() const override;
|
FrameSummaries Summarize() const override;
|
||||||
|
|
||||||
static WasmFrame* cast(StackFrame* frame) {
|
static WasmFrame* cast(StackFrame* frame) {
|
||||||
DCHECK(frame->is_wasm()
|
|
||||||
#ifdef V8_ENABLE_DRUMBRAKE
|
#ifdef V8_ENABLE_DRUMBRAKE
|
||||||
&& !frame->is_wasm_interpreter_entry()
|
DCHECK(frame->is_wasm() && !frame->is_wasm_interpreter_entry());
|
||||||
|
#else
|
||||||
|
DCHECK(frame->is_wasm());
|
||||||
#endif // V8_ENABLE_DRUMBRAKE
|
#endif // V8_ENABLE_DRUMBRAKE
|
||||||
);
|
|
||||||
return static_cast<WasmFrame*>(frame);
|
return static_cast<WasmFrame*>(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
deps/v8/src/execution/isolate.h
vendored
4
deps/v8/src/execution/isolate.h
vendored
|
@ -574,10 +574,14 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
|
||||||
#define THREAD_LOCAL_TOP_ADDRESS(type, name) \
|
#define THREAD_LOCAL_TOP_ADDRESS(type, name) \
|
||||||
inline type* name##_address() { return &thread_local_top()->name##_; }
|
inline type* name##_address() { return &thread_local_top()->name##_; }
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
extern thread_local Isolate* g_current_isolate_ V8_CONSTINIT;
|
||||||
|
#else
|
||||||
// Do not use this variable directly, use Isolate::Current() instead.
|
// Do not use this variable directly, use Isolate::Current() instead.
|
||||||
// Defined outside of Isolate because Isolate uses V8_EXPORT_PRIVATE.
|
// Defined outside of Isolate because Isolate uses V8_EXPORT_PRIVATE.
|
||||||
__attribute__((tls_model(V8_TLS_MODEL))) extern thread_local Isolate*
|
__attribute__((tls_model(V8_TLS_MODEL))) extern thread_local Isolate*
|
||||||
g_current_isolate_ V8_CONSTINIT;
|
g_current_isolate_ V8_CONSTINIT;
|
||||||
|
#endif // defined(_MSC_VER)
|
||||||
|
|
||||||
// HiddenFactory exists so Isolate can privately inherit from it without making
|
// HiddenFactory exists so Isolate can privately inherit from it without making
|
||||||
// Factory's members available to Isolate directly.
|
// Factory's members available to Isolate directly.
|
||||||
|
|
32
deps/v8/src/heap/base/asm/arm64/push_registers_masm.S
vendored
Normal file
32
deps/v8/src/heap/base/asm/arm64/push_registers_masm.S
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
; Copyright 2020 the V8 project authors. All rights reserved.
|
||||||
|
; Use of this source code is governed by a BSD-style license that can be
|
||||||
|
; found in the LICENSE file.
|
||||||
|
|
||||||
|
; This file is exactly the same as push_registers_asm.cc, just formatted for
|
||||||
|
; the Microsoft Arm Assembler.
|
||||||
|
|
||||||
|
AREA |.text|, CODE, ALIGN=4, READONLY
|
||||||
|
EXPORT PushAllRegistersAndIterateStack
|
||||||
|
PushAllRegistersAndIterateStack
|
||||||
|
; x19-x29 are callee-saved
|
||||||
|
STP x19, x20, [sp, #-16]!
|
||||||
|
STP x21, x22, [sp, #-16]!
|
||||||
|
STP x23, x24, [sp, #-16]!
|
||||||
|
STP x25, x26, [sp, #-16]!
|
||||||
|
STP x27, x28, [sp, #-16]!
|
||||||
|
STP fp, lr, [sp, #-16]!
|
||||||
|
; Maintain frame pointer
|
||||||
|
MOV fp, sp
|
||||||
|
; Pass 1st parameter (x0) unchanged (Stack*).
|
||||||
|
; Pass 2nd parameter (x1) unchanged (StackVisitor*).
|
||||||
|
; Save 3rd parameter (x2; IterateStackCallback)
|
||||||
|
MOV x7, x2
|
||||||
|
; Pass 3rd parameter as sp (stack pointer)
|
||||||
|
MOV x2, sp
|
||||||
|
BLR x7
|
||||||
|
; Load return address
|
||||||
|
LDR lr, [sp, #8]
|
||||||
|
; Restore frame pointer and pop all callee-saved registers.
|
||||||
|
LDR fp, [sp], #96
|
||||||
|
RET
|
||||||
|
END
|
4
deps/v8/src/heap/local-heap.h
vendored
4
deps/v8/src/heap/local-heap.h
vendored
|
@ -33,10 +33,14 @@ class MarkingBarrier;
|
||||||
class MutablePageMetadata;
|
class MutablePageMetadata;
|
||||||
class Safepoint;
|
class Safepoint;
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
extern thread_local LocalHeap* g_current_local_heap_ V8_CONSTINIT;
|
||||||
|
#else
|
||||||
// Do not use this variable directly, use LocalHeap::Current() instead.
|
// Do not use this variable directly, use LocalHeap::Current() instead.
|
||||||
// Defined outside of LocalHeap because LocalHeap uses V8_EXPORT_PRIVATE.
|
// Defined outside of LocalHeap because LocalHeap uses V8_EXPORT_PRIVATE.
|
||||||
__attribute__((tls_model(V8_TLS_MODEL))) extern thread_local LocalHeap*
|
__attribute__((tls_model(V8_TLS_MODEL))) extern thread_local LocalHeap*
|
||||||
g_current_local_heap_ V8_CONSTINIT;
|
g_current_local_heap_ V8_CONSTINIT;
|
||||||
|
#endif // defined(_MSC_VER)
|
||||||
|
|
||||||
// LocalHeap is used by the GC to track all threads with heap access in order to
|
// LocalHeap is used by the GC to track all threads with heap access in order to
|
||||||
// stop them before performing a collection. LocalHeaps can be either Parked or
|
// stop them before performing a collection. LocalHeaps can be either Parked or
|
||||||
|
|
12
deps/v8/src/maglev/maglev-graph-builder.cc
vendored
12
deps/v8/src/maglev/maglev-graph-builder.cc
vendored
|
@ -11003,13 +11003,19 @@ MaybeReduceResult MaglevGraphBuilder::TryReduceCallForNewClosure(
|
||||||
return BuildCallRuntime(Runtime::kThrowConstructorNonCallableError,
|
return BuildCallRuntime(Runtime::kThrowConstructorNonCallableError,
|
||||||
{target_node});
|
{target_node});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef V8_ENABLE_LEAPTIERING
|
||||||
|
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
|
||||||
|
target_context, target_node,
|
||||||
|
GetRootConstant(RootIndex::kUndefinedValue),
|
||||||
|
dispatch_handle,
|
||||||
|
shared, feedback_cell, args, feedback_source));
|
||||||
|
#else
|
||||||
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
|
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
|
||||||
target_context, target_node,
|
target_context, target_node,
|
||||||
GetRootConstant(RootIndex::kUndefinedValue),
|
GetRootConstant(RootIndex::kUndefinedValue),
|
||||||
#ifdef V8_ENABLE_LEAPTIERING
|
|
||||||
dispatch_handle,
|
|
||||||
#endif
|
|
||||||
shared, feedback_cell, args, feedback_source));
|
shared, feedback_cell, args, feedback_source));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return BuildGenericCall(target_node, Call::TargetType::kJSFunction, args);
|
return BuildGenericCall(target_node, Call::TargetType::kJSFunction, args);
|
||||||
}
|
}
|
||||||
|
|
4
deps/v8/src/objects/instance-type-inl.h
vendored
4
deps/v8/src/objects/instance-type-inl.h
vendored
|
@ -42,13 +42,13 @@ HEAP_OBJECT_TYPE_LIST(DECL_TYPE)
|
||||||
// Instance types which are associated with one unique map.
|
// Instance types which are associated with one unique map.
|
||||||
|
|
||||||
template <class type>
|
template <class type>
|
||||||
V8_INLINE consteval std::optional<RootIndex> UniqueMapOfInstanceTypeCheck() {
|
V8_INLINE constexpr std::optional<RootIndex> UniqueMapOfInstanceTypeCheck() {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INSTANCE_TYPE_MAP(V, rootIndexName, rootAccessorName, class_name) \
|
#define INSTANCE_TYPE_MAP(V, rootIndexName, rootAccessorName, class_name) \
|
||||||
template <> \
|
template <> \
|
||||||
V8_INLINE consteval std::optional<RootIndex> \
|
V8_INLINE constexpr std::optional<RootIndex> \
|
||||||
UniqueMapOfInstanceTypeCheck<InstanceTypeTraits::class_name>() { \
|
UniqueMapOfInstanceTypeCheck<InstanceTypeTraits::class_name>() { \
|
||||||
return {RootIndex::k##rootIndexName}; \
|
return {RootIndex::k##rootIndexName}; \
|
||||||
}
|
}
|
||||||
|
|
2
deps/v8/src/objects/tagged-field.h
vendored
2
deps/v8/src/objects/tagged-field.h
vendored
|
@ -121,12 +121,10 @@ static_assert(sizeof(UnalignedDoubleMember) == sizeof(double));
|
||||||
#define FLEXIBLE_ARRAY_MEMBER(Type, name) \
|
#define FLEXIBLE_ARRAY_MEMBER(Type, name) \
|
||||||
using FlexibleDataReturnType = Type[0]; \
|
using FlexibleDataReturnType = Type[0]; \
|
||||||
FlexibleDataReturnType& name() { \
|
FlexibleDataReturnType& name() { \
|
||||||
static_assert(alignof(Type) <= alignof(decltype(*this))); \
|
|
||||||
using ReturnType = Type[0]; \
|
using ReturnType = Type[0]; \
|
||||||
return reinterpret_cast<ReturnType&>(*(this + 1)); \
|
return reinterpret_cast<ReturnType&>(*(this + 1)); \
|
||||||
} \
|
} \
|
||||||
const FlexibleDataReturnType& name() const { \
|
const FlexibleDataReturnType& name() const { \
|
||||||
static_assert(alignof(Type) <= alignof(decltype(*this))); \
|
|
||||||
using ReturnType = Type[0]; \
|
using ReturnType = Type[0]; \
|
||||||
return reinterpret_cast<const ReturnType&>(*(this + 1)); \
|
return reinterpret_cast<const ReturnType&>(*(this + 1)); \
|
||||||
} \
|
} \
|
||||||
|
|
4
deps/v8/src/runtime/runtime-test.cc
vendored
4
deps/v8/src/runtime/runtime-test.cc
vendored
|
@ -1204,8 +1204,8 @@ RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
int FixedArrayLenFromSize(int size) {
|
int FixedArrayLenFromSize(int size) {
|
||||||
return std::min({(size - OFFSET_OF_DATA_START(FixedArray)) / kTaggedSize,
|
return std::min<int>((size - OFFSET_OF_DATA_START(FixedArray)) / kTaggedSize,
|
||||||
FixedArray::kMaxRegularLength});
|
static_cast<int>(FixedArray::kMaxRegularLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillUpOneNewSpacePage(Isolate* isolate, Heap* heap,
|
void FillUpOneNewSpacePage(Isolate* isolate, Heap* heap,
|
||||||
|
|
10
deps/v8/src/wasm/wasm-objects.cc
vendored
10
deps/v8/src/wasm/wasm-objects.cc
vendored
|
@ -3009,15 +3009,21 @@ DirectHandle<WasmExportedFunction> WasmExportedFunction::New(
|
||||||
DirectHandle<WasmFuncRef> func_ref,
|
DirectHandle<WasmFuncRef> func_ref,
|
||||||
DirectHandle<WasmInternalFunction> internal_function, int arity,
|
DirectHandle<WasmInternalFunction> internal_function, int arity,
|
||||||
DirectHandle<Code> export_wrapper) {
|
DirectHandle<Code> export_wrapper) {
|
||||||
|
#if V8_ENABLE_DRUMBRAKE
|
||||||
DCHECK(CodeKind::JS_TO_WASM_FUNCTION == export_wrapper->kind() ||
|
DCHECK(CodeKind::JS_TO_WASM_FUNCTION == export_wrapper->kind() ||
|
||||||
(export_wrapper->is_builtin() &&
|
(export_wrapper->is_builtin() &&
|
||||||
(export_wrapper->builtin_id() == Builtin::kJSToWasmWrapper ||
|
(export_wrapper->builtin_id() == Builtin::kJSToWasmWrapper ||
|
||||||
#if V8_ENABLE_DRUMBRAKE
|
|
||||||
export_wrapper->builtin_id() ==
|
export_wrapper->builtin_id() ==
|
||||||
Builtin::kGenericJSToWasmInterpreterWrapper ||
|
Builtin::kGenericJSToWasmInterpreterWrapper ||
|
||||||
#endif // V8_ENABLE_DRUMBRAKE
|
|
||||||
export_wrapper->builtin_id() == Builtin::kWasmPromising ||
|
export_wrapper->builtin_id() == Builtin::kWasmPromising ||
|
||||||
export_wrapper->builtin_id() == Builtin::kWasmStressSwitch)));
|
export_wrapper->builtin_id() == Builtin::kWasmStressSwitch)));
|
||||||
|
#else
|
||||||
|
DCHECK(CodeKind::JS_TO_WASM_FUNCTION == export_wrapper->kind() ||
|
||||||
|
(export_wrapper->is_builtin() &&
|
||||||
|
(export_wrapper->builtin_id() == Builtin::kJSToWasmWrapper ||
|
||||||
|
export_wrapper->builtin_id() == Builtin::kWasmPromising ||
|
||||||
|
export_wrapper->builtin_id() == Builtin::kWasmStressSwitch)));
|
||||||
|
#endif // V8_ENABLE_DRUMBRAKE
|
||||||
int func_index = internal_function->function_index();
|
int func_index = internal_function->function_index();
|
||||||
Factory* factory = isolate->factory();
|
Factory* factory = isolate->factory();
|
||||||
DirectHandle<Map> rtt;
|
DirectHandle<Map> rtt;
|
||||||
|
|
9
deps/v8/third_party/rapidhash-v8/rapidhash.h
vendored
9
deps/v8/third_party/rapidhash-v8/rapidhash.h
vendored
|
@ -153,8 +153,13 @@ struct PlainHashReader {
|
||||||
/*
|
/*
|
||||||
* Likely and unlikely macros.
|
* Likely and unlikely macros.
|
||||||
*/
|
*/
|
||||||
#define _likely_(x) __builtin_expect(x, 1)
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
#define _unlikely_(x) __builtin_expect(x, 0)
|
#define _likely_(x) (x)
|
||||||
|
#define _unlikely_(x) (x)
|
||||||
|
#else
|
||||||
|
#define _likely_(x) __builtin_expect(x, 1)
|
||||||
|
#define _unlikely_(x) __builtin_expect(x, 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default seed.
|
* Default seed.
|
||||||
|
|
14
test/addons/esm-export/binding.gyp
Normal file
14
test/addons/esm-export/binding.gyp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
'targets': [
|
||||||
|
{
|
||||||
|
'target_name': 'binding-export-default',
|
||||||
|
'sources': [ 'binding-export-default.cc' ],
|
||||||
|
'includes': ['../common.gypi'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'target_name': 'binding-export-primitive',
|
||||||
|
'sources': [ 'binding-export-primitive.cc' ],
|
||||||
|
'includes': ['../common.gypi'],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
37
test/addons/esm-export/test-esm.mjs
Normal file
37
test/addons/esm-export/test-esm.mjs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* This file is supposed to be loaded by `test-import.js` and `test-require.js`
|
||||||
|
* to verify that `import('*.node')` is working properly either been loaded with
|
||||||
|
* the ESM loader or the CJS loader.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { buildType } from '../../common/index.mjs';
|
||||||
|
import assert from 'node:assert';
|
||||||
|
import { createRequire } from 'node:module';
|
||||||
|
import { pathToFileURL } from 'node:url';
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
|
export async function run() {
|
||||||
|
// binding-export-default.node
|
||||||
|
{
|
||||||
|
const bindingPath = require.resolve(`./build/${buildType}/binding-export-default.node`);
|
||||||
|
// Test with order of require+import
|
||||||
|
const bindingRequire = require(bindingPath);
|
||||||
|
const ns = await import(pathToFileURL(bindingPath));
|
||||||
|
assert.strictEqual(ns.default, bindingRequire);
|
||||||
|
|
||||||
|
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
|
||||||
|
assert.strictEqual(ns.default, ns['module.exports']);
|
||||||
|
assert.strictEqual(ns.default.default(), 'hello world');
|
||||||
|
}
|
||||||
|
|
||||||
|
// binding-export-primitive.node
|
||||||
|
{
|
||||||
|
const bindingPath = require.resolve(`./build/${buildType}/binding-export-primitive.node`);
|
||||||
|
const ns = await import(pathToFileURL(bindingPath));
|
||||||
|
|
||||||
|
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
|
||||||
|
assert.strictEqual(ns.default, ns['module.exports']);
|
||||||
|
assert.strictEqual(ns.default, 'hello world');
|
||||||
|
}
|
||||||
|
}
|
6
test/addons/esm-export/test-require.js
Normal file
6
test/addons/esm-export/test-require.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// Flags: --experimental-addon-modules
|
||||||
|
'use strict';
|
||||||
|
const common = require('../../common');
|
||||||
|
|
||||||
|
require('./test-esm.mjs')
|
||||||
|
.run().then(common.mustCall());
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
'variables': {
|
'variables': {
|
||||||
'source_dir': '<!(<(python) -c "import os; print(os.getcwd())")',
|
'source_dir': '<!("<(python)" -c "import os; print(os.getcwd())")',
|
||||||
},
|
},
|
||||||
'targets': [
|
'targets': [
|
||||||
{
|
{
|
||||||
|
@ -8,16 +8,6 @@
|
||||||
'sources': [ 'binding.cc' ],
|
'sources': [ 'binding.cc' ],
|
||||||
'includes': ['../common.gypi'],
|
'includes': ['../common.gypi'],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
'target_name': 'binding-export-default',
|
|
||||||
'sources': [ 'binding-export-default.cc' ],
|
|
||||||
'includes': ['../common.gypi'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'target_name': 'binding-export-primitive',
|
|
||||||
'sources': [ 'binding-export-primitive.cc' ],
|
|
||||||
'includes': ['../common.gypi'],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
'target_name': 'node_modules',
|
'target_name': 'node_modules',
|
||||||
'type': 'none',
|
'type': 'none',
|
||||||
|
|
|
@ -31,27 +31,4 @@ export async function run() {
|
||||||
assert.strictEqual(rebinding.hello(), 'world');
|
assert.strictEqual(rebinding.hello(), 'world');
|
||||||
assert.strictEqual(binding.hello, rebinding.hello);
|
assert.strictEqual(binding.hello, rebinding.hello);
|
||||||
}
|
}
|
||||||
|
|
||||||
// binding-export-default.node
|
|
||||||
{
|
|
||||||
const bindingPath = require.resolve(`./build/${buildType}/binding-export-default.node`);
|
|
||||||
// Test with order of require+import
|
|
||||||
const bindingRequire = require(bindingPath);
|
|
||||||
const ns = await import(pathToFileURL(bindingPath));
|
|
||||||
assert.strictEqual(ns.default, bindingRequire);
|
|
||||||
|
|
||||||
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
|
|
||||||
assert.strictEqual(ns.default, ns['module.exports']);
|
|
||||||
assert.strictEqual(ns.default.default(), 'hello world');
|
|
||||||
}
|
|
||||||
|
|
||||||
// binding-export-primitive.node
|
|
||||||
{
|
|
||||||
const bindingPath = require.resolve(`./build/${buildType}/binding-export-primitive.node`);
|
|
||||||
const ns = await import(pathToFileURL(bindingPath));
|
|
||||||
|
|
||||||
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
|
|
||||||
assert.strictEqual(ns.default, ns['module.exports']);
|
|
||||||
assert.strictEqual(ns.default, 'hello world');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue