spy,
} from "./dev-deps.js";
import {
+ defineOwnDataProperty,
+ defineOwnNonenumerableDataProperty,
defineOwnProperties,
defineOwnProperty,
deleteOwnProperty,
});
});
+describe("defineOwnDataProperty", () => {
+ it("[[Call]] defines the property", () => {
+ const obj = {};
+ defineOwnDataProperty(obj, "etaoin", "success");
+ assert(Object.hasOwn(obj, "etaoin"));
+ assertStrictEquals(obj.etaoin, "success");
+ });
+
+ it("[[Call]] defines a configurable, enumerable, writable property", () => {
+ const obj = {};
+ defineOwnDataProperty(obj, "etaoin", "success");
+ assertEquals(
+ Object.getOwnPropertyDescriptor(obj, "etaoin"),
+ {
+ configurable: true,
+ enumerable: true,
+ value: "success",
+ writable: true,
+ },
+ );
+ });
+
+ it("[[Call]] returns the provided object", () => {
+ const obj = {};
+ assertStrictEquals(
+ defineOwnDataProperty(obj, "etaoin", null),
+ obj,
+ );
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() => new defineOwnDataProperty(obj, "etaoin", null));
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(defineOwnDataProperty.length, 3);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ defineOwnDataProperty.name,
+ "defineOwnDataProperty",
+ );
+ });
+ });
+});
+
+describe("defineOwnNonenumerableDataProperty", () => {
+ it("[[Call]] defines the property", () => {
+ const obj = {};
+ defineOwnNonenumerableDataProperty(obj, "etaoin", "success");
+ assert(Object.hasOwn(obj, "etaoin"));
+ assertStrictEquals(obj.etaoin, "success");
+ });
+
+ it("[[Call]] defines a configurable, non·enumerable, writable property", () => {
+ const obj = {};
+ defineOwnNonenumerableDataProperty(obj, "etaoin", "success");
+ assertEquals(
+ Object.getOwnPropertyDescriptor(obj, "etaoin"),
+ {
+ configurable: true,
+ enumerable: false,
+ value: "success",
+ writable: true,
+ },
+ );
+ });
+
+ it("[[Call]] returns the provided object", () => {
+ const obj = {};
+ assertStrictEquals(
+ defineOwnNonenumerableDataProperty(obj, "etaoin", null),
+ obj,
+ );
+ });
+
+ it("[[Construct]] throws an error", () => {
+ assertThrows(() =>
+ new defineOwnNonenumerableDataProperty(obj, "etaoin", null)
+ );
+ });
+
+ describe(".length", () => {
+ it("[[Get]] returns the correct length", () => {
+ assertStrictEquals(defineOwnNonenumerableDataProperty.length, 3);
+ });
+ });
+
+ describe(".name", () => {
+ it("[[Get]] returns the correct name", () => {
+ assertStrictEquals(
+ defineOwnNonenumerableDataProperty.name,
+ "defineOwnNonenumerableDataProperty",
+ );
+ });
+ });
+});
+
describe("defineOwnProperty", () => {
it("[[Call]] defines the property", () => {
const obj = {};
defineOwnProperty(obj, "etaoin", {});
- assert("etaoin" in obj);
+ assert(Object.hasOwn(obj, "etaoin"));
});
it("[[Call]] returns the provided object", () => {
);
});
+ it("[[Call]] preserves data properties", () => {
+ const properties = {
+ implied: {
+ configurable: false,
+ enumerable: true,
+ },
+ writable: {
+ configurable: false,
+ enumerable: true,
+ value: "etaoin",
+ writable: true,
+ },
+ nonwritable: {
+ configurable: false,
+ enumerable: true,
+ value: "shrdlu",
+ writable: false,
+ },
+ };
+ assertEquals(
+ Object.getOwnPropertyDescriptors(
+ frozenCopy(Object.create(null, properties)),
+ ),
+ {
+ implied: {
+ ...properties.implied,
+ value: undefined,
+ writable: false,
+ },
+ writable: { ...properties.writable, writable: false },
+ nonwritable: properties.nonwritable,
+ },
+ );
+ });
+
it("[[Call]] does not copy properties on the prototype", () => {
assert(
!("failure" in
- frozenCopy(Object.create({ failure: undefined }), {
- data: {
- configurable: true,
- value: undefined,
- writable: true,
- },
- accessor: { configurable: true, get: undefined },
- })),
+ frozenCopy(Object.create({ failure: undefined }))),
);
});