-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaScriptBridgeWrapper.gd
More file actions
47 lines (39 loc) · 1.35 KB
/
JavaScriptBridgeWrapper.gd
File metadata and controls
47 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Copyright (C) 2025 Egor Kostan
## SPDX-License-Identifier: GPL-3.0-or-later
## JavaScriptBridgeWrapper.gd
## Wrapper for JavaScriptBridge singleton methods to enable mocking in unit tests.
##
## Provides instance methods mirroring JavaScriptBridge static methods.
##
## Use this instead of direct JavaScriptBridge calls for testability.
class_name JavaScriptBridgeWrapper
extends RefCounted
func eval(code: String, global_exec: bool = false) -> Variant:
## Evaluates JavaScript code.
##
## Mirrors JavaScriptBridge.eval.
##
## :param code: The JavaScript code to evaluate.
## :type code: String
## :param global_exec: Whether to execute in global scope.
## :type global_exec: bool
## :rtype: Variant
return JavaScriptBridge.eval(code, global_exec)
func get_interface(interface: String) -> Variant:
## Gets a JavaScript interface.
##
## Mirrors JavaScriptBridge.get_interface.
##
## :param interface: The interface name (e.g., "window").
## :type interface: String
## :rtype: Variant
return JavaScriptBridge.get_interface(interface)
func create_callback(callable: Callable) -> Variant:
## Creates a JavaScript callback from a GDScript callable.
##
## Mirrors JavaScriptBridge.create_callback.
##
## :param callable: The GDScript callable to wrap.
## :type callable: Callable
## :rtype: Variant
return JavaScriptBridge.create_callback(callable)