Skip to content

Commit

Permalink
Forward execution context to wrapped bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ndisidore committed Oct 5, 2023
1 parent 1d9158a commit b31141c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,22 @@ static v8::Local<v8::Value> createBindingValue(
createBindingValue(lock, innerBinding, featureFlags, ownerId));
}

// build an execution context object for information about the wider Worker
auto executionContext = v8::Object::New(lock.v8Isolate);
// corral feature flags into object that can be passed
capnp::JsonCodec jsonCodec;
jsonCodec.handleByAnnotation<CompatibilityFlags>();
jsonCodec.setPrettyPrint(false);
kj::String compatibilityFlagsJson = jsonCodec.encode(featureFlags);
lock.v8Set(executionContext, "compatibilityFlags", lock.parseJson(compatibilityFlagsJson).getHandle(lock));

// obtain exported function to call
auto moduleNs = jsg::check(module->GetModuleNamespace()->ToObject(context));
auto fn = lock.v8Get(moduleNs, wrapped.entrypoint);
KJ_ASSERT(fn->IsFunction(), "Entrypoint is not a function", wrapped.entrypoint);

// invoke the function, its result will be binding value
auto args = kj::arr(env.As<v8::Value>());
auto args = kj::arr(env.As<v8::Value>(), executionContext.As<v8::Value>());
value = jsg::check(v8::Function::Cast(*fn)-> Call(context, context->Global(),
args.size(), args.begin()));
} else {
Expand Down

0 comments on commit b31141c

Please sign in to comment.