summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-05-08 16:55:01 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-05-10 18:22:48 +0200
commitd2eef397312d1c142d95c2aef0ff3d5aeee6495a (patch)
tree3d5564f2769337c4eee0899d245b246e526ea542 /platform
parent7411e7fd37eb169b0f0675d4e4c2ec28786aec1b (diff)
Fix Closure compiler build, python style.
Move copyToFS into utils.js library included with '--pre-js'.
Diffstat (limited to 'platform')
-rw-r--r--platform/javascript/SCsub27
-rw-r--r--platform/javascript/detect.py6
-rw-r--r--platform/javascript/display_server_javascript.cpp10
-rw-r--r--platform/javascript/engine/engine.js6
-rw-r--r--platform/javascript/engine/utils.js18
-rw-r--r--platform/javascript/native/http_request.js (renamed from platform/javascript/http_request.js)0
-rw-r--r--platform/javascript/native/id_handler.js (renamed from platform/javascript/id_handler.js)0
-rw-r--r--platform/javascript/native/utils.js48
-rw-r--r--platform/javascript/os_javascript.cpp2
9 files changed, 73 insertions, 44 deletions
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index 172e15473b..dcf9a46bf9 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -18,18 +18,19 @@ if env["threads_enabled"]:
build = env.add_program(build_targets, javascript_files)
js_libraries = [
- "http_request.js",
+ "native/http_request.js",
]
for lib in js_libraries:
env.Append(LINKFLAGS=["--js-library", env.File(lib).path])
env.Depends(build, js_libraries)
-js_modules = [
- "id_handler.js",
+js_pre = [
+ "native/id_handler.js",
+ "native/utils.js",
]
-for module in js_modules:
- env.Append(LINKFLAGS=["--pre-js", env.File(module).path])
-env.Depends(build, js_modules)
+for js in js_pre:
+ env.Append(LINKFLAGS=["--pre-js", env.File(js).path])
+env.Depends(build, js_pre)
engine = [
"engine/preloader.js",
@@ -49,16 +50,12 @@ js_wrapped = env.Textfile("#bin/godot", [env.File(f) for f in wrap_list], TEXTFI
zip_dir = env.Dir("#bin/.javascript_zip")
binary_name = "godot.tools" if env["tools"] else "godot"
out_files = [
- zip_dir.File(binary_name + ".js"),
- zip_dir.File(binary_name + ".wasm"),
- zip_dir.File(binary_name + ".html")
+ zip_dir.File(binary_name + ".js"),
+ zip_dir.File(binary_name + ".wasm"),
+ zip_dir.File(binary_name + ".html"),
]
html_file = "#misc/dist/html/full-size.html"
-in_files = [
- js_wrapped,
- build[1],
- html_file
-]
+in_files = [js_wrapped, build[1], html_file]
if env["threads_enabled"]:
in_files.append(build[2])
out_files.append(zip_dir.File(binary_name + ".worker.js"))
@@ -69,5 +66,5 @@ env.Zip(
zip_files,
ZIPROOT=zip_dir,
ZIPSUFFIX="${PROGSUFFIX}${ZIPSUFFIX}",
- ZIPCOMSTR="Archving $SOURCES as $TARGET"
+ ZIPCOMSTR="Archving $SOURCES as $TARGET",
)
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 5a0f8503f9..81287cead8 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -2,6 +2,7 @@ import os
from emscripten_helpers import parse_config, run_closure_compiler, create_engine_file
+
def is_active():
return True
@@ -16,6 +17,7 @@ def can_build():
def get_opts():
from SCons.Variables import BoolVariable
+
return [
# eval() can be a security concern, so it can be disabled.
BoolVariable("javascript_eval", "Enable JavaScript eval interface", True),
@@ -55,7 +57,7 @@ def configure(env):
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
# Retain function names for backtraces at the cost of file size.
env.Append(LINKFLAGS=["--profiling-funcs"])
- else: # "debug"
+ else: # "debug"
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
env.Append(CCFLAGS=["-O1", "-g"])
env.Append(LINKFLAGS=["-O1", "-g"])
@@ -164,6 +166,6 @@ def configure(env):
env.Append(LINKFLAGS=["-s", "OFFSCREEN_FRAMEBUFFER=1"])
# callMain for manual start, FS for preloading, PATH and ERRNO_CODES for BrowserFS.
- env.Append(LINKFLAGS=["-s", "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'FS', 'PATH', 'ERRNO_CODES']"])
+ env.Append(LINKFLAGS=["-s", "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain', 'FS', 'PATH']"])
# Add code that allow exiting runtime.
env.Append(LINKFLAGS=["-s", "EXIT_RUNTIME=1"])
diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp
index 13615bebe1..103bbf4ead 100644
--- a/platform/javascript/display_server_javascript.cpp
+++ b/platform/javascript/display_server_javascript.cpp
@@ -820,16 +820,16 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
EM_ASM({
const canvas = Module['canvas'];
var enc = new TextEncoder("utf-8");
- buffer = new Uint8Array(enc.encode(canvas.id));
- var len = buffer.length*buffer.BYTES_PER_ELEMENT;
- var out = Module._malloc(len);
- Module.HEAPU8.set(buffer, out);
+ var buffer = new Uint8Array(enc.encode(canvas.id));
+ var len = buffer.byteLength;
+ var out = _malloc(len);
+ HEAPU8.set(buffer, out);
ccall("_set_canvas_id",
"void",
["number", "number"],
[out, len]
);
- Module._free(out);
+ _free(out);
});
/* clang-format on */
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js
index aecc6b9432..d709422abb 100644
--- a/platform/javascript/engine/engine.js
+++ b/platform/javascript/engine/engine.js
@@ -82,7 +82,7 @@ Function('return this')()['Engine'] = (function() {
var me = this;
return me.init().then(function() {
if (!me.rtenv) {
- reject(new Error('The engine must be initialized before it can be started'));
+ return Promise.reject(new Error('The engine must be initialized before it can be started'));
}
if (!(me.canvas instanceof HTMLCanvasElement)) {
@@ -124,7 +124,7 @@ Function('return this')()['Engine'] = (function() {
}
return new Promise(function(resolve, reject) {
preloader.preloadedFiles.forEach(function(file) {
- Utils.copyToFS(me.rtenv['FS'], file.path, file.buffer);
+ me.rtenv['copyToFS'](file.path, file.buffer);
});
preloader.preloadedFiles.length = 0; // Clear memory
me.rtenv['callMain'](args);
@@ -217,7 +217,7 @@ Function('return this')()['Engine'] = (function() {
if (this.rtenv == null) {
throw new Error("Engine must be inited before copying files");
}
- Utils.copyToFS(this.rtenv['FS'], path, buffer);
+ this.rtenv['copyToFS'](path, buffer);
}
// Closure compiler exported engine methods.
diff --git a/platform/javascript/engine/utils.js b/platform/javascript/engine/utils.js
index fdff90a923..0c97b38199 100644
--- a/platform/javascript/engine/utils.js
+++ b/platform/javascript/engine/utils.js
@@ -27,24 +27,6 @@ var Utils = {
return instantiateWasm;
},
- copyToFS: function(fs, path, buffer) {
- var p = path.lastIndexOf("/");
- var dir = "/";
- if (p > 0) {
- dir = path.slice(0, path.lastIndexOf("/"));
- }
- try {
- fs.stat(dir);
- } catch (e) {
- if (e.errno !== 44) { // 'ENOENT', see https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/arch/emscripten/bits/errno.h
- throw e;
- }
- fs['mkdirTree'](dir);
- }
- // With memory growth, canOwn should be false.
- fs['writeFile'](path, new Uint8Array(buffer), {'flags': 'wx+'});
- },
-
findCanvas: function() {
var nodes = document.getElementsByTagName('canvas');
if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
diff --git a/platform/javascript/http_request.js b/platform/javascript/native/http_request.js
index f621689f9d..f621689f9d 100644
--- a/platform/javascript/http_request.js
+++ b/platform/javascript/native/http_request.js
diff --git a/platform/javascript/id_handler.js b/platform/javascript/native/id_handler.js
index 67d29075b8..67d29075b8 100644
--- a/platform/javascript/id_handler.js
+++ b/platform/javascript/native/id_handler.js
diff --git a/platform/javascript/native/utils.js b/platform/javascript/native/utils.js
new file mode 100644
index 0000000000..d45c6c3032
--- /dev/null
+++ b/platform/javascript/native/utils.js
@@ -0,0 +1,48 @@
+/*************************************************************************/
+/* utils.js */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+Module['copyToFS'] = function(path, buffer) {
+ var p = path.lastIndexOf("/");
+ var dir = "/";
+ if (p > 0) {
+ dir = path.slice(0, path.lastIndexOf("/"));
+ }
+ try {
+ FS.stat(dir);
+ } catch (e) {
+ if (e.errno !== ERRNO_CODES.ENOENT) { // 'ENOENT', see https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/arch/emscripten/bits/errno.h
+ throw e;
+ }
+ FS.mkdirTree(dir);
+ }
+ // With memory growth, canOwn should be false.
+ FS.writeFile(path, new Uint8Array(buffer), {'flags': 'wx+'});
+}
+
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 4b41ed5d02..205644ce51 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -71,7 +71,7 @@ void OS_JavaScript::initialize() {
char locale_ptr[16];
/* clang-format off */
EM_ASM({
- stringToUTF8(Module.locale, $0, 16);
+ stringToUTF8(Module['locale'], $0, 16);
}, locale_ptr);
/* clang-format on */
setenv("LANG", locale_ptr, true);