Changeset 270923 in webkit
- Timestamp:
- Dec 16, 2020, 6:46:48 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 10 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/modules/arbitrary-module-names (added)
-
JSTests/modules/arbitrary-module-names.js (added)
-
JSTests/modules/arbitrary-module-names/export.js (added)
-
JSTests/modules/arbitrary-module-names/export2.js (added)
-
JSTests/stress/modules-syntax-error.js (modified) (7 diffs)
-
JSTests/test262/config.yaml (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/parser/Parser.cpp (modified) (7 diffs)
-
Source/JavaScriptCore/parser/Parser.h (modified) (1 diff)
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/text/StringView.h (modified) (2 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/bindings/js/JSDOMConvertStrings.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r270874 r270923 1 2020-12-15 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Accept arbitrary module namespace identifier names 4 https://bugs.webkit.org/show_bug.cgi?id=217576 5 <rdar://problem/70416104> 6 7 Reviewed by Darin Adler. 8 9 * modules/arbitrary-module-names.js: Added. 10 * modules/arbitrary-module-names/export.js: Added. 11 * modules/arbitrary-module-names/export2.js: Added. 12 * stress/modules-syntax-error.js: 13 * test262/config.yaml: 14 1 15 2020-12-15 Alexey Shvayka <shvaikalesh@gmail.com> 2 16 -
trunk/JSTests/stress/modules-syntax-error.js
r267186 r270923 22 22 checkModuleSyntaxError(String.raw` 23 23 import {,} from "Cocoa" 24 `, `SyntaxError: Unexpected token ','. Expected an imported name for the import declaration.:2`);24 `, `SyntaxError: Unexpected token ','. Expected an imported name or a module export name string for the import declaration.:2`); 25 25 26 26 checkModuleSyntaxError(String.raw` … … 159 159 checkModuleSyntaxError(String.raw` 160 160 import a, { [assign] as c } from "Cocoa" 161 `, `SyntaxError: Unexpected token '['. Expected an imported name for the import declaration.:2`);161 `, `SyntaxError: Unexpected token '['. Expected an imported name or a module export name string for the import declaration.:2`); 162 162 163 163 checkModuleSyntaxError(String.raw` … … 167 167 checkModuleSyntaxError(String.raw` 168 168 import d, { {obj} } from "Cappuccino" 169 `, `SyntaxError: Unexpected token '{'. Expected an imported name for the import declaration.:2`);169 `, `SyntaxError: Unexpected token '{'. Expected an imported name or a module export name string for the import declaration.:2`); 170 170 171 171 checkModuleSyntaxError(String.raw` … … 185 185 checkModuleSyntaxError(String.raw` 186 186 export { , } from "Cocoa" 187 `, `SyntaxError: Unexpected token ','. Expected a variable name for the export declaration.:2`);187 `, `SyntaxError: Unexpected token ','. Expected a variable name or a module export name string for the export declaration.:2`); 188 188 189 189 checkModuleSyntaxError(String.raw` 190 190 export { a, , } from "Cocoa" 191 `, `SyntaxError: Unexpected token ','. Expected a variable name for the export declaration.:2`);191 `, `SyntaxError: Unexpected token ','. Expected a variable name or a module export name string for the export declaration.:2`); 192 192 193 193 checkModuleSyntaxError(String.raw` … … 201 201 checkModuleSyntaxError(String.raw` 202 202 export { * as b } from "Cocoa" 203 `, `SyntaxError: Unexpected token '*'. Expected a variable name for the export declaration.:2`);203 `, `SyntaxError: Unexpected token '*'. Expected a variable name or a module export name string for the export declaration.:2`); 204 204 205 205 checkModuleSyntaxError(String.raw` … … 209 209 checkModuleSyntaxError(String.raw` 210 210 export * as 42 from "Cocoa" 211 `, `SyntaxError: Unexpected number '42'. Expected an exported name for the export declaration.:2`);211 `, `SyntaxError: Unexpected number '42'. Expected an exported name or a module export name string for the export declaration.:2`); 212 212 213 213 checkModuleSyntaxError(String.raw` … … 317 317 `, `SyntaxError: Unexpected keyword 'export':3`); 318 318 319 checkModuleSyntaxError(String.raw` 320 import { "\ud800" as test } from "./ok.js" 321 `, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`); 322 323 checkModuleSyntaxError(String.raw` 324 import { "test" } from "./ok.js" 325 `, String.raw`SyntaxError: Unexpected token '}'. Expected 'as' after the module export name string.:2`); 326 327 checkModuleSyntaxError(String.raw` 328 export { "test" } 329 `, String.raw`SyntaxError: Cannot use module export names if they reference variable names in the current module.:3`); 330 331 checkModuleSyntaxError(String.raw` 332 export { "test" as "ok" } 333 `, String.raw`SyntaxError: Cannot use module export names if they reference variable names in the current module.:3`); 334 335 checkModuleSyntaxError(String.raw` 336 export { "\ud800" } from "./ok.js" 337 `, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`); 338 339 checkModuleSyntaxError(String.raw` 340 export { ok as "\ud800" } from "./ok.js" 341 `, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`); 342 343 checkModuleSyntaxError(String.raw` 344 export { "hello" as "\ud800" } from "./ok.js" 345 `, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`); 346 347 checkModuleSyntaxError(String.raw` 348 export { "\ud800" as "hello" } from "./ok.js" 349 `, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`); 350 351 checkModuleSyntaxError(String.raw` 352 export * as "\ud800" from "./ok.js" 353 `, String.raw`SyntaxError: Unexpected string literal "\ud800". Expected a well-formed-unicode string for the module export name.:2`); 354 319 355 // --------------- other --------------------- 320 356 -
trunk/JSTests/test262/config.yaml
r270043 r270923 20 20 - legacy-regexp 21 21 22 - arbitrary-module-namespace-names23 22 - class-methods-private 24 23 - class-static-methods-private -
trunk/Source/JavaScriptCore/ChangeLog
r270888 r270923 1 2020-12-15 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Accept arbitrary module namespace identifier names 4 https://bugs.webkit.org/show_bug.cgi?id=217576 5 <rdar://problem/70416104> 6 7 Reviewed by Darin Adler. 8 9 This patch implements arbitrary module namespace identifier names[1]. 10 After this, we can export and import arbitrary module export names which are not valid as a variable identifier. 11 For example, 12 13 import { "delete" as deletedValue } from "./ok.js"; 14 15 ... 16 17 export { 18 deletedValue as "delete" 19 }; 20 21 [1]: https://github.com/tc39/ecma262/pull/2154 22 23 * parser/Parser.cpp: 24 (JSC::Parser<LexerType>::parseImportClauseItem): 25 (JSC::Parser<LexerType>::parseImportDeclaration): 26 (JSC::Parser<LexerType>::parseExportSpecifier): 27 (JSC::Parser<LexerType>::parseExportDeclaration): 28 * parser/Parser.h: 29 1 30 2020-12-16 Yusuke Suzuki <ysuzuki@apple.com> 2 31 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r270487 r270923 3415 3415 // ImportedBinding 3416 3416 // IdentifierName as ImportedBinding 3417 // ModuleExportName as ImportedBinding 3417 3418 // e.g. 3418 3419 // A 3419 3420 // A as B 3420 ASSERT(matchIdentifierOrKeyword() );3421 localNameToken = m_token;3421 ASSERT(matchIdentifierOrKeyword() || match(STRING)); 3422 bool isModuleExportName = match(STRING); 3422 3423 localName = m_token.m_data.ident; 3423 3424 importedName = localName; 3424 next(); 3425 3426 if (matchContextualKeyword(m_vm.propertyNames->as)) { 3425 localNameToken = m_token; 3426 if (isModuleExportName) 3427 failIfTrue(hasUnpairedSurrogate(localName->string()), "Expected a well-formed-unicode string for the module export name"); 3428 next(); 3429 3430 bool useAs = matchContextualKeyword(m_vm.propertyNames->as); 3431 if (isModuleExportName) 3432 failIfFalse(useAs, "Expected 'as' after the module export name string"); 3433 if (useAs) { 3427 3434 next(); 3428 3435 failIfFalse(matchSpecIdentifier(), "Expected a variable name for the import declaration"); … … 3503 3510 3504 3511 while (!match(CLOSEBRACE)) { 3505 failIfFalse(matchIdentifierOrKeyword() , "Expected an imported namefor the import declaration");3512 failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an imported name or a module export name string for the import declaration"); 3506 3513 auto specifier = parseImportClauseItem(context, ImportSpecifierType::NamedImport); 3507 3514 failIfFalse(specifier, "Cannot parse the named import"); … … 3529 3536 3530 3537 template <typename LexerType> 3531 template <class TreeBuilder> typename TreeBuilder::ExportSpecifier Parser<LexerType>::parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings )3538 template <class TreeBuilder> typename TreeBuilder::ExportSpecifier Parser<LexerType>::parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings, bool& hasReferencedModuleExportNames) 3532 3539 { 3533 3540 // ExportSpecifier : 3534 3541 // IdentifierName 3535 3542 // IdentifierName as IdentifierName 3543 // IdentifierName as ModuleExportName 3544 // ModuleExportName 3545 // ModuleExportName as IdentifierName 3546 // ModuleExportName as ModuleExportName 3536 3547 // http://www.ecma-international.org/ecma-262/6.0/#sec-exports 3537 ASSERT(matchIdentifierOrKeyword() );3548 ASSERT(matchIdentifierOrKeyword() || match(STRING)); 3538 3549 JSTokenLocation specifierLocation(tokenLocation()); 3539 if (m_token.m_type & KeywordTokenFlag)3540 hasKeywordForLocalBindings = true;3541 3550 const Identifier* localName = m_token.m_data.ident; 3542 3551 const Identifier* exportedName = localName; 3552 if (match(STRING)) { 3553 hasReferencedModuleExportNames = true; 3554 failIfTrue(hasUnpairedSurrogate(exportedName->string()), "Expected a well-formed-unicode string for the module export name"); 3555 } else { 3556 if (m_token.m_type & KeywordTokenFlag) 3557 hasKeywordForLocalBindings = true; 3558 } 3543 3559 next(); 3544 3560 3545 3561 if (matchContextualKeyword(m_vm.propertyNames->as)) { 3546 3562 next(); 3547 failIfFalse(matchIdentifierOrKeyword() , "Expected an exported namefor the export declaration");3563 failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an exported name or a module export name string for the export declaration"); 3548 3564 exportedName = m_token.m_data.ident; 3565 if (match(STRING)) 3566 failIfTrue(hasUnpairedSurrogate(exportedName->string()), "Expected a well-formed-unicode string for the module export name"); 3549 3567 next(); 3550 3568 } … … 3567 3585 // export * FromClause ; 3568 3586 // export * as IdentifierName FromClause ; 3587 // export * as ModuleExportName FromClause ; 3569 3588 next(); 3570 3589 … … 3574 3593 next(); 3575 3594 specifierLocation = JSTokenLocation(tokenLocation()); 3576 failIfFalse(matchIdentifierOrKeyword() , "Expected an exported namefor the export declaration");3595 failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an exported name or a module export name string for the export declaration"); 3577 3596 exportedName = m_token.m_data.ident; 3597 if (match(STRING)) 3598 failIfTrue(hasUnpairedSurrogate(exportedName->string()), "Expected a well-formed-unicode string for the module export name"); 3578 3599 next(); 3579 3600 } … … 3704 3725 3705 3726 bool hasKeywordForLocalBindings = false; 3727 bool hasReferencedModuleExportNames = false; 3706 3728 while (!match(CLOSEBRACE)) { 3707 failIfFalse(matchIdentifierOrKeyword() , "Expected a variable namefor the export declaration");3708 auto specifier = parseExportSpecifier(context, maybeExportedLocalNames, hasKeywordForLocalBindings );3729 failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected a variable name or a module export name string for the export declaration"); 3730 auto specifier = parseExportSpecifier(context, maybeExportedLocalNames, hasKeywordForLocalBindings, hasReferencedModuleExportNames); 3709 3731 failIfFalse(specifier, "Cannot parse the named export"); 3710 3732 context.appendExportSpecifier(specifierList, specifier); … … 3719 3741 moduleName = parseModuleName(context); 3720 3742 failIfFalse(moduleName, "Cannot parse the 'from' clause"); 3721 } 3743 } else 3744 semanticFailIfTrue(hasReferencedModuleExportNames, "Cannot use module export names if they reference variable names in the current module"); 3722 3745 failIfFalse(autoSemiColon(), "Expected a ';' following a targeted export declaration"); 3723 3746 -
trunk/Source/JavaScriptCore/parser/Parser.h
r270481 r270923 1785 1785 template <class TreeBuilder> typename TreeBuilder::ModuleName parseModuleName(TreeBuilder&); 1786 1786 template <class TreeBuilder> TreeStatement parseImportDeclaration(TreeBuilder&); 1787 template <class TreeBuilder> typename TreeBuilder::ExportSpecifier parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings );1787 template <class TreeBuilder> typename TreeBuilder::ExportSpecifier parseExportSpecifier(TreeBuilder& context, Vector<std::pair<const Identifier*, const Identifier*>>& maybeExportedLocalNames, bool& hasKeywordForLocalBindings, bool& hasReferencedModuleExportNames); 1788 1788 template <class TreeBuilder> TreeStatement parseExportDeclaration(TreeBuilder&); 1789 1789 -
trunk/Source/WTF/ChangeLog
r270872 r270923 1 2020-12-15 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Accept arbitrary module namespace identifier names 4 https://bugs.webkit.org/show_bug.cgi?id=217576 5 6 Reviewed by Darin Adler. 7 8 * wtf/text/StringView.h: 9 (WTF::hasUnpairedSurrogate): 10 1 11 2020-12-15 Jer Noble <jer.noble@apple.com> 2 12 -
trunk/Source/WTF/wtf/text/StringView.h
r266973 r270923 1088 1088 WTF_EXPORT_PRIVATE int codePointCompare(StringView, StringView); 1089 1089 1090 inline bool hasUnpairedSurrogate(StringView string) 1091 { 1092 // Fast path for 8-bit strings; they can't have any surrogates. 1093 if (string.is8Bit()) 1094 return false; 1095 for (auto codePoint : string.codePoints()) { 1096 if (U_IS_SURROGATE(codePoint)) 1097 return true; 1098 } 1099 return false; 1100 } 1101 1090 1102 } // namespace WTF 1091 1103 … … 1094 1106 using WTF::StringView; 1095 1107 using WTF::StringViewWithUnderlyingString; 1108 using WTF::hasUnpairedSurrogate; -
trunk/Source/WebCore/ChangeLog
r270919 r270923 1 2020-12-15 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Accept arbitrary module namespace identifier names 4 https://bugs.webkit.org/show_bug.cgi?id=217576 5 6 Reviewed by Darin Adler. 7 8 * bindings/js/JSDOMConvertStrings.cpp: 9 (WebCore::hasUnpairedSurrogate): Deleted. 10 1 11 2020-12-16 Peng Liu <peng.liu6@apple.com> 2 12 -
trunk/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp
r251425 r270923 63 63 } 64 64 65 static inline bool hasUnpairedSurrogate(StringView string)66 {67 // Fast path for 8-bit strings; they can't have any surrogates.68 if (string.is8Bit())69 return false;70 for (auto codePoint : string.codePoints()) {71 if (U_IS_SURROGATE(codePoint))72 return true;73 }74 return false;75 }76 77 65 static inline String stringToUSVString(String&& string) 78 66 {
Note:
See TracChangeset
for help on using the changeset viewer.