Diff
Modified: trunk/JSTests/ChangeLog (270922 => 270923)
--- trunk/JSTests/ChangeLog 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/JSTests/ChangeLog 2020-12-17 02:46:48 UTC (rev 270923)
@@ -1,3 +1,17 @@
+2020-12-15 Yusuke Suzuki <[email protected]>
+
+ [JSC] Accept arbitrary module namespace identifier names
+ https://bugs.webkit.org/show_bug.cgi?id=217576
+ <rdar://problem/70416104>
+
+ Reviewed by Darin Adler.
+
+ * modules/arbitrary-module-names.js: Added.
+ * modules/arbitrary-module-names/export.js: Added.
+ * modules/arbitrary-module-names/export2.js: Added.
+ * stress/modules-syntax-error.js:
+ * test262/config.yaml:
+
2020-12-15 Alexey Shvayka <[email protected]>
Non-enumerable property fails to shadow inherited enumerable property from for-in
Added: trunk/JSTests/modules/arbitrary-module-names/export.js (0 => 270923)
--- trunk/JSTests/modules/arbitrary-module-names/export.js (rev 0)
+++ trunk/JSTests/modules/arbitrary-module-names/export.js 2020-12-17 02:46:48 UTC (rev 270923)
@@ -0,0 +1,8 @@
+var deleting = 42;
+
+export {
+ deleting as "delete"
+};
+export * as "var" from "./export2.js";
+export { "if" } from "./export2.js";
+export { "else" as "ok2" } from "./export2.js";
Added: trunk/JSTests/modules/arbitrary-module-names/export2.js (0 => 270923)
--- trunk/JSTests/modules/arbitrary-module-names/export2.js (rev 0)
+++ trunk/JSTests/modules/arbitrary-module-names/export2.js 2020-12-17 02:46:48 UTC (rev 270923)
@@ -0,0 +1,7 @@
+export var test = 40;
+var ok2 = 400;
+var ok3 = 401;
+export {
+ ok2 as "if",
+ ok3 as "else"
+};
Added: trunk/JSTests/modules/arbitrary-module-names.js (0 => 270923)
--- trunk/JSTests/modules/arbitrary-module-names.js (rev 0)
+++ trunk/JSTests/modules/arbitrary-module-names.js 2020-12-17 02:46:48 UTC (rev 270923)
@@ -0,0 +1,12 @@
+import {
+ "delete" as deleting,
+ "if" as ok1,
+ "ok2" as ok2
+} from "./arbitrary-module-names/export.js";
+import { "var" as variable } from "./arbitrary-module-names/export.js";
+import { shouldBe, shouldThrow } from "./resources/assert.js";
+
+shouldBe(deleting, 42);
+shouldBe(variable.test, 40);
+shouldBe(ok1, 400);
+shouldBe(ok2, 401);
Modified: trunk/JSTests/stress/modules-syntax-error.js (270922 => 270923)
--- trunk/JSTests/stress/modules-syntax-error.js 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/JSTests/stress/modules-syntax-error.js 2020-12-17 02:46:48 UTC (rev 270923)
@@ -21,7 +21,7 @@
checkModuleSyntaxError(String.raw`
import {,} from "Cocoa"
-`, `SyntaxError: Unexpected token ','. Expected an imported name for the import declaration.:2`);
+`, `SyntaxError: Unexpected token ','. Expected an imported name or a module export name string for the import declaration.:2`);
checkModuleSyntaxError(String.raw`
import * from "Cocoa"
@@ -158,7 +158,7 @@
checkModuleSyntaxError(String.raw`
import a, { [assign] as c } from "Cocoa"
-`, `SyntaxError: Unexpected token '['. Expected an imported name for the import declaration.:2`);
+`, `SyntaxError: Unexpected token '['. Expected an imported name or a module export name string for the import declaration.:2`);
checkModuleSyntaxError(String.raw`
import d, { g as {obj} } from "Cappuccino"
@@ -166,7 +166,7 @@
checkModuleSyntaxError(String.raw`
import d, { {obj} } from "Cappuccino"
-`, `SyntaxError: Unexpected token '{'. Expected an imported name for the import declaration.:2`);
+`, `SyntaxError: Unexpected token '{'. Expected an imported name or a module export name string for the import declaration.:2`);
checkModuleSyntaxError(String.raw`
import { binding
@@ -184,11 +184,11 @@
checkModuleSyntaxError(String.raw`
export { , } from "Cocoa"
-`, `SyntaxError: Unexpected token ','. Expected a variable name for the export declaration.:2`);
+`, `SyntaxError: Unexpected token ','. Expected a variable name or a module export name string for the export declaration.:2`);
checkModuleSyntaxError(String.raw`
export { a, , } from "Cocoa"
-`, `SyntaxError: Unexpected token ','. Expected a variable name for the export declaration.:2`);
+`, `SyntaxError: Unexpected token ','. Expected a variable name or a module export name string for the export declaration.:2`);
checkModuleSyntaxError(String.raw`
export a from "Cocoa"
@@ -200,7 +200,7 @@
checkModuleSyntaxError(String.raw`
export { * as b } from "Cocoa"
-`, `SyntaxError: Unexpected token '*'. Expected a variable name for the export declaration.:2`);
+`, `SyntaxError: Unexpected token '*'. Expected a variable name or a module export name string for the export declaration.:2`);
checkModuleSyntaxError(String.raw`
export * as b
@@ -208,7 +208,7 @@
checkModuleSyntaxError(String.raw`
export * as 42 from "Cocoa"
-`, `SyntaxError: Unexpected number '42'. Expected an exported name for the export declaration.:2`);
+`, `SyntaxError: Unexpected number '42'. Expected an exported name or a module export name string for the export declaration.:2`);
checkModuleSyntaxError(String.raw`
export const b = 42;
@@ -316,6 +316,42 @@
}
`, `SyntaxError: Unexpected keyword 'export':3`);
+checkModuleSyntaxError(String.raw`
+import { "\ud800" as test } from "./ok.js"
+`, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`);
+
+checkModuleSyntaxError(String.raw`
+import { "test" } from "./ok.js"
+`, String.raw`SyntaxError: Unexpected token '}'. Expected 'as' after the module export name string.:2`);
+
+checkModuleSyntaxError(String.raw`
+export { "test" }
+`, String.raw`SyntaxError: Cannot use module export names if they reference variable names in the current module.:3`);
+
+checkModuleSyntaxError(String.raw`
+export { "test" as "ok" }
+`, String.raw`SyntaxError: Cannot use module export names if they reference variable names in the current module.:3`);
+
+checkModuleSyntaxError(String.raw`
+export { "\ud800" } from "./ok.js"
+`, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`);
+
+checkModuleSyntaxError(String.raw`
+export { ok as "\ud800" } from "./ok.js"
+`, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`);
+
+checkModuleSyntaxError(String.raw`
+export { "hello" as "\ud800" } from "./ok.js"
+`, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`);
+
+checkModuleSyntaxError(String.raw`
+export { "\ud800" as "hello" } from "./ok.js"
+`, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`);
+
+checkModuleSyntaxError(String.raw`
+export * as "\ud800" from "./ok.js"
+`, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`);
+
// --------------- other ---------------------
checkModuleSyntaxError(String.raw`
Modified: trunk/JSTests/test262/config.yaml (270922 => 270923)
--- trunk/JSTests/test262/config.yaml 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/JSTests/test262/config.yaml 2020-12-17 02:46:48 UTC (rev 270923)
@@ -19,7 +19,6 @@
- regexp-lookbehind
- legacy-regexp
- - arbitrary-module-namespace-names
- class-methods-private
- class-static-methods-private
- cleanupSome
Modified: trunk/Source/_javascript_Core/ChangeLog (270922 => 270923)
--- trunk/Source/_javascript_Core/ChangeLog 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-12-17 02:46:48 UTC (rev 270923)
@@ -1,3 +1,32 @@
+2020-12-15 Yusuke Suzuki <[email protected]>
+
+ [JSC] Accept arbitrary module namespace identifier names
+ https://bugs.webkit.org/show_bug.cgi?id=217576
+ <rdar://problem/70416104>
+
+ Reviewed by Darin Adler.
+
+ This patch implements arbitrary module namespace identifier names[1].
+ After this, we can export and import arbitrary module export names which are not valid as a variable identifier.
+ For example,
+
+ import { "delete" as deletedValue } from "./ok.js";
+
+ ...
+
+ export {
+ deletedValue as "delete"
+ };
+
+ [1]: https://github.com/tc39/ecma262/pull/2154
+
+ * parser/Parser.cpp:
+ (JSC::Parser<LexerType>::parseImportClauseItem):
+ (JSC::Parser<LexerType>::parseImportDeclaration):
+ (JSC::Parser<LexerType>::parseExportSpecifier):
+ (JSC::Parser<LexerType>::parseExportDeclaration):
+ * parser/Parser.h:
+
2020-12-16 Yusuke Suzuki <[email protected]>
Unreviewed, fix stale assertions
Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (270922 => 270923)
--- trunk/Source/_javascript_Core/parser/Parser.cpp 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp 2020-12-17 02:46:48 UTC (rev 270923)
@@ -3414,16 +3414,23 @@
// ImportSpecifier :
// ImportedBinding
// IdentifierName as ImportedBinding
+ // ModuleExportName as ImportedBinding
// e.g.
// A
// A as B
- ASSERT(matchIdentifierOrKeyword());
- localNameToken = m_token;
+ ASSERT(matchIdentifierOrKeyword() || match(STRING));
+ bool isModuleExportName = match(STRING);
localName = m_token.m_data.ident;
importedName = localName;
+ localNameToken = m_token;
+ if (isModuleExportName)
+ failIfTrue(hasUnpairedSurrogate(localName->string()), "Expected a well-formed-unicode string for the module export name");
next();
- if (matchContextualKeyword(m_vm.propertyNames->as)) {
+ bool useAs = matchContextualKeyword(m_vm.propertyNames->as);
+ if (isModuleExportName)
+ failIfFalse(useAs, "Expected 'as' after the module export name string");
+ if (useAs) {
next();
failIfFalse(matchSpecIdentifier(), "Expected a variable name for the import declaration");
localNameToken = m_token;
@@ -3502,7 +3509,7 @@
next();
while (!match(CLOSEBRACE)) {
- failIfFalse(matchIdentifierOrKeyword(), "Expected an imported name for the import declaration");
+ failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an imported name or a module export name string for the import declaration");
auto specifier = parseImportClauseItem(context, ImportSpecifierType::NamedImport);
failIfFalse(specifier, "Cannot parse the named import");
context.appendImportSpecifier(specifierList, specifier);
@@ -3528,24 +3535,35 @@
}
template <typename LexerType>
-template <class TreeBuilder> typename TreeBuilder::ExportSpecifier Parser<LexerType>::parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings)
+template <class TreeBuilder> typename TreeBuilder::ExportSpecifier Parser<LexerType>::parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings, bool& hasReferencedModuleExportNames)
{
// ExportSpecifier :
// IdentifierName
// IdentifierName as IdentifierName
+ // IdentifierName as ModuleExportName
+ // ModuleExportName
+ // ModuleExportName as IdentifierName
+ // ModuleExportName as ModuleExportName
// http://www.ecma-international.org/ecma-262/6.0/#sec-exports
- ASSERT(matchIdentifierOrKeyword());
+ ASSERT(matchIdentifierOrKeyword() || match(STRING));
JSTokenLocation specifierLocation(tokenLocation());
- if (m_token.m_type & KeywordTokenFlag)
- hasKeywordForLocalBindings = true;
const Identifier* localName = m_token.m_data.ident;
const Identifier* exportedName = localName;
+ if (match(STRING)) {
+ hasReferencedModuleExportNames = true;
+ failIfTrue(hasUnpairedSurrogate(exportedName->string()), "Expected a well-formed-unicode string for the module export name");
+ } else {
+ if (m_token.m_type & KeywordTokenFlag)
+ hasKeywordForLocalBindings = true;
+ }
next();
if (matchContextualKeyword(m_vm.propertyNames->as)) {
next();
- failIfFalse(matchIdentifierOrKeyword(), "Expected an exported name for the export declaration");
+ failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an exported name or a module export name string for the export declaration");
exportedName = m_token.m_data.ident;
+ if (match(STRING))
+ failIfTrue(hasUnpairedSurrogate(exportedName->string()), "Expected a well-formed-unicode string for the module export name");
next();
}
@@ -3566,6 +3584,7 @@
case TIMES: {
// export * FromClause ;
// export * as IdentifierName FromClause ;
+ // export * as ModuleExportName FromClause ;
next();
const Identifier* exportedName = nullptr;
@@ -3573,8 +3592,10 @@
if (matchContextualKeyword(m_vm.propertyNames->as)) {
next();
specifierLocation = JSTokenLocation(tokenLocation());
- failIfFalse(matchIdentifierOrKeyword(), "Expected an exported name for the export declaration");
+ failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an exported name or a module export name string for the export declaration");
exportedName = m_token.m_data.ident;
+ if (match(STRING))
+ failIfTrue(hasUnpairedSurrogate(exportedName->string()), "Expected a well-formed-unicode string for the module export name");
next();
}
@@ -3703,9 +3724,10 @@
Vector<std::pair<const Identifier*, const Identifier*>> maybeExportedLocalNames;
bool hasKeywordForLocalBindings = false;
+ bool hasReferencedModuleExportNames = false;
while (!match(CLOSEBRACE)) {
- failIfFalse(matchIdentifierOrKeyword(), "Expected a variable name for the export declaration");
- auto specifier = parseExportSpecifier(context, maybeExportedLocalNames, hasKeywordForLocalBindings);
+ failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected a variable name or a module export name string for the export declaration");
+ auto specifier = parseExportSpecifier(context, maybeExportedLocalNames, hasKeywordForLocalBindings, hasReferencedModuleExportNames);
failIfFalse(specifier, "Cannot parse the named export");
context.appendExportSpecifier(specifierList, specifier);
if (!consume(COMMA))
@@ -3718,7 +3740,8 @@
next();
moduleName = parseModuleName(context);
failIfFalse(moduleName, "Cannot parse the 'from' clause");
- }
+ } else
+ semanticFailIfTrue(hasReferencedModuleExportNames, "Cannot use module export names if they reference variable names in the current module");
failIfFalse(autoSemiColon(), "Expected a ';' following a targeted export declaration");
if (!moduleName) {
Modified: trunk/Source/_javascript_Core/parser/Parser.h (270922 => 270923)
--- trunk/Source/_javascript_Core/parser/Parser.h 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/_javascript_Core/parser/Parser.h 2020-12-17 02:46:48 UTC (rev 270923)
@@ -1784,7 +1784,7 @@
template <class TreeBuilder> typename TreeBuilder::ImportSpecifier parseImportClauseItem(TreeBuilder&, ImportSpecifierType);
template <class TreeBuilder> typename TreeBuilder::ModuleName parseModuleName(TreeBuilder&);
template <class TreeBuilder> TreeStatement parseImportDeclaration(TreeBuilder&);
- template <class TreeBuilder> typename TreeBuilder::ExportSpecifier parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings);
+ template <class TreeBuilder> typename TreeBuilder::ExportSpecifier parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings, bool& hasReferencedModuleExportNames);
template <class TreeBuilder> TreeStatement parseExportDeclaration(TreeBuilder&);
template <class TreeBuilder> ALWAYS_INLINE TreeExpression createResolveAndUseVariable(TreeBuilder&, const Identifier*, bool isEval, const JSTextPosition&, const JSTokenLocation&);
Modified: trunk/Source/WTF/ChangeLog (270922 => 270923)
--- trunk/Source/WTF/ChangeLog 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/WTF/ChangeLog 2020-12-17 02:46:48 UTC (rev 270923)
@@ -1,3 +1,13 @@
+2020-12-15 Yusuke Suzuki <[email protected]>
+
+ [JSC] Accept arbitrary module namespace identifier names
+ https://bugs.webkit.org/show_bug.cgi?id=217576
+
+ Reviewed by Darin Adler.
+
+ * wtf/text/StringView.h:
+ (WTF::hasUnpairedSurrogate):
+
2020-12-15 Jer Noble <[email protected]>
[Cocoa] Adopt -externalContentProtectionStatus
Modified: trunk/Source/WTF/wtf/text/StringView.h (270922 => 270923)
--- trunk/Source/WTF/wtf/text/StringView.h 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/WTF/wtf/text/StringView.h 2020-12-17 02:46:48 UTC (rev 270923)
@@ -1087,6 +1087,18 @@
WTF_EXPORT_PRIVATE int codePointCompare(StringView, StringView);
+inline bool hasUnpairedSurrogate(StringView string)
+{
+ // Fast path for 8-bit strings; they can't have any surrogates.
+ if (string.is8Bit())
+ return false;
+ for (auto codePoint : string.codePoints()) {
+ if (U_IS_SURROGATE(codePoint))
+ return true;
+ }
+ return false;
+}
+
} // namespace WTF
using WTF::append;
@@ -1093,3 +1105,4 @@
using WTF::equal;
using WTF::StringView;
using WTF::StringViewWithUnderlyingString;
+using WTF::hasUnpairedSurrogate;
Modified: trunk/Source/WebCore/ChangeLog (270922 => 270923)
--- trunk/Source/WebCore/ChangeLog 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/WebCore/ChangeLog 2020-12-17 02:46:48 UTC (rev 270923)
@@ -1,3 +1,13 @@
+2020-12-15 Yusuke Suzuki <[email protected]>
+
+ [JSC] Accept arbitrary module namespace identifier names
+ https://bugs.webkit.org/show_bug.cgi?id=217576
+
+ Reviewed by Darin Adler.
+
+ * bindings/js/JSDOMConvertStrings.cpp:
+ (WebCore::hasUnpairedSurrogate): Deleted.
+
2020-12-16 Peng Liu <[email protected]>
[Media in GPU Process][MSE] Add an IPC message BufferedSamplesForTrackId for testing purposes
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp (270922 => 270923)
--- trunk/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp 2020-12-17 02:20:13 UTC (rev 270922)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp 2020-12-17 02:46:48 UTC (rev 270923)
@@ -62,18 +62,6 @@
return stringToByteString(lexicalGlobalObject, scope, WTFMove(string));
}
-static inline bool hasUnpairedSurrogate(StringView string)
-{
- // Fast path for 8-bit strings; they can't have any surrogates.
- if (string.is8Bit())
- return false;
- for (auto codePoint : string.codePoints()) {
- if (U_IS_SURROGATE(codePoint))
- return true;
- }
- return false;
-}
-
static inline String stringToUSVString(String&& string)
{
// Fast path for the case where there are no unpaired surrogates.