Skip to content

Commit

Permalink
fix wrapping object with null prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFoxPro committed Sep 15, 2024
1 parent e4b2c66 commit a2be161
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/solid/store/src/mutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function wrap<T extends StoreNode>(value: T): T {

const proto = Object.getPrototypeOf(value);
const isClass =
proto !== null &&
value !== null &&
typeof value === "object" &&
!Array.isArray(value) &&
Expand Down
6 changes: 6 additions & 0 deletions packages/solid/store/test/mutable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { createRoot, createSignal, createMemo, batch, createEffect } from "../..
import { Accessor, Setter } from "../../types";
import { createMutable, unwrap, $RAW } from "../src";

test("Object.create(null) is allowed", () => {
const user = createMutable(Object.assign(Object.create(null), { name: "John" }));
expect(user.name).toBe("John");
});

describe("State Mutability", () => {

test("Setting a property", () => {
const user = createMutable({ name: "John" });
expect(user.name).toBe("John");
Expand Down

0 comments on commit a2be161

Please sign in to comment.