GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: set ModuleWrap internal fields only once · nodejs/node@2c2892b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • module_wrap.cc
    • module_wrap.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/module_wrap.cc‎

Copy file name to clipboardExpand all lines: src/module_wrap.cc
+23-17Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,22 @@ using v8::Value;
5252
ModuleWrap::ModuleWrap(Environment* env,
5353
Local<Object> object,
5454
Local<Module> module,
55-
Local<String> url)
56-
: BaseObject(env, object),
57-
module_(env->isolate(), module),
58-
id_(env->get_next_module_id()) {
55+
Local<String> url,
56+
Local<Object> context_object,
57+
Local<Value> synthetic_evaluation_step)
58+
: BaseObject(env, object),
59+
module_(env->isolate(), module),
60+
id_(env->get_next_module_id()) {
5961
env->id_to_module_map.emplace(id_, this);
6062

61-
Local<Value> undefined = Undefined(env->isolate());
6263
object->SetInternalField(kURLSlot, url);
63-
object->SetInternalField(kSyntheticEvaluationStepsSlot, undefined);
64-
object->SetInternalField(kContextObjectSlot, undefined);
64+
object->SetInternalField(kSyntheticEvaluationStepsSlot,
65+
synthetic_evaluation_step);
66+
object->SetInternalField(kContextObjectSlot, context_object);
67+
68+
if (!synthetic_evaluation_step->IsUndefined()) {
69+
synthetic_ = true;
70+
}
6571
}
6672

6773
ModuleWrap::~ModuleWrap() {
@@ -79,7 +85,9 @@ ModuleWrap::~ModuleWrap() {
7985

8086
Local<Context> ModuleWrap::context() const {
8187
Local<Value> obj = object()->GetInternalField(kContextObjectSlot).As<Value>();
82-
if (obj.IsEmpty()) return {};
88+
// If this fails, there is likely a bug e.g. ModuleWrap::context() is accessed
89+
// before the ModuleWrap constructor completes.
90+
CHECK(obj->IsObject());
8391
return obj.As<Object>()->GetCreationContext().ToLocalChecked();
8492
}
8593

@@ -227,18 +235,16 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
227235
return;
228236
}
229237

230-
ModuleWrap* obj = new ModuleWrap(env, that, module, url);
231-
232-
if (synthetic) {
233-
obj->synthetic_ = true;
234-
obj->object()->SetInternalField(kSyntheticEvaluationStepsSlot, args[3]);
235-
}
236-
237238
// Use the extras object as an object whose GetCreationContext() will be the
238239
// original `context`, since the `Context` itself strictly speaking cannot
239240
// be stored in an internal field.
240-
obj->object()->SetInternalField(kContextObjectSlot,
241-
context->GetExtrasBindingObject());
241+
Local<Object> context_object = context->GetExtrasBindingObject();
242+
Local<Value> synthetic_evaluation_step =
243+
synthetic ? args[3] : Undefined(env->isolate()).As<v8::Value>();
244+
245+
ModuleWrap* obj = new ModuleWrap(
246+
env, that, module, url, context_object, synthetic_evaluation_step);
247+
242248
obj->contextify_context_ = contextify_context;
243249

244250
env->hash_to_module_map.emplace(module->GetIdentityHash(), obj);
Collapse file

‎src/module_wrap.h‎

Copy file name to clipboardExpand all lines: src/module_wrap.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class ModuleWrap : public BaseObject {
7272
ModuleWrap(Environment* env,
7373
v8::Local<v8::Object> object,
7474
v8::Local<v8::Module> module,
75-
v8::Local<v8::String> url);
75+
v8::Local<v8::String> url,
76+
v8::Local<v8::Object> context_object,
77+
v8::Local<v8::Value> synthetic_evaluation_step);
7678
~ModuleWrap() override;
7779

7880
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.