From 48f9069f3a443204fb20d5da468093265d03553c Mon Sep 17 00:00:00 2001 From: Geequlim Date: Fri, 2 Sep 2022 20:40:41 +0800 Subject: Rename JavaScript singleton to JavaScriptBridge --- doc/classes/@GlobalScope.xml | 4 +- doc/classes/JavaScript.xml | 79 ---------------------------------------- doc/classes/JavaScriptBridge.xml | 79 ++++++++++++++++++++++++++++++++++++++++ doc/classes/JavaScriptObject.xml | 16 ++++---- 4 files changed, 89 insertions(+), 89 deletions(-) delete mode 100644 doc/classes/JavaScript.xml create mode 100644 doc/classes/JavaScriptBridge.xml (limited to 'doc/classes') diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 71b0901b3d..e06385de62 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1275,8 +1275,8 @@ The [JavaClassWrapper] singleton. [b]Note:[/b] Only implemented on Android. - - The [JavaScript] singleton. + + The [JavaScriptBridge] singleton. [b]Note:[/b] Only implemented on the Web platform. diff --git a/doc/classes/JavaScript.xml b/doc/classes/JavaScript.xml deleted file mode 100644 index c838422e85..0000000000 --- a/doc/classes/JavaScript.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - Singleton that connects the engine with the browser's JavaScript context in Web export. - - - The JavaScript singleton is implemented only in the Web export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs. - [b]Note:[/b] This singleton can be disabled at build-time to improve security. By default, the JavaScript singleton is enabled. Official export templates also have the JavaScript singleton enabled. See [url=$DOCS_URL/development/compiling/compiling_for_web.html]Compiling for the Web[/url] in the documentation for more information. - - - $DOCS_URL/tutorials/export/exporting_for_web.html#calling-javascript-from-script - - - - - - - Creates a reference to a [Callable] that can be used as a callback by JavaScript. The reference must be kept until the callback happens, or it won't be called at all. See [JavaScriptObject] for usage. - - - - - - - Creates a new JavaScript object using the [code]new[/code] constructor. The [param object] must a valid property of the JavaScript [code]window[/code]. See [JavaScriptObject] for usage. - - - - - - - - - Prompts the user to download a file containing the specified [param buffer]. The file will have the given [param name] and [param mime] type. - [b]Note:[/b] The browser may override the [url=https://en.wikipedia.org/wiki/Media_type]MIME type[/url] provided based on the file [param name]'s extension. - [b]Note:[/b] Browsers might block the download if [method download_buffer] is not being called from a user interaction (e.g. button click). - [b]Note:[/b] Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession. - - - - - - - - Execute the string [param code] as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code]eval()[/code]. - If [param use_global_execution_context] is [code]true[/code], the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment. - - - - - - - Returns an interface to a JavaScript object that can be used by scripts. The [param interface] must be a valid property of the JavaScript [code]window[/code]. The callback must accept a single [Array] argument, which will contain the JavaScript [code]arguments[/code]. See [JavaScriptObject] for usage. - - - - - - Returns [code]true[/code] if a new version of the progressive web app is waiting to be activated. - [b]Note:[/b] Only relevant when exported as a Progressive Web App. - - - - - - Performs the live update of the progressive web app. Forcing the new version to be installed and the page to be reloaded. - [b]Note:[/b] Your application will be [b]reloaded in all browser tabs[/b]. - [b]Note:[/b] Only relevant when exported as a Progressive Web App and [method pwa_needs_update] returns [code]true[/code]. - - - - - - - Emitted when an update for this progressive web app has been detected but is waiting to be activated because a previous version is active. See [method pwa_update] to force the update to take place immediately. - - - - diff --git a/doc/classes/JavaScriptBridge.xml b/doc/classes/JavaScriptBridge.xml new file mode 100644 index 0000000000..5e36b5cc80 --- /dev/null +++ b/doc/classes/JavaScriptBridge.xml @@ -0,0 +1,79 @@ + + + + Singleton that connects the engine with the browser's JavaScript context in Web export. + + + The JavaScriptBridge singleton is implemented only in the Web export. It's used to access the browser's JavaScript context. This allows interaction with embedding pages or calling third-party JavaScript APIs. + [b]Note:[/b] This singleton can be disabled at build-time to improve security. By default, the JavaScriptBridge singleton is enabled. Official export templates also have the JavaScriptBridge singleton enabled. See [url=$DOCS_URL/development/compiling/compiling_for_web.html]Compiling for the Web[/url] in the documentation for more information. + + + $DOCS_URL/tutorials/export/exporting_for_web.html#calling-javascript-from-script + + + + + + + Creates a reference to a [Callable] that can be used as a callback by JavaScript. The reference must be kept until the callback happens, or it won't be called at all. See [JavaScriptObject] for usage. + + + + + + + Creates a new JavaScript object using the [code]new[/code] constructor. The [param object] must a valid property of the JavaScript [code]window[/code]. See [JavaScriptObject] for usage. + + + + + + + + + Prompts the user to download a file containing the specified [param buffer]. The file will have the given [param name] and [param mime] type. + [b]Note:[/b] The browser may override the [url=https://en.wikipedia.org/wiki/Media_type]MIME type[/url] provided based on the file [param name]'s extension. + [b]Note:[/b] Browsers might block the download if [method download_buffer] is not being called from a user interaction (e.g. button click). + [b]Note:[/b] Browsers might ask the user for permission or block the download if multiple download requests are made in a quick succession. + + + + + + + + Execute the string [param code] as JavaScript code within the browser window. This is a call to the actual global JavaScript function [code]eval()[/code]. + If [param use_global_execution_context] is [code]true[/code], the code will be evaluated in the global execution context. Otherwise, it is evaluated in the execution context of a function within the engine's runtime environment. + + + + + + + Returns an interface to a JavaScript object that can be used by scripts. The [param interface] must be a valid property of the JavaScript [code]window[/code]. The callback must accept a single [Array] argument, which will contain the JavaScript [code]arguments[/code]. See [JavaScriptObject] for usage. + + + + + + Returns [code]true[/code] if a new version of the progressive web app is waiting to be activated. + [b]Note:[/b] Only relevant when exported as a Progressive Web App. + + + + + + Performs the live update of the progressive web app. Forcing the new version to be installed and the page to be reloaded. + [b]Note:[/b] Your application will be [b]reloaded in all browser tabs[/b]. + [b]Note:[/b] Only relevant when exported as a Progressive Web App and [method pwa_needs_update] returns [code]true[/code]. + + + + + + + Emitted when an update for this progressive web app has been detected but is waiting to be activated because a previous version is active. See [method pwa_update] to force the update to take place immediately. + + + + diff --git a/doc/classes/JavaScriptObject.xml b/doc/classes/JavaScriptObject.xml index e279acf5a4..26792bd19e 100644 --- a/doc/classes/JavaScriptObject.xml +++ b/doc/classes/JavaScriptObject.xml @@ -1,27 +1,27 @@ - A wrapper class for native JavaScript objects. + A wrapper class for web native JavaScript objects. - JavaScriptObject is used to interact with JavaScript objects retrieved or created via [method JavaScript.get_interface], [method JavaScript.create_object], or [method JavaScript.create_callback]. + JavaScriptObject is used to interact with JavaScript objects retrieved or created via [method JavaScriptBridge.get_interface], [method JavaScriptBridge.create_object], or [method JavaScriptBridge.create_callback]. Example: [codeblock] extends Node - var _my_js_callback = JavaScript.create_callback(self, "myCallback") # This reference must be kept - var console = JavaScript.get_interface("console") + var _my_js_callback = JavaScriptBridge.create_callback(self, "myCallback") # This reference must be kept + var console = JavaScriptBridge.get_interface("console") func _init(): - var buf = JavaScript.create_object("ArrayBuffer", 10) # new ArrayBuffer(10) + var buf = JavaScriptBridge.create_object("ArrayBuffer", 10) # new ArrayBuffer(10) print(buf) # prints [JavaScriptObject:OBJECT_ID] - var uint8arr = JavaScript.create_object("Uint8Array", buf) # new Uint8Array(buf) + var uint8arr = JavaScriptBridge.create_object("Uint8Array", buf) # new Uint8Array(buf) uint8arr[1] = 255 prints(uint8arr[1], uint8arr.byteLength) # prints 255 10 console.log(uint8arr) # prints in browser console "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]" - # Equivalent of JavaScript: Array.from(uint8arr).forEach(myCallback) - JavaScript.get_interface("Array").from(uint8arr).forEach(_my_js_callback) + # Equivalent of JavaScriptBridge: Array.from(uint8arr).forEach(myCallback) + JavaScriptBridge.get_interface("Array").from(uint8arr).forEach(_my_js_callback) func myCallback(args): # Will be called with the parameters passed to the "forEach" callback -- cgit v1.2.3