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> process,
|
||||||
v8::Local<v8::Value> require) {
|
v8::Local<v8::Value> require) {
|
||||||
// Evaluate asar_init.js.
|
// Evaluate asar_init.js.
|
||||||
const char* asar_init_native = reinterpret_cast<const char*>(
|
v8::Local<v8::Script> asar_init =
|
||||||
static_cast<const unsigned char*>(node::asar_init_data));
|
v8::Script::Compile(node::asar_init_value.ToStringChecked(isolate));
|
||||||
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::Value> result = asar_init->Run();
|
v8::Local<v8::Value> result = asar_init->Run();
|
||||||
|
|
||||||
// Initialize asar support.
|
// Initialize asar support.
|
||||||
if (result->IsFunction()) {
|
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[] = {
|
v8::Local<v8::Value> args[] = {
|
||||||
process,
|
process, require, node::asar_value.ToStringChecked(isolate),
|
||||||
require,
|
|
||||||
mate::ConvertToV8(isolate, asar_data),
|
|
||||||
};
|
};
|
||||||
result.As<v8::Function>()->Call(result, 3, args);
|
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
|
// Wrap the bundle into a function that receives the binding object as
|
||||||
// an argument.
|
// an argument.
|
||||||
std::string bundle(node::isolated_bundle_data,
|
std::string left = "(function (binding, require) {\n";
|
||||||
node::isolated_bundle_data + sizeof(node::isolated_bundle_data));
|
std::string right = "\n})";
|
||||||
std::string wrapper = "(function (binding, require) {\n" + bundle + "\n})";
|
auto script = v8::Script::Compile(v8::String::Concat(
|
||||||
auto script = v8::Script::Compile(
|
mate::ConvertToV8(isolate, left)->ToString(),
|
||||||
mate::ConvertToV8(isolate, wrapper)->ToString());
|
v8::String::Concat(node::isolated_bundle_value.ToStringChecked(isolate),
|
||||||
|
mate::ConvertToV8(isolate, right)->ToString())));
|
||||||
auto func = v8::Handle<v8::Function>::Cast(
|
auto func = v8::Handle<v8::Function>::Cast(
|
||||||
script->Run(context).ToLocalChecked());
|
script->Run(context).ToLocalChecked());
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
#include "atom/renderer/atom_sandboxed_renderer_client.h"
|
#include "atom/renderer/atom_sandboxed_renderer_client.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/api/atom_bindings.h"
|
#include "atom/common/api/atom_bindings.h"
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
|
@ -171,16 +169,13 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
|
||||||
v8::Context::Scope context_scope(context);
|
v8::Context::Scope context_scope(context);
|
||||||
// Wrap the bundle into a function that receives the binding object and the
|
// Wrap the bundle into a function that receives the binding object and the
|
||||||
// preload script path as arguments.
|
// preload script path as arguments.
|
||||||
std::string preload_bundle_native(node::preload_bundle_data,
|
std::string left = "(function(binding, preloadPath, require) {\n";
|
||||||
node::preload_bundle_data + sizeof(node::preload_bundle_data));
|
std::string right = "\n})";
|
||||||
std::stringstream ss;
|
|
||||||
ss << "(function(binding, preloadPath, require) {\n";
|
|
||||||
ss << preload_bundle_native << "\n";
|
|
||||||
ss << "})";
|
|
||||||
std::string preload_wrapper = ss.str();
|
|
||||||
// Compile the wrapper and run it to get the function object
|
// Compile the wrapper and run it to get the function object
|
||||||
auto script = v8::Script::Compile(
|
auto script = v8::Script::Compile(v8::String::Concat(
|
||||||
mate::ConvertToV8(isolate, preload_wrapper)->ToString());
|
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(
|
auto func = v8::Handle<v8::Function>::Cast(
|
||||||
script->Run(context).ToLocalChecked());
|
script->Run(context).ToLocalChecked());
|
||||||
// Create and initialize the binding object
|
// Create and initialize the binding object
|
||||||
|
|
|
@ -9,6 +9,19 @@ import sys
|
||||||
|
|
||||||
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
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():
|
def main():
|
||||||
natives = os.path.abspath(sys.argv[1])
|
natives = os.path.abspath(sys.argv[1])
|
||||||
|
@ -23,7 +36,8 @@ def call_js2c(natives, js_source_files):
|
||||||
with scoped_cwd(src_dir):
|
with scoped_cwd(src_dir):
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
[sys.executable, js2c, natives] +
|
[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
|
@contextlib.contextmanager
|
||||||
|
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 584e6370849aa73025e6206109f25f441cb6cf9f
|
Subproject commit 538a5023af0a92ba19de2420a0eada6ad4cd18f6
|
Loading…
Reference in a new issue