Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void ContextifyContext::Init(Environment* env, Local<Object> target) {
env->SetMethod(target, "makeContext", MakeContext);
env->SetMethod(target, "isContext", IsContext);
env->SetMethod(target, "compileFunction", CompileFunction);
env->SetMethod(target, "createCacheForFunction", CreateCacheForFunction);
}


Expand Down Expand Up @@ -1108,6 +1109,26 @@ void ContextifyContext::CompileFunction(
args.GetReturnValue().Set(fun);
}

void ContextifyContext::CreateCacheForFunction(
const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

// Argument 1: target function
Local<Function> function = args[0].As<Function>();

const std::unique_ptr<ScriptCompiler::CachedData> cache(
ScriptCompiler::CreateCodeCacheForFunction(function));

if (cache == nullptr) {
args.GetReturnValue().SetUndefined();
Comment thread
ryzokuken marked this conversation as resolved.
Outdated
} else {
args.GetReturnValue().Set(
Buffer::Copy(
env, reinterpret_cast<const char*>(cache->data), cache->length)
.ToLocalChecked());
}
}


void Initialize(Local<Object> target,
Local<Value> unused,
Expand Down
2 changes: 2 additions & 0 deletions src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ContextifyContext {
static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CompileFunction(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void CreateCacheForFunction(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void WeakCallback(
const v8::WeakCallbackInfo<ContextifyContext>& data);
static void PropertyGetterCallback(
Expand Down