defineOwnProperties,
deleteOwnProperty,
frozenCopy,
+ getMethod,
+ getOwnPropertyKeys,
+ getPropertyValue,
+ hasProperty,
LazyLoader,
PropertyDescriptor,
setPropertyValue,
});
});
+describe("getMethod", () => {
+ it("[[Call]] gets a method", () => {
+ const method = () => {};
+ assertStrictEquals(getMethod({ method }, "method"), method);
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertEquals(getMethod("", "toString"), String.prototype.toString);
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => getMethod(null, "valueOf"));
+ assertThrows(() => getMethod(undefined, "valueOf"));
+ });
+
+ it("[[Call]] throws if the resulting value isn’t callable", () => {
+ assertThrows(() => getMethod({ "failure": true }, "failure"));
+ });
+});
+
+describe("getOwnPropertyKeys", () => {
+ it("[[Call]] gets own (but not inherited) property keys", () => {
+ assertEquals(getOwnPropertyKeys({ success: true }), ["success"]);
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertEquals(getOwnPropertyKeys("foo"), ["0", "1", "2", "length"]);
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => getOwnPropertyKeys(null));
+ assertThrows(() => getOwnPropertyKeys(undefined));
+ });
+});
+
+describe("getPropertyValue", () => {
+ it("[[Call]] gets property values on the provided object", () => {
+ assertStrictEquals(
+ getPropertyValue({ success: true }, "success"),
+ true,
+ );
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertStrictEquals(
+ getPropertyValue("", "toString"),
+ String.prototype.toString,
+ );
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => getPropertyValue(null, "valueOf"));
+ assertThrows(() => getPropertyValue(undefined, "valueOf"));
+ });
+});
+
+describe("hasProperty", () => {
+ it("[[Call]] gets whether a property exists on the provided object", () => {
+ assertStrictEquals(
+ hasProperty({ success: "etaoin" }, "success"),
+ true,
+ );
+ });
+
+ it("[[Call]] works for values coercible to objects", () => {
+ assertStrictEquals(hasProperty("", "toString"), true);
+ });
+
+ it("[[Call]] throws for null and undefined", () => {
+ assertThrows(() => hasProperty(null, "valueOf"));
+ assertThrows(() => hasProperty(undefined, "valueOf"));
+ });
+});
+
describe("setPropertyValue", () => {
it("[[Call]] sets the provided property on the provided object", () => {
const obj = {};
assertStrictEquals(toObject(obj), obj);
});
- it("returns a new object for nullish values", () => {
- assertEquals(toObject(null), {});
- assertEquals(toObject(void {}), {});
+ it("throws for nullish values", () => {
+ assertThrows(() => toObject(null));
+ assertThrows(() => toObject(void {}));
});
it("returns a wrapper object for other primitives", () => {