tools: pass custom template for js2c (#12593)
* Update node v9.7.0 ref * tools: pass custom template to node/tools/js2c.py
This commit is contained in:
parent
9e5c264012
commit
ad2baccefa
5 changed files with 31 additions and 31 deletions
|
@ -131,24 +131,14 @@ void InitAsarSupport(v8::Isolate* isolate,
|
|||
v8::Local<v8::Value> process,
|
||||
v8::Local<v8::Value> require) {
|
||||
// Evaluate asar_init.js.
|
||||
const char* asar_init_native = reinterpret_cast<const char*>(
|
||||
static_cast<const unsigned char*>(node::asar_init_data));
|
||||
v8::Local<v8::Script> asar_init = v8::Script::Compile(v8::String::NewFromUtf8(
|
||||
isolate,
|
||||
asar_init_native,
|
||||
v8::String::kNormalString,
|
||||
sizeof(node::asar_init_data) -1));
|
||||
v8::Local<v8::Script> asar_init =
|
||||
v8::Script::Compile(node::asar_init_value.ToStringChecked(isolate));
|
||||
v8::Local<v8::Value> result = asar_init->Run();
|
||||
|
||||
// Initialize asar support.
|
||||
if (result->IsFunction()) {
|
||||
const char* asar_native = reinterpret_cast<const char*>(
|
||||
static_cast<const unsigned char*>(node::asar_data));
|
||||
base::StringPiece asar_data(asar_native, sizeof(node::asar_data) - 1);
|
||||
v8::Local<v8::Value> args[] = {
|
||||
process,
|
||||
require,
|
||||
mate::ConvertToV8(isolate, asar_data),
|
||||
process, require, node::asar_value.ToStringChecked(isolate),
|
||||
};
|
||||
result.As<v8::Function>()->Call(result, 3, args);
|
||||
}
|
||||
|
|
|
@ -181,11 +181,12 @@ void AtomRendererClient::SetupMainWorldOverrides(
|
|||
|
||||
// Wrap the bundle into a function that receives the binding object as
|
||||
// an argument.
|
||||
std::string bundle(node::isolated_bundle_data,
|
||||
node::isolated_bundle_data + sizeof(node::isolated_bundle_data));
|
||||
std::string wrapper = "(function (binding, require) {\n" + bundle + "\n})";
|
||||
auto script = v8::Script::Compile(
|
||||
mate::ConvertToV8(isolate, wrapper)->ToString());
|
||||
std::string left = "(function (binding, require) {\n";
|
||||
std::string right = "\n})";
|
||||
auto script = v8::Script::Compile(v8::String::Concat(
|
||||
mate::ConvertToV8(isolate, left)->ToString(),
|
||||
v8::String::Concat(node::isolated_bundle_value.ToStringChecked(isolate),
|
||||
mate::ConvertToV8(isolate, right)->ToString())));
|
||||
auto func = v8::Handle<v8::Function>::Cast(
|
||||
script->Run(context).ToLocalChecked());
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
#include "atom/renderer/atom_sandboxed_renderer_client.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/api/atom_bindings.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
|
@ -171,16 +169,13 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
|
|||
v8::Context::Scope context_scope(context);
|
||||
// Wrap the bundle into a function that receives the binding object and the
|
||||
// preload script path as arguments.
|
||||
std::string preload_bundle_native(node::preload_bundle_data,
|
||||
node::preload_bundle_data + sizeof(node::preload_bundle_data));
|
||||
std::stringstream ss;
|
||||
ss << "(function(binding, preloadPath, require) {\n";
|
||||
ss << preload_bundle_native << "\n";
|
||||
ss << "})";
|
||||
std::string preload_wrapper = ss.str();
|
||||
std::string left = "(function(binding, preloadPath, require) {\n";
|
||||
std::string right = "\n})";
|
||||
// Compile the wrapper and run it to get the function object
|
||||
auto script = v8::Script::Compile(
|
||||
mate::ConvertToV8(isolate, preload_wrapper)->ToString());
|
||||
auto script = v8::Script::Compile(v8::String::Concat(
|
||||
mate::ConvertToV8(isolate, left)->ToString(),
|
||||
v8::String::Concat(node::preload_bundle_value.ToStringChecked(isolate),
|
||||
mate::ConvertToV8(isolate, right)->ToString())));
|
||||
auto func = v8::Handle<v8::Function>::Cast(
|
||||
script->Run(context).ToLocalChecked());
|
||||
// Create and initialize the binding object
|
||||
|
|
|
@ -9,6 +9,19 @@ import sys
|
|||
|
||||
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
TEMPLATE = """
|
||||
#ifndef ATOM_NATIVES_H_
|
||||
#define ATOM_NATIVES_H_
|
||||
|
||||
namespace node {{
|
||||
|
||||
{definitions}
|
||||
|
||||
}} // namespace node
|
||||
|
||||
#endif // ATOM_NATIVES_H_
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
natives = os.path.abspath(sys.argv[1])
|
||||
|
@ -23,7 +36,8 @@ def call_js2c(natives, js_source_files):
|
|||
with scoped_cwd(src_dir):
|
||||
subprocess.check_call(
|
||||
[sys.executable, js2c, natives] +
|
||||
[os.path.basename(source) for source in js_source_files])
|
||||
[os.path.basename(source) for source in js_source_files] +
|
||||
['-t', TEMPLATE])
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 584e6370849aa73025e6206109f25f441cb6cf9f
|
||||
Subproject commit 538a5023af0a92ba19de2420a0eada6ad4cd18f6
|
Loading…
Reference in a new issue