-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create has handler and proxyhandlerevent
- Loading branch information
Showing
13 changed files
with
91 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Nexo from "../types/Nexo.js"; | ||
import ProxyEvent from "./ProxyEvent.js"; | ||
|
||
class ProxyHandlerEvent extends ProxyEvent { | ||
constructor( | ||
name: Nexo.proxy.handler, | ||
proxy: Nexo.Proxy, | ||
data?: Record<string, unknown>, | ||
) { | ||
super(`handler.${name}`, proxy, data); | ||
} | ||
} | ||
|
||
export default ProxyHandlerEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Nexo from "../../types/Nexo.js"; | ||
import { map } from "../../utils/index.js"; | ||
import ProxyHandlerEvent from "../ProxyHandlerEvent.js"; | ||
|
||
const has = (mock: Nexo.Mock, key: Nexo.objectKey): boolean => { | ||
const proxy = map.tracables.get(mock); | ||
const data = map.proxies.get(proxy); | ||
|
||
const { sandbox } = data; | ||
const scope = data.scope.deref(); | ||
|
||
const event = new ProxyHandlerEvent("has", proxy, { key }); | ||
|
||
scope.emit(event.name, event); | ||
|
||
if (event.defaultPrevented) { | ||
return event.returnValue === true; | ||
} | ||
|
||
return sandbox.has(key); | ||
}; | ||
|
||
export default has; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters