2021-08-27 23:47:49 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const { rejects } = require('assert');
|
|
|
|
|
|
|
|
const jsModuleDataUrl = 'data:text/javascript,export{}';
|
|
|
|
const jsonModuleDataUrl = 'data:application/json,""';
|
|
|
|
|
|
|
|
async function test() {
|
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import('data:text/css,', { with: { type: 'css' } }),
|
2020-11-30 16:03:30 +00:00
|
|
|
{ code: 'ERR_UNKNOWN_MODULE_FORMAT' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import('data:text/css,', { with: { unsupportedAttribute: 'value' } }),
|
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
|
|
|
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import(jsModuleDataUrl, { with: { type: 'json' } }),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
2023-11-19 21:22:49 +00:00
|
|
|
await rejects(
|
|
|
|
import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }),
|
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
|
|
|
|
);
|
|
|
|
|
2021-08-27 23:47:49 +00:00
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import(jsModuleDataUrl, { with: { type: 'unsupported' } }),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
|
|
|
import(jsonModuleDataUrl),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import(jsonModuleDataUrl, { with: {} }),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import(jsonModuleDataUrl, { with: { foo: 'bar' } }),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
2023-10-14 03:52:38 +00:00
|
|
|
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
|
2023-10-18 14:27:55 +00:00
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
|
2021-08-27 23:47:49 +00:00
|
|
|
);
|
2024-04-19 00:01:24 +00:00
|
|
|
|
|
|
|
await rejects(
|
|
|
|
import(jsonModuleDataUrl, { assert: { type: 'json' } }),
|
|
|
|
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
|
|
|
|
);
|
|
|
|
|
|
|
|
await rejects(
|
|
|
|
import(`data:text/javascript,import${JSON.stringify(jsonModuleDataUrl)}assert{type:"json"}`),
|
|
|
|
SyntaxError
|
|
|
|
);
|
2021-08-27 23:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test().then(common.mustCall());
|