Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check if the memory is backed by a SAB by checking the constructor name#381

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kateinoigakukun merged 2 commits intomainfromyt/fix-sab-check-on-android
Jul 3, 2025

Conversation

@kateinoigakukun
Copy link
Member

No description provided.

Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces theinstanceof SharedArrayBuffer check with a constructor-name–based detection for SharedArrayBuffer backing and improves DataView reuse in the generated runtime.

  • UseObject.getPrototypeOf(...).constructor.name to detect SAB backing in both TS and MJS runtimes
  • Add detailed comments explaining why directSharedArrayBuffer references aren’t used
  • Cachethis.getDataView() in a local variable before passing todecodeObjectRefs

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

FileDescription
Runtime/src/index.tsSwapped SAB detection frominstanceof to constructor-name check
Plugins/PackageToJS/Templates/runtime.mjsMirrored SAB detection update and cachedgetDataView() for calls
Comments suppressed due to low confidence (2)

Runtime/src/index.ts:68

  • Add unit tests covering the new constructor-name detection path, including scenarios whereglobalThis.SharedArrayBuffer is undefined and where the buffer is SAB-backed in non–cross-origin isolated contexts.
            // Check the constructor name of the buffer to determine if it's backed by a SharedArrayBuffer.

Plugins/PackageToJS/Templates/runtime.mjs:311

  • Include tests for the generated runtime’s SAB detection logic, verifying correct behavior when SharedArrayBuffer isn’t available and when it is present.
            // Check the constructor name of the buffer to determine if it's backed by a SharedArrayBuffer.

// 1. It may not be available in the global scope if the context is not cross-origin isolated.
// 2. The underlying buffer may be still backed by SAB even if the context is not cross-origin
// isolated (e.g. localhost on Chrome on Android).
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
Copy link

CopilotAIJul 3, 2025

Choose a reason for hiding this comment

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

Relying onconstructor.name can break if code is minified or prototypes are altered. Consider using a direct equality check whenglobalThis.SharedArrayBuffer is available (wasmMemory.buffer.constructor === globalThis.SharedArrayBuffer) or fall back toObject.prototype.toString.call(wasmMemory.buffer) === '[object SharedArrayBuffer]' for more robust detection.

Suggested change
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
if(
(globalThis.SharedArrayBuffer&&wasmMemory.buffer.constructor===globalThis.SharedArrayBuffer)||
Object.prototype.toString.call(wasmMemory.buffer)==='[object SharedArrayBuffer]'
){

Copilot uses AI. Check for mistakes.
// 1. It may not be available in the global scope if the context is not cross-origin isolated.
// 2. The underlying buffer may be still backed by SAB even if the context is not cross-origin
// isolated (e.g. localhost on Chrome on Android).
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
Copy link

CopilotAIJul 3, 2025

Choose a reason for hiding this comment

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

Same here: usingconstructor.name may be brittle under minification or prototype mutation. A stronger check iswasmMemory.buffer.constructor === globalThis.SharedArrayBuffer with anObject.prototype.toString fallback.

Suggested change
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
if(wasmMemory.buffer.constructor===globalThis.SharedArrayBuffer||
Object.prototype.toString.call(wasmMemory.buffer)==="[object SharedArrayBuffer]"){

Copilot uses AI. Check for mistakes.
// 1. It may not be available in the global scope if the context is not cross-origin isolated.
// 2. The underlying buffer may be still backed by SAB even if the context is not cross-origin
// isolated (e.g. localhost on Chrome on Android).
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
Copy link

CopilotAIJul 3, 2025

Choose a reason for hiding this comment

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

AccessingObject.getPrototypeOf(...).constructor without checking for null/undefined can throw ifbuffer has a null prototype. Add optional chaining:Object.getPrototypeOf(wasmMemory.buffer)?.constructor?.name === 'SharedArrayBuffer'.

Suggested change
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
if(Object.getPrototypeOf(wasmMemory.buffer)?.constructor?.name==="SharedArrayBuffer"){

Copilot uses AI. Check for mistakes.
// 1. It may not be available in the global scope if the context is not cross-origin isolated.
// 2. The underlying buffer may be still backed by SAB even if the context is not cross-origin
// isolated (e.g. localhost on Chrome on Android).
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
Copy link

CopilotAIJul 3, 2025

Choose a reason for hiding this comment

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

Wrap prototype access in optional chaining to avoid runtime errors if the prototype is null:Object.getPrototypeOf(wasmMemory.buffer)?.constructor?.name === 'SharedArrayBuffer'.

Suggested change
if(Object.getPrototypeOf(wasmMemory.buffer).constructor.name==="SharedArrayBuffer"){
if(Object.getPrototypeOf(wasmMemory.buffer)?.constructor?.name==="SharedArrayBuffer"){

Copilot uses AI. Check for mistakes.
@kateinoigakukunkateinoigakukun merged commite854719 intomainJul 3, 2025
6 checks passed
@kateinoigakukunkateinoigakukun deleted the yt/fix-sab-check-on-android branchJuly 3, 2025 10:22
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@fjtrujyfjtrujyfjtrujy approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@kateinoigakukun@fjtrujy

[8]ページ先頭

©2009-2025 Movatter.jp