From bcdc613df785aeec154ea8794050244f64aa11da Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Tue, 23 Oct 2018 18:42:11 -0400 Subject: [PATCH] Add case for custom toprimitive operations --- .../dynamic-import/custom-primitive.js | 32 +++++++++++++++++++ .../dynamic-import/custom-tostring_FIXTURE.js | 6 ++++ .../dynamic-import/custom-valueof_FIXTURE.js | 6 ++++ 3 files changed, 44 insertions(+) create mode 100644 test/language/expressions/dynamic-import/custom-primitive.js create mode 100644 test/language/expressions/dynamic-import/custom-tostring_FIXTURE.js create mode 100644 test/language/expressions/dynamic-import/custom-valueof_FIXTURE.js diff --git a/test/language/expressions/dynamic-import/custom-primitive.js b/test/language/expressions/dynamic-import/custom-primitive.js new file mode 100644 index 0000000000..eee1707be5 --- /dev/null +++ b/test/language/expressions/dynamic-import/custom-primitive.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + Import a custom toString and valueOf bindings +esid: sec-finishdynamicimport +info: | + Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) + + 2. Otherwise, + a. Assert: completion is a normal completion and completion.[[Value]] is undefined. + b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). + c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. + d. Let namespace be GetModuleNamespace(moduleRecord). + ... + f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). +flags: [async] +features: [dynamic-import] +---*/ + +async function fn() { + const str = await import('./custom-tostring_FIXTURE.js'); + const value = await import('./custom-valueof_FIXTURE.js'); + + assert.sameValue(String(str), '1612', 'namespace uses the imported toString'); + assert.sameValue(Number(str), 1612, 'namespace fallsback to toString as its prototype is null'); + + assert.sameValue(Number(value), 42, 'namespace uses the imported valueOf'); + assert.sameValue(String(value), '42', 'namespace fallsback to valueOf as its prototype is null'); +} + +fn().then($DONE, $DONE); diff --git a/test/language/expressions/dynamic-import/custom-tostring_FIXTURE.js b/test/language/expressions/dynamic-import/custom-tostring_FIXTURE.js new file mode 100644 index 0000000000..f077ef7fcd --- /dev/null +++ b/test/language/expressions/dynamic-import/custom-tostring_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export function toString() { + return '1612'; +} diff --git a/test/language/expressions/dynamic-import/custom-valueof_FIXTURE.js b/test/language/expressions/dynamic-import/custom-valueof_FIXTURE.js new file mode 100644 index 0000000000..8737f5c461 --- /dev/null +++ b/test/language/expressions/dynamic-import/custom-valueof_FIXTURE.js @@ -0,0 +1,6 @@ +// Copyright (C) 2018 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +export function valueOf() { + return 42; +}