@@ -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 |
|
|