Repository navigation
Don't throw when the Pointer Lock API is missing #28103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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?.(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using ES2020 optional chaining ( if (document.exitPointerLock) document.exitPointerLock(); |
||
| break; | ||
| } | ||
| case 0x00034002: { // GLFW_CURSOR_HIDDEN | ||
|
|
@@ -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?.(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using ES2020 optional chaining ( if (canvas.requestPointerLock) canvas.requestPointerLock(); |
||
| break; | ||
| } | ||
| default: { | ||
|
|
@@ -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?.(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using ES2020 optional chaining ( if (Browser.lockPointer && canvas.requestPointerLock) canvas.requestPointerLock(); |
||
| Browser.isFullscreen = true; | ||
| if (Browser.resizeCanvas) { | ||
| Browser.setFullscreenCanvasSize(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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?.(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using ES2020 optional chaining ( 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?.(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using ES2020 optional chaining ( if (document.exitPointerLock) document.exitPointerLock(); |
||
| return 1; | ||
| case -1: // SDL_QUERY | ||
| return !Browser.pointerLock; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.