src: check import attributes value types as strings · nodejs/node@2178007

@@ -63,6 +63,10 @@ using v8::UnboundModuleScript;

6363

using v8::Undefined;

6464

using v8::Value;

656566+

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,

83878488

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,14 @@ static Local<Object> createImportAttributesContainer(

488495

LocalVector<Value> values(isolate, num_attributes);

489496490497

for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) {

498+

Local<Data> key = raw_attributes->Get(realm->context(), i);

499+

Local<Data> value = raw_attributes->Get(realm->context(), i + 1);

500+

DCHECK(DataIsString(key));

501+

DCHECK(DataIsString(value));

502+491503

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>();

504+

names[idx] = key.As<String>();

505+

values[idx] = value.As<String>();

494506

}

495507496508

Local<Object> attributes = Object::New(

@@ -507,6 +519,7 @@ static Local<Array> createModuleRequestsContainer(

507519

LocalVector<Value> requests(isolate, raw_requests->Length());

508520509521

for (int i = 0; i < raw_requests->Length(); i++) {

522+

DCHECK(raw_requests->Get(context, i)->IsModuleRequest());

510523

Local<ModuleRequest> module_request =

511524

raw_requests->Get(realm->context(), i).As<ModuleRequest>();

512525