Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2018-04-25 20:22:20 +0300
committerGus Caplan <me@gus.host>2018-06-27 00:38:13 +0300
commit4f67c6f667fa98e25ba311d3459fc8e270407250 (patch)
treedb0b6502b9143103d3bf7151b249068915824426 /src/node_contextify.cc
parenta9d9d7689d326d363c8d9546a80ba76f4cd0decb (diff)
vm: add Script.createCodeCache()
PR-URL: https://github.com/nodejs/node/pull/20300 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org>
Diffstat (limited to 'src/node_contextify.cc')
-rw-r--r--src/node_contextify.cc26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index a8dfce83558..61c686ba001 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -25,6 +25,7 @@
#include "base_object-inl.h"
#include "node_contextify.h"
#include "node_context_data.h"
+#include "node_errors.h"
namespace node {
namespace contextify {
@@ -596,6 +597,7 @@ class ContextifyScript : public BaseObject {
Local<FunctionTemplate> script_tmpl = env->NewFunctionTemplate(New);
script_tmpl->InstanceTemplate()->SetInternalFieldCount(1);
script_tmpl->SetClassName(class_name);
+ env->SetProtoMethod(script_tmpl, "createCachedData", CreateCachedData);
env->SetProtoMethod(script_tmpl, "runInContext", RunInContext);
env->SetProtoMethod(script_tmpl, "runInThisContext", RunInThisContext);
@@ -637,7 +639,7 @@ class ContextifyScript : public BaseObject {
Local<Context> parsing_context = context;
if (argc > 2) {
- // new ContextifyScript(code, filename, lineOffset, columnOffset
+ // new ContextifyScript(code, filename, lineOffset, columnOffset,
// cachedData, produceCachedData, parsingContext)
CHECK_EQ(argc, 7);
CHECK(args[2]->IsNumber());
@@ -719,7 +721,7 @@ class ContextifyScript : public BaseObject {
Boolean::New(isolate, source.GetCachedData()->rejected));
} else if (produce_cached_data) {
const ScriptCompiler::CachedData* cached_data =
- ScriptCompiler::CreateCodeCache(v8_script.ToLocalChecked(), code);
+ ScriptCompiler::CreateCodeCache(v8_script.ToLocalChecked());
bool cached_data_produced = cached_data != nullptr;
if (cached_data_produced) {
MaybeLocal<Object> buf = Buffer::Copy(
@@ -745,6 +747,26 @@ class ContextifyScript : public BaseObject {
}
+ static void CreateCachedData(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ ContextifyScript* wrapped_script;
+ ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.Holder());
+ Local<UnboundScript> unbound_script =
+ PersistentToLocal(env->isolate(), wrapped_script->script_);
+ std::unique_ptr<ScriptCompiler::CachedData> cached_data(
+ ScriptCompiler::CreateCodeCache(unbound_script));
+ if (!cached_data) {
+ args.GetReturnValue().Set(Buffer::New(env, 0).ToLocalChecked());
+ } else {
+ MaybeLocal<Object> buf = Buffer::Copy(
+ env,
+ reinterpret_cast<const char*>(cached_data->data),
+ cached_data->length);
+ args.GetReturnValue().Set(buf.ToLocalChecked());
+ }
+ }
+
+
static void RunInThisContext(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);