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

Let's remove the IsDetachedBuffer check in 22.2.4.3, step 18.a #1002

Closed
anba opened this Issue Sep 16, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@anba
Contributor

anba commented Sep 16, 2017

I didn't remove the step in #844 to avoid normative changes in that PR, but since this check is only implemented correctly in SpiderMonkey and CloneArrayBuffer will again check for detached buffers, it doesn't seem terrible useful to me to test for detached buffers in this step.

Test case for the current spec.

function detach(ab) {
  if (ArrayBuffer.transfer) {
    ArrayBuffer.transfer(ab);
  } else if (typeof detachArrayBuffer === "function") {
    detachArrayBuffer(ab);
  } else if (typeof transferArrayBuffer === "function") {
    transferArrayBuffer(ab)
  } else if (typeof Worker === "function") {
    try { eval("%ArrayBufferNeuter(ab)") } catch (e) {
      var w = new Worker("");
      w.postMessage(ab, [ab]);
      w.terminate();
    }
  } else {
    throw new TypeError("cannot detach array buffer");
  }
}

function test(from, to) {
    var ta = new from(0);
    ta.buffer.constructor = {
        get [Symbol.species]() {
            print("get @@species");
            detach(ta.buffer);
            return Object.defineProperty(function(){}.bind(), "prototype", {
                get() {
                    print("get prototype");
                    return null;
                }
            });
        }
    };
    try {
        new to(ta);
    } catch (e) {
        print("caught:", e);
        return;
    }
    print("No error");
}

// Expected: Prints "get @@species" and then throws a TypeError
test(Int32Array, Int32Array);

// Expected: Prints "get @@species", "get prototype", and then throws a TypeError
test(Int32Array, Uint32Array);
@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Sep 21, 2017

Member

@anba want to whip up a needs-consensus PR?

Member

bterlson commented Sep 21, 2017

@anba want to whip up a needs-consensus PR?

anba added a commit to anba/ecma262 that referenced this issue Sep 22, 2017

Normative: Remove detached array buffer check prior to calling CloneA…
…rrayBuffer

This aligns the detached array buffer checks in step 18 and 19 of 22.2.4.3.

Fixes tc39#1002
@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Sep 25, 2017

Member

This test is valid both in the current spec and after your PR, right?

Member

littledan commented Sep 25, 2017

This test is valid both in the current spec and after your PR, right?

@anba

This comment has been minimized.

Show comment
Hide comment
@anba

anba Sep 25, 2017

Contributor

This test is valid both in the current spec and after your PR, right?

No. After the update "get prototype" will also be printed for the test(Int32Array, Int32Array) call.

Contributor

anba commented Sep 25, 2017

This test is valid both in the current spec and after your PR, right?

No. After the update "get prototype" will also be printed for the test(Int32Array, Int32Array) call.

ljharb added a commit to anba/ecma262 that referenced this issue Jul 18, 2018

Normative: Remove detached array buffer check prior to calling CloneA…
…rrayBuffer

This aligns the detached array buffer checks in step 18 and 19 of 22.2.4.3.

Fixes tc39#1002

@ljharb ljharb closed this in #1009 Jul 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment