mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
Dynamically load native scripts
This commit is contained in:
1 parent
901d5fd0d2
commit
c4636a578c
5 files changed
+67
-26
No files matched your search
+23
-1
@@ -211,13 +211,30 @@ namespace node {
|
||||
|
||||
%(source_lines)s\
|
||||
|
||||
struct _native {
|
||||
const char* name;
|
||||
const char* source;
|
||||
};
|
||||
|
||||
static const struct _native natives[] = {
|
||||
|
||||
%(native_lines)s\
|
||||
|
||||
{ NULL, NULL } /* sentinel */
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
"""
|
||||
|
||||
|
||||
NATIVE_DECLARATION = """\
|
||||
{ "%(id)s", %(id)s_native },
|
||||
"""
|
||||
|
||||
SOURCE_DECLARATION = """\
|
||||
static const char native_%(id)s[] = { %(data)s };
|
||||
const char %(id)s_native[] = { %(data)s };
|
||||
"""
|
||||
|
||||
|
||||
@@ -252,6 +269,9 @@ def JS2C(source, target):
|
||||
# Build source code lines
|
||||
source_lines = [ ]
|
||||
source_lines_empty = []
|
||||
|
||||
native_lines = []
|
||||
|
||||
for s in modules:
|
||||
delay = str(s).endswith('-delay.js')
|
||||
lines = ReadFile(str(s))
|
||||
@@ -269,6 +289,7 @@ def JS2C(source, target):
|
||||
ids.append((id, len(lines)))
|
||||
source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
|
||||
source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': 0 })
|
||||
native_lines.append(NATIVE_DECLARATION % { 'id': id })
|
||||
|
||||
# Build delay support functions
|
||||
get_index_cases = [ ]
|
||||
@@ -312,6 +333,7 @@ def JS2C(source, target):
|
||||
'builtin_count': len(ids) + len(delay_ids),
|
||||
'delay_count': len(delay_ids),
|
||||
'source_lines': "\n".join(source_lines),
|
||||
'native_lines': "\n".join(native_lines),
|
||||
'get_index_cases': "".join(get_index_cases),
|
||||
'get_script_source_cases': "".join(get_script_source_cases),
|
||||
'get_script_name_cases': "".join(get_script_name_cases)
|
||||
|
||||
Reference in new issue
Block a user