Skip to content

Commit f7bcf68

Browse files
committed
Disable dynamic import and put it behind the flag.
The host work is still pending so instead of showing this as a broken feature, it will be displayed as not supported feature.
1 parent 739cde3 commit f7bcf68

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

bin/NativeTests/JsRTApiTest.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,7 @@ namespace JsRTApiTest
20632063
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, ReentrantParseModuleTest);
20642064
}
20652065

2066+
20662067
ModuleResponseData reentrantNoErrorParseData;
20672068
static JsErrorCode CALLBACK reentrantNoErrorParse_FIMC(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
20682069
{
@@ -2131,6 +2132,49 @@ namespace JsRTApiTest
21312132
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, ReentrantNoErrorParseModuleTest);
21322133
}
21332134

2135+
static JsErrorCode CALLBACK FIMC1(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
2136+
{
2137+
JsModuleRecord moduleRecord = JS_INVALID_REFERENCE;
2138+
LPCWSTR specifierStr;
2139+
size_t length;
2140+
JsErrorCode errorCode = JsStringToPointer(specifier, &specifierStr, &length);
2141+
REQUIRE(errorCode == JsNoError);
2142+
2143+
if (wcscmp(specifierStr, _u("foo.js")) == 0)
2144+
{
2145+
errorCode = JsInitializeModuleRecord(referencingModule, specifier, &moduleRecord);
2146+
REQUIRE(errorCode == JsNoError);
2147+
*dependentModuleRecord = moduleRecord;
2148+
}
2149+
return JsNoError;
2150+
}
2151+
2152+
static JsErrorCode CALLBACK NMRC1(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar)
2153+
{
2154+
// NotifyModuleReadyCallback handling.
2155+
2156+
return JsNoError;
2157+
}
2158+
2159+
void SomebugTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
2160+
{
2161+
JsModuleRecord rec;
2162+
JsInitializeModuleRecord(nullptr, nullptr, &rec);
2163+
JsSetModuleHostInfo(rec, JsModuleHostInfo_FetchImportedModuleCallback, FIMC1);
2164+
JsSetModuleHostInfo(rec, JsModuleHostInfo_FetchImportedModuleFromScriptCallback, FIMC1);
2165+
JsSetModuleHostInfo(rec, JsModuleHostInfo_NotifyModuleReadyCallback, NMRC1);
2166+
2167+
JsValueRef F = JS_INVALID_REFERENCE;
2168+
JsErrorCode err = JsRunScript(_u("var j = import('foo.js').then(mod => { mod.bar(); })"), 0, _u(""), &F);
2169+
2170+
CHECK(err == JsNoError);
2171+
}
2172+
2173+
TEST_CASE("ApiTest_SomebugTest", "[ApiTest]")
2174+
{
2175+
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, SomebugTest);
2176+
2177+
}
21342178
void ObjectHasOwnPropertyMethodTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
21352179
{
21362180
JsValueRef proto = JS_INVALID_REFERENCE;

lib/Common/ConfigFlagsList.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ PHASE(All)
604604
#define DEFAULT_CONFIG_ES7TrailingComma (true)
605605
#define DEFAULT_CONFIG_ES7ValuesEntries (true)
606606
#define DEFAULT_CONFIG_ESObjectGetOwnPropertyDescriptors (true)
607+
#define DEFAULT_CONFIG_ESDynamicImport (false)
607608

608609
#define DEFAULT_CONFIG_ESSharedArrayBuffer (true)
609610

@@ -1037,6 +1038,11 @@ FLAGPR (Boolean, ES6, ES7TrailingComma , "Enable ES7 trailing co
10371038
FLAGPR (Boolean, ES6, ES6IsConcatSpreadable , "Enable ES6 isConcatSpreadable Symbol" , DEFAULT_CONFIG_ES6IsConcatSpreadable)
10381039
FLAGPR (Boolean, ES6, ES6Math , "Enable ES6 Math extensions" , DEFAULT_CONFIG_ES6Math)
10391040

1041+
#ifndef COMPILE_DISABLE_ESDynamicImport
1042+
#define COMPILE_DISABLE_ESDynamicImport 0
1043+
#endif
1044+
FLAGPR_REGOVR_EXP(Boolean, ES6, ESDynamicImport , "Enable dynamic import" , DEFAULT_CONFIG_ESDynamicImport)
1045+
10401046
FLAGPR (Boolean, ES6, ES6Module , "Enable ES6 Modules" , DEFAULT_CONFIG_ES6Module)
10411047
FLAGPR (Boolean, ES6, ES6Object , "Enable ES6 Object extensions" , DEFAULT_CONFIG_ES6Object)
10421048
FLAGPR (Boolean, ES6, ES6Number , "Enable ES6 Number extensions" , DEFAULT_CONFIG_ES6Number)

lib/Parser/Parse.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,11 @@ ParseNodePtr Parser::ParseImport()
26462646
// import()
26472647
if (m_token.tk == tkLParen)
26482648
{
2649+
if (!m_scriptContext->GetConfig()->IsESDynamicImportEnabled())
2650+
{
2651+
Error(ERRsyntax);
2652+
}
2653+
26492654
ParseNodePtr pnode = ParseImportCall<buildAST>();
26502655
BOOL fCanAssign;
26512656
IdentToken token;
@@ -3522,7 +3527,7 @@ LFunction :
35223527
break;
35233528

35243529
case tkIMPORT:
3525-
if (m_scriptContext->GetConfig()->IsES6ModuleEnabled())
3530+
if (m_scriptContext->GetConfig()->IsES6ModuleEnabled() && m_scriptContext->GetConfig()->IsESDynamicImportEnabled())
35263531
{
35273532
m_pscan->Scan();
35283533
ChkCurTokNoScan(tkLParen, ERRnoLparen);

lib/Runtime/Base/ThreadConfigFlagsList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ FLAG_RELEASE(SkipSplitOnNoResult, SkipSplitOnNoResult)
4646
FLAG_RELEASE(IsES7AsyncAndAwaitEnabled, ES7AsyncAwait)
4747
FLAG_RELEASE(IsESObjectGetOwnPropertyDescriptorsEnabled, ESObjectGetOwnPropertyDescriptors)
4848
FLAG_RELEASE(IsESSharedArrayBufferEnabled, ESSharedArrayBuffer)
49+
FLAG_RELEASE(IsESDynamicImportEnabled, ESDynamicImport)
4950
#ifdef ENABLE_PROJECTION
5051
FLAG(AreWinRTDelegatesInterfaces, WinRTDelegateInterfaces)
5152
FLAG_RELEASE(IsWinRTAdaptiveAppsEnabled, WinRTAdaptiveApps)

test/es6/rlexe.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,14 +1366,14 @@
13661366
<test>
13671367
<default>
13681368
<files>dynamic-module-functionality.js</files>
1369-
<compile-flags>-ES6Module -args summary -endargs</compile-flags>
1369+
<compile-flags>-ES6Module -ESDynamicImport -args summary -endargs</compile-flags>
13701370
<tags>exclude_sanitize_address</tags>
13711371
</default>
13721372
</test>
13731373
<test>
13741374
<default>
13751375
<files>dynamic-module-import-specifier.js</files>
1376-
<compile-flags>-MuteHostErrorMsg -ES6Module -args summary -endargs</compile-flags>
1376+
<compile-flags>-MuteHostErrorMsg -ESDynamicImport -ES6Module -args summary -endargs</compile-flags>
13771377
<tags>exclude_sanitize_address</tags>
13781378
</default>
13791379
</test>
@@ -1410,7 +1410,7 @@
14101410
<test>
14111411
<default>
14121412
<files>bug_OS12095746.js</files>
1413-
<compile-flags>-MuteHostErrorMsg -IgnoreScriptErrorCode -TraceHostCallback -ES6Module</compile-flags>
1413+
<compile-flags>-MuteHostErrorMsg -IgnoreScriptErrorCode -TraceHostCallback -ES6Module -ESDynamicImport</compile-flags>
14141414
<tags>exclude_dynapogo,exclude_sanitize_address,bugfix,exclude_drt</tags>
14151415
<baseline>bug_OS12095746.baseline</baseline>
14161416
</default>
@@ -1459,7 +1459,7 @@
14591459
<test>
14601460
<default>
14611461
<files>bug_issue_3076.js</files>
1462-
<compile-flags>-force:deferparse</compile-flags>
1462+
<compile-flags>-force:deferparse -ESDynamicImport </compile-flags>
14631463
<tags>BugFix,exclude_sanitize_address</tags>
14641464
</default>
14651465
</test>

0 commit comments

Comments
 (0)