Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/libbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ var LibraryBrowser = {
var canvasContainer = canvas.parentNode;
if (getFullscreenElement() === canvasContainer) {
canvas.exitFullscreen = Browser.exitFullscreen;
if (Browser.lockPointer) canvas.requestPointerLock();
if (Browser.lockPointer) canvas.requestPointerLock?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2020 optional chaining (?.) in Emscripten system libraries can cause compatibility issues with older JavaScript environments or build toolchains that do not downlevel modern JS syntax. It is safer and more backward-compatible to use standard conditional checks.

          if (Browser.lockPointer && canvas.requestPointerLock) canvas.requestPointerLock();

Browser.isFullscreen = true;
if (Browser.resizeCanvas) {
Browser.setFullscreenCanvasSize();
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libglfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ var LibraryGLFW = {
case 0x00034001: { // GLFW_CURSOR_NORMAL
win.inputModes[mode] = value;
canvas.removeEventListener('click', GLFW.onClickRequestPointerLock, true);
document.exitPointerLock();
document.exitPointerLock?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2020 optional chaining (?.) in Emscripten system libraries can cause compatibility issues with older JavaScript environments or build toolchains that do not downlevel modern JS syntax. It is safer and more backward-compatible to use standard conditional checks.

              if (document.exitPointerLock) document.exitPointerLock();

break;
}
case 0x00034002: { // GLFW_CURSOR_HIDDEN
Expand All @@ -1004,7 +1004,7 @@ var LibraryGLFW = {
case 0x00034003: { // GLFW_CURSOR_DISABLED
win.inputModes[mode] = value;
canvas.addEventListener('click', GLFW.onClickRequestPointerLock, true);
canvas.requestPointerLock();
canvas.requestPointerLock?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2020 optional chaining (?.) in Emscripten system libraries can cause compatibility issues with older JavaScript environments or build toolchains that do not downlevel modern JS syntax. It is safer and more backward-compatible to use standard conditional checks.

              if (canvas.requestPointerLock) canvas.requestPointerLock();

break;
}
default: {
Expand Down Expand Up @@ -1222,7 +1222,7 @@ var LibraryGLFW = {
var canvasContainer = canvas.parentNode;
if (getFullscreenElement() === canvasContainer) {
canvas.exitFullscreen = Browser.exitFullscreen;
if (Browser.lockPointer) canvas.requestPointerLock();
if (Browser.lockPointer) canvas.requestPointerLock?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2020 optional chaining (?.) in Emscripten system libraries can cause compatibility issues with older JavaScript environments or build toolchains that do not downlevel modern JS syntax. It is safer and more backward-compatible to use standard conditional checks.

          if (Browser.lockPointer && canvas.requestPointerLock) canvas.requestPointerLock();

Browser.isFullscreen = true;
if (Browser.resizeCanvas) {
Browser.setFullscreenCanvasSize();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/libsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,13 +1742,13 @@ var LibrarySDL = {
switch (toggle) {
case 0: // SDL_DISABLE
if (Browser.isFullscreen) { // only try to lock the pointer when in full screen mode
Browser.getCanvas().requestPointerLock();
Browser.getCanvas().requestPointerLock?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2020 optional chaining (?.) in Emscripten system libraries can cause compatibility issues with older JavaScript environments or build toolchains that do not downlevel modern JS syntax. It is safer and more backward-compatible to use standard conditional checks.

          if (Browser.getCanvas().requestPointerLock) Browser.getCanvas().requestPointerLock();

return 0;
}
// else return SDL_ENABLE to indicate the failure
return 1;
case 1: // SDL_ENABLE
document.exitPointerLock();
document.exitPointerLock?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using ES2020 optional chaining (?.) in Emscripten system libraries can cause compatibility issues with older JavaScript environments or build toolchains that do not downlevel modern JS syntax. It is safer and more backward-compatible to use standard conditional checks.

        if (document.exitPointerLock) document.exitPointerLock();

return 1;
case -1: // SDL_QUERY
return !Browser.pointerLock;
Expand Down
2 changes: 2 additions & 0 deletions test/browser/test_glfw3.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ int main() {
// glfwPollEvents();
// glfwWaitEvents();

assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
assert(glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_NORMAL);

// XXX: not implemented
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 272928,
"a.out.js": 272934,
"a.out.nodebug.wasm": 589443,
"total": 862371,
"total": 862377,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
6 changes: 6 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2841,6 +2841,12 @@ def test_glfw3_default_hints(self):
def test_glfw3(self, args, opts):
self.btest_exit('test_glfw3.c', cflags=['-sUSE_GLFW=3', '-lglfw', '-lGL'] + args + opts)

@requires_graphics_hardware
def test_glfw3_no_pointer_lock(self):
# Browsers without the Pointer Lock API, such as Safari on iOS
create_file('pre.js', 'delete Document.prototype.exitPointerLock; delete Element.prototype.requestPointerLock;')
self.btest_exit('test_glfw3.c', cflags=['-sUSE_GLFW=3', '-lglfw', '-lGL', '-DCLIENT_API=GLFW_OPENGL_ES_API', '-sGL_ENABLE_GET_PROC_ADDRESS', '--pre-js', 'pre.js'])

@parameterized({
'': (['-sUSE_GLFW=2', '-DUSE_GLFW=2'],),
'glfw3': (['-sUSE_GLFW=3', '-DUSE_GLFW=3'],),
Expand Down
Loading