-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Original commit message: Reland "[import-attributes] Implement import attributes, with `assert` fallback" This is a reland of commit 159c82c5e6392e78b9bba7161b1bed6e23758984, to set the correct author. Original change's description: > [import-attributes] Implement import attributes, with `assert` fallback > > In the past six months, the old import assertions proposal has been > renamed to "import attributes" with the follwing major changes: > 1. the keyword is now `with` instead of `assert` > 2. unknown assertions cause an error rather than being ignored > > To preserve backward compatibility with existing applications that use > `assert`, implementations _can_ keep it around as a fallback for both > the static and dynamic forms. > > Additionally, the proposal has some minor changes that came up during > the stage 3 reviews: > 3. dynamic import first reads all the attributes, and then verifies > that they are all strings > 4. there is no need for a `[no LineTerminator here]` restriction before > the `with` keyword > 5. static import syntax allows any `LiteralPropertyName` as attribute > keys, to align with every other syntax using key-value pairs > > The new syntax is enabled by a new `--harmony-import-attributes` flag, > disabled by default. However, the new behavioral changes also apply to > the old syntax that is under the `--harmony-import-assertions` flag. > > This patch does implements (1), (3), (4) and (5). Handling of unknown > import assertions was not implemented directly in V8, but delegated > to embedders. As such, it will be implemented separately in d8 and > Chromium. > > To simplify the review, this patch doesn't migrate usage of the term > "assertions" to "attributes". There are many variables and internal > functions that could be easily renamed as soon as this patch landes. > There is one usage in the public API > (`ModuleRequest::GetImportAssertions`) that will probably need to be > aliased and then removed following the same process as for other API > breaking changes. > > Bug: v8:13856 > Change-Id: I78b167348d898887332c5ca7468bc5d58cd9b1ca > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4632799 > Commit-Queue: Shu-yu Guo <syg@chromium.org> > Reviewed-by: Adam Klein <adamk@chromium.org> > Cr-Commit-Position: refs/heads/main@{#89110} Bug: v8:13856 Change-Id: Ic59aa3bd9101618e47ddf6cf6d6416a3a438ebec Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4705558 Commit-Queue: Shu-yu Guo <syg@chromium.org> Reviewed-by: Shu-yu Guo <syg@chromium.org> Reviewed-by: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/main@{#89115} Refs: v8/v8@a0fd320 PR-URL: #51136 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
- Loading branch information
1 parent
68fd751
commit 6fbf0ba
Showing
26 changed files
with
398 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// 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: --harmony-import-attributes | ||
|
||
import { life } from 'modules-skip-1.mjs' with { }; | ||
|
||
assertEquals(42, life()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// 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: --harmony-import-attributes | ||
|
||
import json from 'modules-skip-1.json' with { type: 'json' }; | ||
|
||
assertEquals(42, json.life); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// 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: --harmony-import-attributes | ||
|
||
import {life} from 'modules-skip-imports-json-1.mjs'; | ||
|
||
assertEquals(42, life()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// 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: --harmony-import-attributes | ||
|
||
import json from 'modules-skip-1.json' with { type: 'json', notARealAssertion: 'value'}; | ||
|
||
assertEquals(42, json.life); |
12 changes: 12 additions & 0 deletions
12
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-1.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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-attributes | ||
|
||
var life; | ||
import('modules-skip-1.mjs', { }).then(namespace => life = namespace.life()); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals(42, life); |
19 changes: 19 additions & 0 deletions
19
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-10.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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-attributes | ||
|
||
var result1; | ||
var result2; | ||
import('modules-skip-1.json', { get with() { throw 'bad \'with\' getter!'; } }).then( | ||
() => assertUnreachable('Should have failed due to throwing getter'), | ||
error => result1 = error); | ||
import('modules-skip-1.json', { with: { get assertionKey() { throw 'bad \'assertionKey\' getter!'; } } }).then( | ||
() => assertUnreachable('Should have failed due to throwing getter'), | ||
error => result2 = error); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals('bad \'with\' getter!', result1); | ||
assertEquals('bad \'assertionKey\' getter!', result2); |
19 changes: 19 additions & 0 deletions
19
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-11.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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-attributes --harmony-top-level-await | ||
|
||
var life1; | ||
var life2; | ||
import('modules-skip-1.json', { with: { type: 'json' } }).then( | ||
namespace => life1 = namespace.default.life); | ||
|
||
// Try loading the same module a second time. | ||
import('modules-skip-1.json', { with: { type: 'json' } }).then( | ||
namespace => life2 = namespace.default.life); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals(42, life1); | ||
assertEquals(42, life2); |
26 changes: 26 additions & 0 deletions
26
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-12.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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-attributes | ||
|
||
let result1; | ||
let result2; | ||
|
||
let badAssertProxy1 = new Proxy({}, { ownKeys() { throw "bad ownKeys!"; } }); | ||
import('./modules-skip-1.mjs', { with: badAssertProxy1 }).then( | ||
() => assertUnreachable('Should have failed due to throwing ownKeys'), | ||
error => result1 = error); | ||
|
||
let badAssertProxy2 = new Proxy( | ||
{foo: "bar"}, | ||
{ getOwnPropertyDescriptor() { throw "bad getOwnPropertyDescriptor!"; } }); | ||
import('./modules-skip-1.mjs', { with: badAssertProxy2 }).then( | ||
() => assertUnreachable( | ||
'Should have failed due to throwing getOwnPropertyDescriptor'), | ||
error => result2 = error); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals('bad ownKeys!', result1); | ||
assertEquals('bad getOwnPropertyDescriptor!', result2); |
26 changes: 26 additions & 0 deletions
26
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-13.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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-attributes | ||
|
||
let getters = 0; | ||
let result; | ||
|
||
import('./modules-skip-1.mjs', { with: { | ||
get attr1() { | ||
getters++; | ||
return {}; | ||
}, | ||
get attr2() { | ||
getters++; | ||
return {}; | ||
}, | ||
} }).then( | ||
() => assertUnreachable('Should have failed due to invalid attributes values'), | ||
error => result = error); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals(2, getters); | ||
assertInstanceof(result, TypeError); |
13 changes: 13 additions & 0 deletions
13
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-2.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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-attributes | ||
|
||
var life; | ||
import('modules-skip-1.mjs', { with: { } }).then( | ||
namespace => life = namespace.life()); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals(42, life); |
13 changes: 13 additions & 0 deletions
13
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-3.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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-attributes | ||
|
||
var life; | ||
import('modules-skip-1.json', { with: { type: 'json' } }).then( | ||
namespace => life = namespace.default.life); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals(42, life); |
14 changes: 14 additions & 0 deletions
14
deps/v8/test/mjsunit/harmony/modules-import-attributes-dynamic-4.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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-attributes | ||
|
||
var result; | ||
import('modules-skip-1.json', { with: { type: 'notARealType' } }).then( | ||
() => assertUnreachable('Should have failed due to bad module type'), | ||
error => result = error.message); | ||
|
||
%PerformMicrotaskCheckpoint(); | ||
|
||
assertEquals('Invalid module type was asserted', result); |
Oops, something went wrong.