Skip to content

Commit 0918ea0

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 158d446 commit 0918ea0

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/api/async_resource.cc

+1-3
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

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ CallbackScope::CallbackScope(Isolate* isolate,
2626
try_catch_.SetVerbose(true);
2727
}
2828

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

src/node.h

+3
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,9 @@ class NODE_EXTERN CallbackScope {
10081008
CallbackScope(v8::Isolate* isolate,
10091009
v8::Local<v8::Object> resource,
10101010
async_context asyncContext);
1011+
CallbackScope(Environment* env,
1012+
v8::Local<v8::Object> resource,
1013+
async_context asyncContext);
10111014
~CallbackScope();
10121015

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

src/node_api.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ class AsyncContext {
539539
class CallbackScope : public node::CallbackScope {
540540
public:
541541
explicit CallbackScope(AsyncContext* async_context)
542-
: node::CallbackScope(async_context->node_env()->isolate(),
542+
: node::CallbackScope(async_context->node_env(),
543543
async_context->resource_.Get(
544544
async_context->node_env()->isolate()),
545545
async_context->async_context()) {}

0 commit comments

Comments
 (0)