Skip to content

Commit 6dfa380

Browse files
committed
Turns out extends + super() is unsafe eval after all
1 parent 64fc722 commit 6dfa380

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/signalizejs/src/modules/signal.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default () => {
44
* @template T
55
* @type {import('../../types/modules/signal').Signal<T>}
66
*/
7-
class Signal extends Function {
7+
class Signal {
88
/** @type {T} */
99
value;
1010

@@ -17,19 +17,21 @@ export default () => {
1717

1818
/** @param {T} defaultValue */
1919
constructor(defaultValue) {
20-
super();
2120
this.value = defaultValue;
2221

23-
return new Proxy(this, {
24-
apply: (target, thisArg, args) => {
25-
if (args.length === 1) {
26-
this.#set(args[0]);
27-
return this.value;
28-
}
29-
30-
return this.#get();
22+
// In order to make signal callable and to be able to check if created signal is instanceof Signal
23+
// We have to create this function and bind a protype of the Signal to it
24+
const callable = (...args) => {
25+
if (args.length === 1) {
26+
this.#set(args[0]);
27+
return this.value;
3128
}
32-
});
29+
return this.#get();
30+
};
31+
32+
Object.setPrototypeOf(callable, this);
33+
34+
return callable;
3335
}
3436

3537
/**

0 commit comments

Comments
 (0)