-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathModuleBinding.cpp
More file actions
101 lines (79 loc) · 2.92 KB
/
ModuleBinding.cpp
File metadata and controls
101 lines (79 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// ModuleBinding.cpp
// NativeScript
//
// Created by Eduardo Speroni on 5/11/23.
// Copyright © 2023 Progress. All rights reserved.
//
#include "ModuleBinding.hpp"
// TODO: add here
//#define NSC_BUILTIN_STANDARD_BINDINGS(V) \
//V(fs)
#define NSC_BUILTIN_STANDARD_BINDINGS(V)
#define NSC_BUILTIN_BINDINGS(V) \
NSC_BUILTIN_STANDARD_BINDINGS(V)
// This is used to load built-in bindings. Instead of using
// __attribute__((constructor)), we call the _register_<modname>
// function for each built-in bindings explicitly in
// binding::RegisterBuiltinBindings(). This is only forward declaration.
// The definitions are in each binding's implementation when calling
// the NODE_BINDING_CONTEXT_AWARE_INTERNAL.
#define V(modname) void _register_##modname();
NSC_BUILTIN_BINDINGS(V)
#undef V
#define V(modname) \
void _register_isolate_##modname(v8::Isolate* isolate, \
v8::Local<v8::FunctionTemplate> target);
NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V)
#undef V
using v8::Context;
using v8::EscapableHandleScope;
using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
namespace tns {
// Globals per process
static ns_module* modlist_internal;
static ns_module* modlist_linked;
static thread_local ns_module* thread_local_modpending;
bool node_is_initialized = false;
extern "C" void nativescript_module_register(void* m) {
struct ns_module* mp = reinterpret_cast<struct ns_module*>(m);
if (mp->nm_flags & NM_F_INTERNAL) {
mp->nm_link = modlist_internal;
modlist_internal = mp;
} else if (!node_is_initialized) {
// "Linked" modules are included as part of the node project.
// Like builtins they are registered *before* node::Init runs.
mp->nm_flags = NM_F_LINKED;
mp->nm_link = modlist_linked;
modlist_linked = mp;
} else {
thread_local_modpending = mp;
}
}
namespace binding {
void RegisterBuiltinBindings() {
#define V(modname) _register_##modname();
NSC_BUILTIN_BINDINGS(V)
#undef V
}
void CreateInternalBindingTemplates(v8::Isolate* isolate, Local<FunctionTemplate> templ) {
#define V(modname) \
do { \
/*templ->InstanceTemplate()->SetInternalFieldCount( \
BaseObject::kInternalFieldCount);*/ \
_register_isolate_##modname(isolate, templ); \
/*isolate_data->set_##modname##_binding(templ);*/ \
} while (0);
NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V)
#undef V
}
};
};