v8/test/mjsunit/harmony/modules-import-meta.js
Jan Krems 8683248625 [modules] Optimize import.meta in the interpreter
Use an intrinsic for GetImportMetaObject and generate bytecode for the
case where import.meta has been initialized already. This way the
runtime method will only be called once per module.

Bug: v8:6693
Change-Id: If661e88e6accfb1c5795e37a80582d04f6dd87dd
Reviewed-on: https://chromium-review.googlesource.com/716536
Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48801}
2017-10-20 20:31:49 +00:00

45 lines
1.5 KiB
JavaScript

// Copyright 2017 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.
// MODULE
// Flags: --harmony-import-meta --no-lazy
import foreign, { url as otherUrl } from './modules-skip-export-import-meta.js';
assertEquals("object", typeof import.meta);
assertEquals(null, Object.getPrototypeOf(import.meta));
assertSame(import.meta, import.meta);
const loadImportMetaArrow = () => import.meta;
assertSame(loadImportMetaArrow(), import.meta);
function loadImportMetaFn() {
try {
throw new Error('force catch code path for nested context');
} catch (e) {
return import.meta;
}
}
loadImportMetaFn();
assertSame(loadImportMetaFn(), import.meta);
// This property isn't part of the spec itself but is mentioned as an example
assertMatches(/\/modules-import-meta\.js$/, import.meta.url);
import.meta.x = 42;
assertEquals(42, import.meta.x);
Object.assign(import.meta, { foo: "bar" })
assertEquals("bar", import.meta.foo);
// PerformEval parses its argument for the goal symbol Script. So the following
// should fail just as it does for every other Script context.
//
// See:
// https://github.com/tc39/proposal-import-meta/issues/7#issuecomment-329363083
assertThrows(() => eval('import.meta'), SyntaxError);
assertThrows(() => new Function('return import.meta;'), SyntaxError);
assertNotEquals(foreign, import.meta);
assertMatches(/\/modules-skip-export-import-meta\.js$/, foreign.url);
assertEquals(foreign.url, otherUrl);