Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: add createCacheForFunction #24069

Closed
wants to merge 4 commits into from
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();
ryzokuken marked this conversation as resolved.
Show resolved Hide resolved
} 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