Skip to content

Commit 1efae01

Browse files
RaisinTentargos
authored andcommitted
src: add a constructor overload for CallbackScope
This overload accepts the current Environment* as an argument, unlike the other constructor, which accepts an Isolate*. This is useful because we can pass the current Environment* directly instead of recomputing it from the Isolate* inside the constructor. Signed-off-by: Darshan Sen <[email protected]> PR-URL: #39768 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 1aa2080 commit 1efae01

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/api/async_resource.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ async_id AsyncResource::get_trigger_async_id() const {
6262
return async_context_.trigger_async_id;
6363
}
6464

65-
// TODO(addaleax): We shouldn’t need to use env_->isolate() if we’re just going
66-
// to end up using the Isolate* to figure out the Environment* again.
6765
AsyncResource::CallbackScope::CallbackScope(AsyncResource* res)
68-
: node::CallbackScope(res->env_->isolate(),
66+
: node::CallbackScope(res->env_,
6967
res->resource_.Get(res->env_->isolate()),
7068
res->async_context_) {}
7169

src/api/callback.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ CallbackScope::CallbackScope(Isolate* isolate,
2727
try_catch_.SetVerbose(true);
2828
}
2929

30+
CallbackScope::CallbackScope(Environment* env,
31+
Local<Object> object,
32+
async_context asyncContext)
33+
: private_(new InternalCallbackScope(env,
34+
object,
35+
asyncContext)),
36+
try_catch_(env->isolate()) {
37+
try_catch_.SetVerbose(true);
38+
}
39+
3040
CallbackScope::~CallbackScope() {
3141
if (try_catch_.HasCaught())
3242
private_->MarkAsFailed();

src/node.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,9 @@ class NODE_EXTERN CallbackScope {
983983
CallbackScope(v8::Isolate* isolate,
984984
v8::Local<v8::Object> resource,
985985
async_context asyncContext);
986+
CallbackScope(Environment* env,
987+
v8::Local<v8::Object> resource,
988+
async_context asyncContext);
986989
~CallbackScope();
987990

988991
void operator=(const CallbackScope&) = delete;

src/node_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class AsyncContext {
553553
class CallbackScope : public node::CallbackScope {
554554
public:
555555
explicit CallbackScope(AsyncContext* async_context)
556-
: node::CallbackScope(async_context->node_env()->isolate(),
556+
: node::CallbackScope(async_context->node_env(),
557557
async_context->resource_.Get(
558558
async_context->node_env()->isolate()),
559559
async_context->async_context()) {}

0 commit comments

Comments
 (0)