From a54a2d65e16cea409c8a876f517451d3168da13b Mon Sep 17 00:00:00 2001
From: David Snopek <dsnopek@gmail.com>
Date: Sat, 26 Sep 2020 17:15:21 -0500
Subject: Add support for WebXR

---
 platform/javascript/.eslintrc.libs.js     |  3 +++
 platform/javascript/SCsub                 | 10 ++++++++++
 platform/javascript/detect.py             |  4 +++-
 platform/javascript/emscripten_helpers.py | 12 ++++++++++++
 4 files changed, 28 insertions(+), 1 deletion(-)

(limited to 'platform/javascript')

diff --git a/platform/javascript/.eslintrc.libs.js b/platform/javascript/.eslintrc.libs.js
index e5f0c3d147..81b1b8c864 100644
--- a/platform/javascript/.eslintrc.libs.js
+++ b/platform/javascript/.eslintrc.libs.js
@@ -18,5 +18,8 @@ module.exports = {
 		"GodotRuntime": true,
 		"GodotFS": true,
 		"IDHandler": true,
+		"Browser": true,
+		"GL": true,
+		"XRWebGLLayer": true,
 	},
 };
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index 7a8005fe30..1d3f96a6b8 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -67,6 +67,16 @@ else:
 
 sys_env.Depends(build[0], sys_env["JS_LIBS"])
 
+if "JS_PRE" in env:
+    for js in env["JS_PRE"]:
+        env.Append(LINKFLAGS=["--pre-js", env.File(js).path])
+    env.Depends(build, env["JS_PRE"])
+
+if "JS_EXTERNS" in env:
+    for ext in env["JS_EXTERNS"]:
+        env["ENV"]["EMCC_CLOSURE_ARGS"] += " --externs " + ext.path
+    env.Depends(build, env["JS_EXTERNS"])
+
 engine = [
     "js/engine/preloader.js",
     "js/engine/utils.js",
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index d53c774e77..7d501e94b2 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -1,7 +1,7 @@
 import os
 import sys
 
-from emscripten_helpers import run_closure_compiler, create_engine_file, add_js_libraries
+from emscripten_helpers import run_closure_compiler, create_engine_file, add_js_libraries, add_js_pre, add_js_externs
 from methods import get_compiler_version
 from SCons.Util import WhereIs
 
@@ -133,6 +133,8 @@ def configure(env):
 
     # Add helper method for adding libraries.
     env.AddMethod(add_js_libraries, "AddJSLibraries")
+    env.AddMethod(add_js_pre, "AddJSPre")
+    env.AddMethod(add_js_externs, "AddJSExterns")
 
     # Add method that joins/compiles our Engine files.
     env.AddMethod(create_engine_file, "CreateEngineFile")
diff --git a/platform/javascript/emscripten_helpers.py b/platform/javascript/emscripten_helpers.py
index cc874c432e..278186e4c0 100644
--- a/platform/javascript/emscripten_helpers.py
+++ b/platform/javascript/emscripten_helpers.py
@@ -25,3 +25,15 @@ def add_js_libraries(env, libraries):
     if "JS_LIBS" not in env:
         env["JS_LIBS"] = []
     env.Append(JS_LIBS=env.File(libraries))
+
+
+def add_js_pre(env, js_pre):
+    if "JS_PRE" not in env:
+        env["JS_PRE"] = []
+    env.Append(JS_PRE=env.File(js_pre))
+
+
+def add_js_externs(env, externs):
+    if "JS_EXTERNS" not in env:
+        env["JS_EXTERNS"] = []
+    env.Append(JS_EXTERNS=env.File(externs))
-- 
cgit v1.2.3