Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign updetached ArrayBuffers are specced to throw often, but implementations do not #678
Comments
domenic
added
the
web reality
label
Aug 24, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Possibly relevant thread: heycam/webidl#151 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Feb 6, 2017
Contributor
It's also probably worth mentioning that all current implementations violate one or more of the invariants listed in 6.1.7.3 Invariants of the Essential Internal Methods for operations on typed arrays with detached array buffers. So it's not recommended to simply copy the bevaviour of web browsers.
|
It's also probably worth mentioning that all current implementations violate one or more of the invariants listed in 6.1.7.3 Invariants of the Essential Internal Methods for operations on typed arrays with detached array buffers. So it's not recommended to simply copy the bevaviour of web browsers. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Feb 10, 2017
Member
@anba Which invariants do you see violated? Do you have a test case? (Possibly relevant thread: tc39/test262#841)
|
@anba Which invariants do you see violated? Do you have a test case? (Possibly relevant thread: tc39/test262#841) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Feb 10, 2017
Contributor
One of the [[OwnPropertyKeys]] invariants is violated in all engines:
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");
}
}
var ta = new Int32Array(1);
// Observe ta[0] as non-configurable.
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Expected: Throws TypeError
// Actual: Prints empty string
// Violates: [[OwnPropertyKeys]]
// The returned List must contain at least the keys of all non-configurable own properties that have previously been observed.
print(Object.getOwnPropertyNames(ta));And related to this an issue with for-in because of:
EnumerateObjectProperties must obtain the own property keys of the target object by calling its [[OwnPropertyKeys]] internal method.
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must print "0" or throw.
for (var p in ta) print(p);Violation for [[GetOwnProperty]] in V8 and SM, because non-configurable properties can disappear
If P's attributes other than [[Writable]] may change over time or if the property might disappear, then P's [[Configurable]] attribute must be true.
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must not print undefined.
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));Similar issue for [[HasProperty]] in V8/SM:
If P was previously observed as a non-configurable data or accessor own property of the target, [[HasProperty]] must return true.
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must not print false.
print(0 in ta);And also [[Delete]]:
If P was previously observed to be a non-configurable own data or accessor property of the target, [[Delete]] must return false.
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must not print true.
print(delete ta[0]);And strictly speaking typed arrays aren't even modifiable in JSC, because they're reported as non-configurable + non-writable, but that's unrelated to the detachment issue.
|
One of the [[OwnPropertyKeys]] invariants is violated in all engines: 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");
}
}
var ta = new Int32Array(1);
// Observe ta[0] as non-configurable.
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Expected: Throws TypeError
// Actual: Prints empty string
// Violates: [[OwnPropertyKeys]]
// The returned List must contain at least the keys of all non-configurable own properties that have previously been observed.
print(Object.getOwnPropertyNames(ta));And related to this an issue with
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must print "0" or throw.
for (var p in ta) print(p);Violation for [[GetOwnProperty]] in V8 and SM, because non-configurable properties can disappear
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must not print undefined.
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));Similar issue for [[HasProperty]] in V8/SM:
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must not print false.
print(0 in ta);And also [[Delete]]:
var ta = new Int32Array(1);
print(JSON.stringify(Object.getOwnPropertyDescriptor(ta, 0)));
detach(ta.buffer);
// Must not print true.
print(delete ta[0]);And strictly speaking typed arrays aren't even modifiable in JSC, because they're reported as non-configurable + non-writable, but that's unrelated to the detachment issue. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Feb 10, 2017
Member
Well, all that sounds like a pretty fundamental barrier to spec'ing something more likely to be web-compatible. It sounds like the violations are all coming from TypedArray elements being non-configurable--that if we make these non-configurable properties visible, the only way to get out of it later is to throw when trying to do other stuff. It wouldn't violate the invariants to make them configurable, but then throw all over the place as if they were non-configurable, right? Just a bit ugly.
|
Well, all that sounds like a pretty fundamental barrier to spec'ing something more likely to be web-compatible. It sounds like the violations are all coming from TypedArray elements being non-configurable--that if we make these non-configurable properties visible, the only way to get out of it later is to throw when trying to do other stuff. It wouldn't violate the invariants to make them configurable, but then throw all over the place as if they were non-configurable, right? Just a bit ugly. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Feb 10, 2017
Contributor
It seems like web-reality has shifted a bit, because at least latest Chakra and JSC seem to throw when accessing/setting indexed properties on a detached typed array.
|
It seems like web-reality has shifted a bit, because at least latest Chakra and JSC seem to throw when accessing/setting indexed properties on a detached typed array. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jswalden
Feb 11, 2017
Contributor
"It wouldn't violate the invariants to make them configurable, but then throw all over the place as if they were non-configurable, right? Just a bit ugly." Sounds right to me on all accounts. Seems like the only out available.
|
"It wouldn't violate the invariants to make them configurable, but then throw all over the place as if they were non-configurable, right? Just a bit ugly." Sounds right to me on all accounts. Seems like the only out available. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evilpie
Feb 13, 2017
Contributor
@anba So detached typed array indexed element access throws in release version of Chakra and JSC? Since when?
|
@anba So detached typed array indexed element access throws in release version of Chakra and JSC? Since when? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Feb 13, 2017
Contributor
@evilpie I don't know if the release versions of WebKit/Safari throw an error (I've only tried the latest JSC from source), but at least Edge 38.14393.0.0 throws a TypeError when accessing elements on a detached typed array.
|
@evilpie I don't know if the release versions of WebKit/Safari throw an error (I've only tried the latest JSC from source), but at least Edge 38.14393.0.0 throws a TypeError when accessing elements on a detached typed array. |
littledan
referenced this issue
Mar 18, 2017
Closed
TypedArray constructor reads bufferByteLength too early #842
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evilpie
Jun 23, 2018
Contributor
Considering that Edge has been shipping throwing on detached typed arrays, I plan on changing Firefox to also throw.
|
Considering that Edge has been shipping throwing on detached typed arrays, I plan on changing Firefox to also throw. |
domenic commentedAug 24, 2016
Previously discussed several times. @annevk brought it up 2 years ago in https://esdiscuss.org/topic/arraybuffer-neutering.
My understanding is that TC39 has decided to hope that one day implementations start throwing here. I am not aware of any implementation plans to do so, but maybe my info is out of date.
In any case, it's worth having an open tracking issue under "web reality" so that people trying to implement the ES spec realize that it doesn't match the reality of the web and implementations.