| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 68fd751 commit 6fbf0ba
26 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,10 +128,9 @@ class V8_EXPORT ModuleRequest : public Data { | |||
| 128 | 128 | * | |
| 129 | 129 | * All assertions present in the module request will be supplied in this | |
| 130 | 130 | * list, regardless of whether they are supported by the host. Per | |
| 131 | - * https://tc39.es/proposal-import-assertions/#sec-hostgetsupportedimportassertions, | ||
| 132 | - * hosts are expected to ignore assertions that they do not support (as | ||
| 133 | - * opposed to, for example, triggering an error if an unsupported assertion is | ||
| 134 | - * present). | ||
| 131 | + * https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes, | ||
| 132 | + * hosts are expected to throw for assertions that they do not support (as | ||
| 133 | + * opposed to, for example, ignoring them). | ||
| 135 | 134 | */ | |
| 136 | 135 | Local<FixedArray> GetImportAssertions() const; | |
| 137 | 136 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4726,7 +4726,7 @@ MaybeHandle<FixedArray> Isolate::GetImportAssertionsFromArgument( | |||
| 4726 | 4726 | ||
| 4727 | 4727 | // The parser shouldn't have allowed the second argument to import() if | |
| 4728 | 4728 | // the flag wasn't enabled. | |
| 4729 | - DCHECK(FLAG_harmony_import_assertions); | ||
| 4729 | + DCHECK(FLAG_harmony_import_assertions || FLAG_harmony_import_attributes); | ||
| 4730 | 4730 | ||
| 4731 | 4731 | if (!import_assertions_argument->IsJSReceiver()) { | |
| 4732 | 4732 | this->Throw( | |
@@ -4736,18 +4736,35 @@ MaybeHandle<FixedArray> Isolate::GetImportAssertionsFromArgument( | |||
| 4736 | 4736 | ||
| 4737 | 4737 | Handle<JSReceiver> import_assertions_argument_receiver = | |
| 4738 | 4738 | Handle<JSReceiver>::cast(import_assertions_argument); | |
| 4739 | - Handle<Name> key = factory()->assert_string(); | ||
| 4740 | 4739 | ||
| 4741 | 4740 | Handle<Object> import_assertions_object; | |
| 4742 | - if (!JSReceiver::GetProperty(this, import_assertions_argument_receiver, key) | ||
| 4743 | - .ToHandle(&import_assertions_object)) { | ||
| 4744 | - // This can happen if the property has a getter function that throws | ||
| 4745 | - // an error. | ||
| 4746 | - return MaybeHandle<FixedArray>(); | ||
| 4741 | + | ||
| 4742 | + if (FLAG_harmony_import_attributes) { | ||
| 4743 | + Handle<Name> with_key = factory()->with_string(); | ||
| 4744 | + if (!JSReceiver::GetProperty(this, import_assertions_argument_receiver, | ||
| 4745 | + with_key) | ||
| 4746 | + .ToHandle(&import_assertions_object)) { | ||
| 4747 | + // This can happen if the property has a getter function that throws | ||
| 4748 | + // an error. | ||
| 4749 | + return MaybeHandle<FixedArray>(); | ||
| 4750 | + } | ||
| 4747 | 4751 | } | |
| 4748 | 4752 | ||
| 4749 | - // If there is no 'assert' option in the options bag, it's not an error. Just | ||
| 4750 | - // do the import() as if no assertions were provided. | ||
| 4753 | + if (FLAG_harmony_import_assertions && | ||
| 4754 | + (!FLAG_harmony_import_attributes || | ||
| 4755 | + import_assertions_object->IsUndefined())) { | ||
| 4756 | + Handle<Name> assert_key = factory()->assert_string(); | ||
| 4757 | + if (!JSReceiver::GetProperty(this, import_assertions_argument_receiver, | ||
| 4758 | + assert_key) | ||
| 4759 | + .ToHandle(&import_assertions_object)) { | ||
| 4760 | + // This can happen if the property has a getter function that throws | ||
| 4761 | + // an error. | ||
| 4762 | + return MaybeHandle<FixedArray>(); | ||
| 4763 | + } | ||
| 4764 | + } | ||
| 4765 | + | ||
| 4766 | + // If there is no 'with' or 'assert' option in the options bag, it's not an | ||
| 4767 | + // error. Just do the import() as if no assertions were provided. | ||
| 4751 | 4768 | if (import_assertions_object->IsUndefined()) return import_assertions_array; | |
| 4752 | 4769 | ||
| 4753 | 4770 | if (!import_assertions_object->IsJSReceiver()) { | |
@@ -4769,6 +4786,8 @@ MaybeHandle<FixedArray> Isolate::GetImportAssertionsFromArgument( | |||
| 4769 | 4786 | return MaybeHandle<FixedArray>(); | |
| 4770 | 4787 | } | |
| 4771 | 4788 | ||
| 4789 | + bool has_non_string_attribute = false; | ||
| 4790 | + | ||
| 4772 | 4791 | // The assertions will be passed to the host in the form: [key1, | |
| 4773 | 4792 | // value1, key2, value2, ...]. | |
| 4774 | 4793 | constexpr size_t kAssertionEntrySizeForDynamicImport = 2; | |
@@ -4786,9 +4805,7 @@ MaybeHandle<FixedArray> Isolate::GetImportAssertionsFromArgument( | |||
| 4786 | 4805 | } | |
| 4787 | 4806 | ||
| 4788 | 4807 | if (!assertion_value->IsString()) { | |
| 4789 | - this->Throw(*factory()->NewTypeError( | ||
| 4790 | - MessageTemplate::kNonStringImportAssertionValue)); | ||
| 4791 | - return MaybeHandle<FixedArray>(); | ||
| 4808 | + has_non_string_attribute = true; | ||
| 4792 | 4809 | } | |
| 4793 | 4810 | ||
| 4794 | 4811 | import_assertions_array->set((i * kAssertionEntrySizeForDynamicImport), | |
@@ -4797,6 +4814,12 @@ MaybeHandle<FixedArray> Isolate::GetImportAssertionsFromArgument( | |||
| 4797 | 4814 | *assertion_value); | |
| 4798 | 4815 | } | |
| 4799 | 4816 | ||
| 4817 | + if (has_non_string_attribute) { | ||
| 4818 | + this->Throw(*factory()->NewTypeError( | ||
| 4819 | + MessageTemplate::kNonStringImportAssertionValue)); | ||
| 4820 | + return MaybeHandle<FixedArray>(); | ||
| 4821 | + } | ||
| 4822 | + | ||
| 4800 | 4823 | return import_assertions_array; | |
| 4801 | 4824 | } | |
| 4802 | 4825 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -300,6 +300,7 @@ DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features") | |||
| 300 | 300 | ||
| 301 | 301 | // Features that are still work in progress (behind individual flags). | |
| 302 | 302 | #define HARMONY_INPROGRESS_BASE(V) \ | |
| 303 | + V(harmony_import_attributes, "harmony import attributes") \ | ||
| 303 | 304 | V(harmony_weak_refs_with_cleanup_some, \ | |
| 304 | 305 | "harmony weak references with FinalizationRegistry.prototype.cleanupSome") \ | |
| 305 | 306 | V(harmony_import_assertions, "harmony import assertions") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4482,6 +4482,7 @@ void Genesis::InitializeConsole(Handle<JSObject> extras_binding) { | |||
| 4482 | 4482 | void Genesis::InitializeGlobal_##id() {} | |
| 4483 | 4483 | ||
| 4484 | 4484 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_assertions) | |
| 4485 | + EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_attributes) | ||
| 4485 | 4486 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_private_brand_checks) | |
| 4486 | 4487 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_class_static_blocks) | |
| 4487 | 4488 | EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_error_cause) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -432,6 +432,7 @@ | |||
| 432 | 432 | V(_, week_string, "week") \ | |
| 433 | 433 | V(_, weeks_string, "weeks") \ | |
| 434 | 434 | V(_, weekOfYear_string, "weekOfYear") \ | |
| 435 | + V(_, with_string, "with") \ | ||
| 435 | 436 | V(_, word_string, "word") \ | |
| 436 | 437 | V(_, writable_string, "writable") \ | |
| 437 | 438 | V(_, yearMonthFromFields_string, "yearMonthFromFields") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3725,7 +3725,9 @@ ParserBase<Impl>::ParseImportExpressions() { | |||
| 3725 | 3725 | AcceptINScope scope(this, true); | |
| 3726 | 3726 | ExpressionT specifier = ParseAssignmentExpressionCoverGrammar(); | |
| 3727 | 3727 | ||
| 3728 | - if (FLAG_harmony_import_assertions && Check(Token::COMMA)) { | ||
| 3728 | + if ((FLAG_harmony_import_assertions || | ||
| 3729 | + FLAG_harmony_import_attributes) && | ||
| 3730 | + Check(Token::COMMA)) { | ||
| 3729 | 3731 | if (Check(Token::RPAREN)) { | |
| 3730 | 3732 | // A trailing comma allowed after the specifier. | |
| 3731 | 3733 | return factory()->NewImportCallExpression(specifier, pos); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1344,36 +1344,47 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) { | |||
| 1344 | 1344 | } | |
| 1345 | 1345 | ||
| 1346 | 1346 | ImportAssertions* Parser::ParseImportAssertClause() { | |
| 1347 | - // AssertClause : | ||
| 1348 | - // assert '{' '}' | ||
| 1349 | - // assert '{' AssertEntries '}' | ||
| 1347 | + // WithClause : | ||
| 1348 | + // with '{' '}' | ||
| 1349 | + // with '{' WithEntries ','? '}' | ||
| 1350 | 1350 | ||
| 1351 | - // AssertEntries : | ||
| 1352 | - // IdentifierName: AssertionKey | ||
| 1353 | - // IdentifierName: AssertionKey , AssertEntries | ||
| 1351 | + // WithEntries : | ||
| 1352 | + // LiteralPropertyName | ||
| 1353 | + // LiteralPropertyName ':' StringLiteral , WithEntries | ||
| 1354 | 1354 | ||
| 1355 | - // AssertionKey : | ||
| 1356 | - // IdentifierName | ||
| 1357 | - // StringLiteral | ||
| 1355 | + // (DEPRECATED) | ||
| 1356 | + // AssertClause : | ||
| 1357 | + // assert '{' '}' | ||
| 1358 | + // assert '{' WithEntries ','? '}' | ||
| 1358 | 1359 | ||
| 1359 | 1360 | auto import_assertions = zone()->New<ImportAssertions>(zone()); | |
| 1360 | 1361 | ||
| 1361 | - if (!FLAG_harmony_import_assertions) { | ||
| 1362 | - return import_assertions; | ||
| 1363 | - } | ||
| 1362 | + if (FLAG_harmony_import_attributes && Check(Token::WITH)) { | ||
| 1363 | + // 'with' keyword consumed | ||
| 1364 | + } else if (FLAG_harmony_import_assertions && | ||
| 1365 | + !scanner()->HasLineTerminatorBeforeNext() && | ||
| 1366 | + CheckContextualKeyword(ast_value_factory()->assert_string())) { | ||
| 1367 | + // The 'assert' contextual keyword is deprecated in favor of 'with', and we | ||
| 1368 | + // need to investigate feasibility of unshipping. | ||
| 1369 | + // | ||
| 1370 | + // TODO(v8:13856): Remove once decision is made to unship 'assert' or keep. | ||
| 1364 | 1371 | ||
| 1365 | - // Assert clause is optional, and cannot be preceded by a LineTerminator. | ||
| 1366 | - if (scanner()->HasLineTerminatorBeforeNext() || | ||
| 1367 | - !CheckContextualKeyword(ast_value_factory()->assert_string())) { | ||
| 1372 | + // NOTE(Node.js): Commented out to avoid backporting this use counter to Node.js 18 | ||
| 1373 | + // ++use_counts_[v8::Isolate::kImportAssertionDeprecatedSyntax]; | ||
| 1374 | + } else { | ||
| 1368 | 1375 | return import_assertions; | |
| 1369 | 1376 | } | |
| 1370 | 1377 | ||
| 1371 | 1378 | Expect(Token::LBRACE); | |
| 1372 | 1379 | ||
| 1373 | 1380 | while (peek() != Token::RBRACE) { | |
| 1374 | 1381 | const AstRawString* attribute_key = nullptr; | |
| 1375 | - if (Check(Token::STRING)) { | ||
| 1382 | + if (Check(Token::STRING) || Check(Token::SMI)) { | ||
| 1376 | 1383 | attribute_key = GetSymbol(); | |
| 1384 | + } else if (Check(Token::NUMBER)) { | ||
| 1385 | + attribute_key = GetNumberAsSymbol(); | ||
| 1386 | + } else if (Check(Token::BIGINT)) { | ||
| 1387 | + attribute_key = GetBigIntAsSymbol(); | ||
| 1377 | 1388 | } else { | |
| 1378 | 1389 | attribute_key = ParsePropertyName(); | |
| 1379 | 1390 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + // Copyright 2021 the V8 project authors. All rights reserved. | ||
| 2 | + // Use of this source code is governed by a BSD-style license that can be | ||
| 3 | + // found in the LICENSE file. | ||
| 4 | + | ||
| 5 | + // Flags: --harmony-import-attributes | ||
| 6 | + | ||
| 7 | + import { life } from 'modules-skip-1.mjs' with { }; | ||
| 8 | + | ||
| 9 | + assertEquals(42, life()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + // Copyright 2021 the V8 project authors. All rights reserved. | ||
| 2 | + // Use of this source code is governed by a BSD-style license that can be | ||
| 3 | + // found in the LICENSE file. | ||
| 4 | + | ||
| 5 | + // Flags: --harmony-import-attributes | ||
| 6 | + | ||
| 7 | + import json from 'modules-skip-1.json' with { type: 'json' }; | ||
| 8 | + | ||
| 9 | + assertEquals(42, json.life); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + // Copyright 2021 the V8 project authors. All rights reserved. | ||
| 2 | + // Use of this source code is governed by a BSD-style license that can be | ||
| 3 | + // found in the LICENSE file. | ||
| 4 | + | ||
| 5 | + // Flags: --harmony-import-attributes | ||
| 6 | + | ||
| 7 | + import {life} from 'modules-skip-imports-json-1.mjs'; | ||
| 8 | + | ||
| 9 | + assertEquals(42, life()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments