Repository navigation
fix: stem mixer on iOS — install play/pause shims via defineProperty #17
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Regression test for the iOS WebKit #audio play/pause shim install. | ||
| // | ||
| // iOS WebKit exposes HTMLMediaElement.play / .pause as NON-writable properties, | ||
| // so a plain `core.play = fn` assignment throws "Attempted to assign to readonly | ||
| // property" in this plugin's strict-mode (ES module) execution context. That | ||
| // left playOk/pauseOk false, so onSongReady() refused the sloppak takeover and | ||
| // the browser played only stems[0] — the reported "only one stem, mixer sliders | ||
| // do nothing" on iPhone/iPad. Chromium/Electron silently allow the assignment, | ||
| // which is why it only bit on iOS. installAudioShims() must install play/pause | ||
| // with Object.defineProperty (an OWN property on the instance), which works even | ||
| // when the inherited method is non-writable. | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import test from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const src = fs.readFileSync(path.join(__dirname, '..', 'screen.js'), 'utf8'); | ||
|
|
||
| test('play/pause shims use defineProperty, not the assignment that throws on iOS', () => { | ||
| assert.ok( | ||
| !/\bcore\.play\s*=\s*function/.test(src), | ||
| 'core.play must not be installed via direct assignment (throws on iOS WebKit)' | ||
| ); | ||
| assert.ok( | ||
| !/\bcore\.pause\s*=\s*function/.test(src), | ||
| 'core.pause must not be installed via direct assignment (throws on iOS WebKit)' | ||
| ); | ||
| assert.match(src, /Object\.defineProperty\(core, 'play'/, 'core.play must use Object.defineProperty'); | ||
| assert.match(src, /Object\.defineProperty\(core, 'pause'/, 'core.pause must use Object.defineProperty'); | ||
| }); | ||
|
|
||
| test('defineProperty overrides a non-writable method where assignment throws (iOS WebKit model)', () => { | ||
| // Model an iOS-style media element: play/pause are non-writable + configurable, | ||
| // exactly the shape that makes `el.play = fn` throw but defineProperty succeed. | ||
| const makeIOSElement = () => { | ||
| const el = {}; | ||
| for (const name of ['play', 'pause']) { | ||
| Object.defineProperty(el, name, { | ||
| configurable: true, | ||
| writable: false, | ||
| value: () => `native ${name}`, | ||
| }); | ||
| } | ||
| return el; | ||
| }; | ||
|
|
||
| // The OLD pattern throws (this file is a module, so already strict mode). | ||
| const a = makeIOSElement(); | ||
| assert.throws(() => { a.play = () => 'shim'; }, /read.?only|assign/i); | ||
|
|
||
| // The NEW pattern succeeds and the override actually takes effect. | ||
| const b = makeIOSElement(); | ||
| assert.doesNotThrow(() => { | ||
| Object.defineProperty(b, 'play', { configurable: true, writable: true, value: () => 'shim play' }); | ||
| Object.defineProperty(b, 'pause', { configurable: true, writable: true, value: () => 'shim pause' }); | ||
| }); | ||
| assert.equal(b.play(), 'shim play'); | ||
| assert.equal(b.pause(), 'shim pause'); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.