Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit96514a8

Browse files
targosrichardlau
authored andcommitted
src: iterate on import attributes array correctly
The array's length is supposed to be a multiple of two for dynamicimport callbacks.Fixes:#50700PR-URL:#50703Backport-PR-URL:#51136Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent06646e1 commit96514a8

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

‎src/module_wrap.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,14 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
250250
}
251251

252252
static Local<Object>createImportAttributesContainer(
253-
Environment* env, Isolate* isolate, Local<FixedArray> raw_attributes) {
253+
Environment* env,
254+
Isolate* isolate,
255+
Local<FixedArray> raw_attributes,
256+
constint elements_per_attribute) {
257+
CHECK_EQ(raw_attributes->Length() % elements_per_attribute,0);
254258
Local<Object> attributes =
255259
Object::New(isolate,v8::Null(env->isolate()),nullptr,nullptr,0);
256-
for (int i =0; i < raw_attributes->Length(); i +=3) {
260+
for (int i =0; i < raw_attributes->Length(); i +=elements_per_attribute) {
257261
attributes
258262
->Set(env->context(),
259263
raw_attributes->Get(env->context(), i).As<String>(),
@@ -299,7 +303,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
299303

300304
Local<FixedArray> raw_attributes = module_request->GetImportAssertions();
301305
Local<Object> attributes =
302-
createImportAttributesContainer(env, isolate, raw_attributes);
306+
createImportAttributesContainer(env, isolate, raw_attributes,3);
303307

304308
Local<Value> argv[] = {
305309
specifier,
@@ -583,7 +587,7 @@ static MaybeLocal<Promise> ImportModuleDynamically(
583587
options->Get(context, HostDefinedOptions::kID).As<Symbol>();
584588

585589
Local<Object> attributes =
586-
createImportAttributesContainer(env, isolate, import_attributes);
590+
createImportAttributesContainer(env, isolate, import_attributes,2);
587591

588592
Local<Value> import_args[] = {
589593
id,

‎test/es-module/test-esm-import-attributes-errors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ async function test() {
2626
{code:'ERR_IMPORT_ASSERTION_TYPE_FAILED'}
2727
);
2828

29+
awaitrejects(
30+
import(jsModuleDataUrl,{with:{type:'json',other:'unsupported'}}),
31+
{code:'ERR_IMPORT_ASSERTION_TYPE_FAILED'}
32+
);
33+
2934
awaitrejects(
3035
import(jsModuleDataUrl,{with:{type:'unsupported'}}),
3136
{code:'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED'}

‎test/es-module/test-esm-import-attributes-errors.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ await rejects(
2121
{code:'ERR_IMPORT_ASSERTION_TYPE_FAILED'}
2222
);
2323

24+
awaitrejects(
25+
import(jsModuleDataUrl,{with:{type:'json',other:'unsupported'}}),
26+
{code:'ERR_IMPORT_ASSERTION_TYPE_FAILED'}
27+
);
28+
2429
awaitrejects(
2530
import(import.meta.url,{with:{type:'unsupported'}}),
2631
{code:'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED'}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp