mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 15:34:29 +02:00
Add more cases for Dynamic Imports usage
- Add cases for mixing module and script code - Rename test case from return promise to thenable - Fix script code case with valid loaded fixture - Add a test to assert a promise return - Add case for specifier toString rejection - Add case for specifier toString - Test Assignment expression abrupt completion - Test Promise return
This commit is contained in:
parent
e1ff0bbe5c
commit
b0ec060e62
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
desc: import() from a ascript code can load a file with module code
|
||||||
|
template: default
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
// This is still valid in script code, and should not be valid for module code
|
||||||
|
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames
|
||||||
|
var smoosh; function smoosh() {}
|
||||||
|
|
||||||
|
//- import
|
||||||
|
import('./module-code_FIXTURE.js')
|
||||||
|
//- body
|
||||||
|
assert.sameValue(imported.default, 42);
|
||||||
|
assert.sameValue(imported.x, 'Test262');
|
||||||
|
assert.sameValue(imported.z, 42);
|
22
src/dynamic-import/eval-script-code-target.case
Normal file
22
src/dynamic-import/eval-script-code-target.case
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
desc: >
|
||||||
|
import() from a module code can load a file with script code, but the target
|
||||||
|
is resolved into a Module Record
|
||||||
|
info: |
|
||||||
|
Modules
|
||||||
|
|
||||||
|
Static Semantics: Early Errors
|
||||||
|
|
||||||
|
ModuleBody : ModuleItemList
|
||||||
|
- It is a Syntax Error if the LexicallyDeclaredNames of ModuleItemList containsany duplicate entries.
|
||||||
|
- It is a Syntax Error if any element of the LexicallyDeclaredNames of ModuleItemList also occurs in the VarDeclaredNames of ModuleItemList.
|
||||||
|
template: catch
|
||||||
|
flags: [module]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- import
|
||||||
|
import('./script-code_FIXTURE.js')
|
||||||
|
//- body
|
||||||
|
assert.sameValue(error.name, 'SyntaxError');
|
@ -2,7 +2,7 @@
|
|||||||
// Copyright (C) 2018 the V8 project authors. All rights reserved.
|
// Copyright (C) 2018 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
desc: Dynamic import() returns a Promise object.
|
desc: Dynamic import() returns a thenable object.
|
||||||
template: default
|
template: default
|
||||||
---*/
|
---*/
|
||||||
|
|
@ -11,4 +11,4 @@ template: syntax/valid
|
|||||||
var smoosh; function smoosh() {}
|
var smoosh; function smoosh() {}
|
||||||
|
|
||||||
//- import
|
//- import
|
||||||
import('./script-code-valid.js')
|
import('./empty_FIXTURE.js')
|
||||||
|
36
src/dynamic-import/specifier-tostring-abrupt-rejects.case
Normal file
36
src/dynamic-import/specifier-tostring-abrupt-rejects.case
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (C) 2018 Rick Waldron. All rights reserved.
|
||||||
|
// Copyright (C) 2018 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
desc: >
|
||||||
|
Abrupt from ToString(specifier) rejects the promise
|
||||||
|
esid: sec-moduleevaluation
|
||||||
|
info: |
|
||||||
|
Import Calls
|
||||||
|
|
||||||
|
Runtime Semantics: Evaluation
|
||||||
|
|
||||||
|
ImportCall : import(AssignmentExpression)
|
||||||
|
|
||||||
|
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
|
||||||
|
2. Let argRef be the result of evaluating AssignmentExpression.
|
||||||
|
3. Let specifier be ? GetValue(argRef).
|
||||||
|
4. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
5. Let specifierString be ToString(specifier).
|
||||||
|
6. IfAbruptRejectPromise(specifierString, promiseCapability).
|
||||||
|
7. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
|
||||||
|
8. Return promiseCapability.[[Promise]].
|
||||||
|
template: catch
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
const obj = {
|
||||||
|
toString() {
|
||||||
|
throw 'custom error';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- import
|
||||||
|
import(obj)
|
||||||
|
//- body
|
||||||
|
assert.sameValue(error, 'custom error');
|
38
src/dynamic-import/specifier-tostring.case
Normal file
38
src/dynamic-import/specifier-tostring.case
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2018 Rick Waldron. All rights reserved.
|
||||||
|
// Copyright (C) 2018 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
desc: >
|
||||||
|
ToString value of specifier
|
||||||
|
esid: sec-moduleevaluation
|
||||||
|
info: |
|
||||||
|
Import Calls
|
||||||
|
|
||||||
|
Runtime Semantics: Evaluation
|
||||||
|
|
||||||
|
ImportCall : import(AssignmentExpression)
|
||||||
|
|
||||||
|
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
|
||||||
|
2. Let argRef be the result of evaluating AssignmentExpression.
|
||||||
|
3. Let specifier be ? GetValue(argRef).
|
||||||
|
4. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
5. Let specifierString be ToString(specifier).
|
||||||
|
6. IfAbruptRejectPromise(specifierString, promiseCapability).
|
||||||
|
7. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
|
||||||
|
8. Return promiseCapability.[[Promise]].
|
||||||
|
template: default
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//- setup
|
||||||
|
const obj = {
|
||||||
|
toString() {
|
||||||
|
return './module-code_FIXTURE.js';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//- import
|
||||||
|
import(obj)
|
||||||
|
//- body
|
||||||
|
assert.sameValue(imported.default, 42);
|
||||||
|
assert.sameValue(imported.x, 'Test262');
|
||||||
|
assert.sameValue(imported.z, 42);
|
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
Return Abrupt from the GetValue evaluation on the given AssignmentExpression
|
||||||
|
esid: sec-import-call-runtime-semantics-evaluation
|
||||||
|
info: |
|
||||||
|
Import Calls
|
||||||
|
|
||||||
|
Runtime Semantics: Evaluation
|
||||||
|
|
||||||
|
ImportCall : import(AssignmentExpression)
|
||||||
|
|
||||||
|
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
|
||||||
|
2. Let argRef be the result of evaluating AssignmentExpression.
|
||||||
|
3. Let specifier be ? GetValue(argRef).
|
||||||
|
4. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
5. Let specifierString be ToString(specifier).
|
||||||
|
6. IfAbruptRejectPromise(specifierString, promiseCapability).
|
||||||
|
7. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
|
||||||
|
8. Return promiseCapability.[[Promise]].
|
||||||
|
features: [dynamic-import]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const obj = {
|
||||||
|
get err() {
|
||||||
|
throw new Test262Error('catpure this on evaluation')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
import(obj.err);
|
||||||
|
}, 'Custom Error getting property value');
|
||||||
|
|
||||||
|
assert.throws(ReferenceError, function() {
|
||||||
|
import(refErr);
|
||||||
|
}, 'bad reference');
|
@ -0,0 +1,7 @@
|
|||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
// This is still valid in script code and strict and non strict modes
|
||||||
|
// This is valid as module code
|
||||||
|
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames
|
||||||
|
var smoosh; function smoosh() {}
|
@ -0,0 +1,4 @@
|
|||||||
|
// Copyright (C) 2018 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
export var x = 1;
|
53
test/language/module-code/dynamic-import/returns-promise.js
Normal file
53
test/language/module-code/dynamic-import/returns-promise.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
description: >
|
||||||
|
ImportCall returns a promise
|
||||||
|
esid: sec-import-call-runtime-semantics-evaluation
|
||||||
|
info: |
|
||||||
|
Import Calls
|
||||||
|
|
||||||
|
Runtime Semantics: Evaluation
|
||||||
|
|
||||||
|
ImportCall : import(AssignmentExpression)
|
||||||
|
|
||||||
|
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
|
||||||
|
2. Let argRef be the result of evaluating AssignmentExpression.
|
||||||
|
3. Let specifier be ? GetValue(argRef).
|
||||||
|
4. Let promiseCapability be ! NewPromiseCapability(%Promise%).
|
||||||
|
5. Let specifierString be ToString(specifier).
|
||||||
|
6. IfAbruptRejectPromise(specifierString, promiseCapability).
|
||||||
|
7. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
|
||||||
|
8. Return promiseCapability.[[Promise]].
|
||||||
|
features: [dynamic-import]
|
||||||
|
includes: [fnGlobalObject.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const originalPromise = Promise;
|
||||||
|
|
||||||
|
fnGlobalObject().Promise = function() {
|
||||||
|
throw "This should not be called";
|
||||||
|
};
|
||||||
|
|
||||||
|
const p = import('./dynamic-import-module_FIXTURE.js');
|
||||||
|
|
||||||
|
assert.sameValue(p.constructor, originalPromise, 'constructor is %Promise%');
|
||||||
|
assert.sameValue(Object.getPrototypeOf(p), originalPromise.prototype, 'prototype is %PromisePrototype%');
|
||||||
|
assert.sameValue(p.then, originalPromise.prototype.then, 'preserves the original `then` method');
|
||||||
|
assert.sameValue(p.catch, originalPromise.prototype.catch, 'preserves the original `catch` method');
|
||||||
|
assert.sameValue(p.finally, originalPromise.prototype.finally, 'preserves the original `finally` method');
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Object.prototype.hasOwnProperty.call(p, 'then'), false,
|
||||||
|
'returned promise has no own property then'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Object.prototype.hasOwnProperty.call(p, 'catch'), false,
|
||||||
|
'returned promise has no own property catch'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Object.prototype.hasOwnProperty.call(p, 'finally'), false,
|
||||||
|
'returned promise has no own property finally'
|
||||||
|
);
|
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
const x = 'Test262';
|
||||||
|
const y = 42;
|
||||||
|
|
||||||
|
export default y;
|
||||||
|
export { x, y as z };
|
Loading…
x
Reference in New Issue
Block a user