a09c076f00
This change completes support for import assertions for dynamic import(). A new version of the HostImportModuleDynamically callback taking import assertions is added to the public API. The name is very verbose; we could consider removing the "ImportAssertions" part when the old API is removed. Bytecode generation is updated to pass the assertions, if present, to Runtime_DynamicImportCall. Isolate::RunHostImportModuleDynamicallyCallback extracts the assertions from the options bag, filters out the assertions not present in the list specified by the host in HostGetSupportedImportAssertions, and sorts them by code point order of the keys per https://tc39.es/proposal-import-assertions/#sec-import-call-runtime-semantics-evaluation. The resulting array is passed to the host in the callback. Bug: v8:10958 Change-Id: I931df00f954a9f9c65bff5bcf461ba1c8f11e94e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2620578 Commit-Queue: Dan Clark <daniec@microsoft.com> Reviewed-by: Camillo Bruni <cbruni@chromium.org> Reviewed-by: Mythri Alle <mythria@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/master@{#72307}
64 lines
2.8 KiB
JavaScript
64 lines
2.8 KiB
JavaScript
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --allow-natives-syntax --harmony-import-assertions
|
|
|
|
var result1;
|
|
var result2;
|
|
var result3;
|
|
var result4;
|
|
var result5;
|
|
var result6;
|
|
var result7;
|
|
var result8;
|
|
var result9;
|
|
var result10;
|
|
import('modules-skip-1.json', null).then(
|
|
() => assertUnreachable('Should have failed due to non-object parameter'),
|
|
error => result1 = error.message);
|
|
import('modules-skip-1.json', 7).then(
|
|
() => assertUnreachable('Should have failed due to non-object parameter'),
|
|
error => result2 = error.message);
|
|
import('modules-skip-1.json', 'string').then(
|
|
() => assertUnreachable('Should have failed due to non-object parameter'),
|
|
error => result3 = error.message);
|
|
import('modules-skip-1.json', { assert: null}).then(
|
|
() => assertUnreachable('Should have failed due to bad assert object'),
|
|
error => result4 = error.message);
|
|
import('modules-skip-1.json', { assert: 7}).then(
|
|
() => assertUnreachable('Should have failed due to bad assert object'),
|
|
error => result5 = error.message);
|
|
import('modules-skip-1.json', { assert: 'string'}).then(
|
|
() => assertUnreachable('Should have failed due to bad assert object'),
|
|
error => result6 = error.message);
|
|
import('modules-skip-1.json', { assert: { a: null }}).then(
|
|
() => assertUnreachable('Should have failed due to bad assert object'),
|
|
error => result7 = error.message);
|
|
import('modules-skip-1.json', { assert: { a: undefined }}).then(
|
|
() => assertUnreachable('Should have failed due to bad assertion value'),
|
|
error => result8 = error.message);
|
|
import('modules-skip-1.json', { assert: { a: 7 }}).then(
|
|
() => assertUnreachable('Should have failed due to bad assertion value'),
|
|
error => result9 = error.message);
|
|
import('modules-skip-1.json', { assert: { a: { } }}).then(
|
|
() => assertUnreachable('Should have failed due to bad assertion value'),
|
|
error => result10 = error.message);
|
|
|
|
%PerformMicrotaskCheckpoint();
|
|
|
|
const argumentNotObjectError = 'The second argument to import() must be an object';
|
|
const assertOptionNotObjectError = 'The \'assert\' option must be an object';
|
|
const assertionValueNotStringError = 'Import assertion value must be a string';
|
|
|
|
assertEquals(argumentNotObjectError, result1);
|
|
assertEquals(argumentNotObjectError, result2);
|
|
assertEquals(argumentNotObjectError, result3);
|
|
assertEquals(assertOptionNotObjectError, result4);
|
|
assertEquals(assertOptionNotObjectError, result5);
|
|
assertEquals(assertOptionNotObjectError, result6);
|
|
assertEquals(assertionValueNotStringError, result7);
|
|
assertEquals(assertionValueNotStringError, result8);
|
|
assertEquals(assertionValueNotStringError, result9);
|
|
assertEquals(assertionValueNotStringError, result10);
|