Skip to content

Commit 649352e

Browse files
committed
src: check import attributes value types as strings
1 parent f5da8f8 commit 649352e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/module_wrap.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ using v8::UnboundModuleScript;
6363
using v8::Undefined;
6464
using v8::Value;
6565

66+
inline bool DataIsString(Local<Data> data) {
67+
return data->IsValue() && data.As<Value>()->IsString();
68+
}
69+
6670
void ModuleCacheKey::MemoryInfo(MemoryTracker* tracker) const {
6771
tracker->TrackField("specifier", specifier);
6872
tracker->TrackField("import_attributes", import_attributes);
@@ -83,6 +87,9 @@ ModuleCacheKey ModuleCacheKey::From(Local<Context> context,
8387

8488
for (int i = 0; i < import_attributes->Length();
8589
i += elements_per_attribute) {
90+
DCHECK(DataIsString(import_attributes->Get(context, i)));
91+
DCHECK(DataIsString(import_attributes->Get(context, i + 1)));
92+
8693
Local<String> v8_key = import_attributes->Get(context, i).As<String>();
8794
Local<String> v8_value =
8895
import_attributes->Get(context, i + 1).As<String>();
@@ -488,9 +495,12 @@ static Local<Object> createImportAttributesContainer(
488495
LocalVector<Value> values(isolate, num_attributes);
489496

490497
for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) {
498+
DCHECK(DataIsString(raw_attributes->Get(context, i)));
499+
DCHECK(DataIsString(raw_attributes->Get(context, i + 1)));
500+
491501
int idx = i / elements_per_attribute;
492-
names[idx] = raw_attributes->Get(realm->context(), i).As<Name>();
493-
values[idx] = raw_attributes->Get(realm->context(), i + 1).As<Value>();
502+
names[idx] = raw_attributes->Get(realm->context(), i).As<String>();
503+
values[idx] = raw_attributes->Get(realm->context(), i + 1).As<String>();
494504
}
495505

496506
Local<Object> attributes = Object::New(
@@ -507,6 +517,7 @@ static Local<Array> createModuleRequestsContainer(
507517
LocalVector<Value> requests(isolate, raw_requests->Length());
508518

509519
for (int i = 0; i < raw_requests->Length(); i++) {
520+
DCHECK(raw_requests->Get(context, i)->IsModuleRequest());
510521
Local<ModuleRequest> module_request =
511522
raw_requests->Get(realm->context(), i).As<ModuleRequest>();
512523

0 commit comments

Comments
 (0)