Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/workerd/api/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ wd_test(
data = ["actor-alarms-name-test.js"],
)

wd_test(
src = "temporal-test.wd-test",
data = ["temporal-test.js"],
)

wd_test(
src = "tail-worker-test.wd-test",
args = [
Expand Down
35 changes: 31 additions & 4 deletions src/workerd/api/tests/temporal-hidden-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,42 @@
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
// https://opensource.org/licenses/Apache-2.0

// Verifies that the `no_temporal` compatibility flag removes the Temporal API.
//
// V8 installs Temporal on every context, because --harmony-temporal is
// process-wide and cannot vary per isolate. Gating it per Worker therefore
// means deleting what V8 already installed, so the absence asserted here is
// the result of jsg::deleteTemporalGlobals() running at context creation
// rather than of V8 declining to install anything.

import { strictEqual } from 'node:assert';

// V8 is built with Temporal, which it enables by default; workerd turns it off with
// --noharmony-temporal so the API surface stays unchanged.
export const temporalIsHidden = {
export const temporalGlobalIsAbsent = {
test() {
// `typeof` on an undeclared identifier evaluates to "undefined" rather
// than throwing, which is exactly the check applications use to decide
// whether to install a polyfill. It is the property that matters to them,
// so it is the property asserted here.
strictEqual(typeof Temporal, 'undefined');

// V8 installs the global as a lazy accessor with replace-on-access, so it
// would still be present as a property even if nothing had read it. Check
// for the property too, not just for a successful read.
strictEqual('Temporal' in globalThis, false);
strictEqual(Date.prototype.toTemporalInstant, undefined);
strictEqual(Object.hasOwn(globalThis, 'Temporal'), false);
},
};

export const dateBridgeIsAbsent = {
test() {
// Genesis::InitializeGlobal_harmony_temporal() installs
// Date.prototype.toTemporalInstant alongside the global, so it is a second
// route into the API and has to be absent as well.
strictEqual(typeof Date.prototype.toTemporalInstant, 'undefined');
strictEqual('toTemporalInstant' in Date.prototype, false);

// Date itself must be otherwise untouched by the deletion.
strictEqual(new Date(0).getTime(), 0);
strictEqual(typeof Date.now(), 'number');
},
};
2 changes: 1 addition & 1 deletion src/workerd/api/tests/temporal-hidden-test.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const unitTests :Workerd.Config = (
modules = [
(name = "worker", esModule = embed "temporal-hidden-test.js")
],
compatibilityFlags = ["nodejs_compat"],
compatibilityFlags = ["nodejs_compat", "no_temporal"],
)
),
],
Expand Down
Loading
Loading