|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax --harmony-sharedarraybuffer
|
|
|
|
|
|
|
|
(function TestFailsWithNonSharedArray() {
|
|
|
|
var ab = new ArrayBuffer(16);
|
|
|
|
|
|
|
|
var i8a = new Int8Array(ab);
|
|
|
|
var i16a = new Int16Array(ab);
|
|
|
|
var i32a = new Int32Array(ab);
|
|
|
|
var ui8a = new Uint8Array(ab);
|
|
|
|
var ui8ca = new Uint8ClampedArray(ab);
|
|
|
|
var ui16a = new Uint16Array(ab);
|
|
|
|
var ui32a = new Uint32Array(ab);
|
|
|
|
var f32a = new Float32Array(ab);
|
|
|
|
var f64a = new Float64Array(ab);
|
|
|
|
|
|
|
|
[i8a, i16a, i32a, ui8a, ui8ca, ui16a, ui32a, f32a, f64a].forEach(function(
|
|
|
|
ta) {
|
|
|
|
assertThrows(function() { Atomics.wait(ta, 0, 0); });
|
|
|
|
assertThrows(function() { Atomics.wake(ta, 0, 1); });
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestFailsWithNonSharedInt32Array() {
|
|
|
|
var sab = new SharedArrayBuffer(16);
|
|
|
|
|
|
|
|
var i8a = new Int8Array(sab);
|
|
|
|
var i16a = new Int16Array(sab);
|
|
|
|
var ui8a = new Uint8Array(sab);
|
|
|
|
var ui8ca = new Uint8ClampedArray(sab);
|
|
|
|
var ui16a = new Uint16Array(sab);
|
|
|
|
var ui32a = new Uint32Array(sab);
|
|
|
|
var f32a = new Float32Array(sab);
|
|
|
|
var f64a = new Float64Array(sab);
|
|
|
|
|
|
|
|
[i8a, i16a, ui8a, ui8ca, ui16a, ui32a, f32a, f64a].forEach(function(
|
|
|
|
ta) {
|
|
|
|
assertThrows(function() { Atomics.wait(ta, 0, 0); });
|
|
|
|
assertThrows(function() { Atomics.wake(ta, 0, 1); });
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestInvalidIndex() {
|
|
|
|
var sab = new SharedArrayBuffer(16);
|
|
|
|
var i32a = new Int32Array(sab);
|
|
|
|
|
|
|
|
// Valid indexes are 0-3.
|
|
|
|
[-1, 4, 100].forEach(function(invalidIndex) {
|
|
|
|
assertThrows(function() {
|
|
|
|
Atomics.wait(i32a, invalidIndex, 0);
|
|
|
|
}, RangeError);
|
|
|
|
assertThrows(function() {
|
|
|
|
Atomics.wake(i32a, invalidIndex, 0);
|
|
|
|
}, RangeError);
|
|
|
|
var validIndex = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
i32a = new Int32Array(sab, 8);
|
|
|
|
[-1, 2, 100].forEach(function(invalidIndex) {
|
|
|
|
assertThrows(function() {
|
|
|
|
Atomics.wait(i32a, invalidIndex, 0);
|
|
|
|
}, RangeError);
|
|
|
|
assertThrows(function() {
|
|
|
|
Atomics.wake(i32a, invalidIndex, 0);
|
|
|
|
}, RangeError);
|
|
|
|
var validIndex = 0;
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestWaitTimeout() {
|
|
|
|
var i32a = new Int32Array(new SharedArrayBuffer(16));
|
|
|
|
var waitMs = 100;
|
|
|
|
var startTime = new Date();
|
|
|
|
assertEquals("timed-out", Atomics.wait(i32a, 0, 0, waitMs));
|
|
|
|
var endTime = new Date();
|
|
|
|
assertTrue(endTime - startTime >= waitMs);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestWaitNotEqual() {
|
|
|
|
var sab = new SharedArrayBuffer(16);
|
|
|
|
var i32a = new Int32Array(sab);
|
|
|
|
assertEquals("not-equal", Atomics.wait(i32a, 0, 42));
|
|
|
|
|
|
|
|
i32a = new Int32Array(sab, 8);
|
|
|
|
i32a[0] = 1;
|
|
|
|
assertEquals("not-equal", Atomics.wait(i32a, 0, 0));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestWaitNegativeTimeout() {
|
|
|
|
var i32a = new Int32Array(new SharedArrayBuffer(16));
|
|
|
|
assertEquals("timed-out", Atomics.wait(i32a, 0, 0, -1));
|
|
|
|
assertEquals("timed-out", Atomics.wait(i32a, 0, 0, -Infinity));
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestWaitNotAllowed() {
|
|
|
|
%SetAllowAtomicsWait(false);
|
|
|
|
var i32a = new Int32Array(new SharedArrayBuffer(16));
|
|
|
|
assertThrows(function() {
|
|
|
|
Atomics.wait(i32a, 0, 0, -1);
|
|
|
|
});
|
|
|
|
%SetAllowAtomicsWait(true);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestWakePositiveInfinity() {
|
|
|
|
var i32a = new Int32Array(new SharedArrayBuffer(16));
|
|
|
|
Atomics.wake(i32a, 0, Number.POSITIVE_INFINITY);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// In a previous version, this test caused a check failure
|
|
|
|
(function TestObjectWaitValue() {
|
|
|
|
var sab = new SharedArrayBuffer(16);
|
|
|
|
var i32a = new Int32Array(sab);
|
|
|
|
assertEquals("timed-out", Atomics.wait(i32a, 0, Math, 0));
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
//// WORKER ONLY TESTS
|
|
|
|
|
|
|
|
if (this.Worker) {
|
|
|
|
|
|
|
|
var TestWaitWithTimeout = function(timeout) {
|
|
|
|
var sab = new SharedArrayBuffer(16);
|
|
|
|
var i32a = new Int32Array(sab);
|
|
|
|
|
|
|
|
var workerScript =
|
|
|
|
`onmessage = function(msg) {
|
|
|
|
var i32a = new Int32Array(msg.sab, msg.offset);
|
|
|
|
var result = Atomics.wait(i32a, 0, 0, ${timeout});
|
|
|
|
postMessage(result);
|
|
|
|
};`;
|
|
|
|
|
|
|
|
var worker = new Worker(workerScript);
|
deps: cherry-pick V8 ValueSerializer changes
Refs: https://github.com/nodejs/node/pull/11048
Below is the list of commits:
deps: cherry-pick 78c0be52d from V8 upstream
Original commit message:
ValueSerializer: Promote scheduled exceptions from wasm::ErrorThrower.
wasm::ErrorThrower doesn't actually throw exceptions, it just schedules them.
As a result, this exception isn't handled properly by code which expects
ValueDeserializer to actually throw. For instance, the unit tests use a
TryCatch to catch and handle expected exceptions in unit tests.
Before this patch, I see local unit test failures because a wasm decode test
schedules one, but it isn't caught (and instead causes Context::New to fail
at the beginning of the next test).
BUG=685713
Review-Url: https://codereview.chromium.org/2659483004
Cr-Commit-Position: refs/heads/master@{#42718}
deps: cherry-pick 966355585 from V8 upstream
Original commit message:
[d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer)
Review-Url: https://codereview.chromium.org/2643723010
Cr-Commit-Position: refs/heads/master@{#42749}
deps: cherry-pick bf511b426 from V8 upstream
Original commit message:
ValueSerializer: Support efficiently reading and writing one-byte strings.
memcpy is faster than UTF-8 encoding/decoding. This yields 10-20% wins on
serializing and deserializing long ASCII strings, according to
blink_perf.bindings -- and these are already in a fast path where the entire
string is known to be ASCII (but this has to be checked). The win may be
larger for strings in Latin-1 but not ASCII (though I suspect this is an
uncommon case).
A change is also made to make ValueSerializerTest.EncodeTwoByteStringUsesPadding
survive wire format version number changes.
This is the first of a series of wire format changes from the previous Blink
format. The deserializer continues to be able to read the old format, but
Chromium M56 will no longer be able to read the messages written by this, in M58.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2658793004
Cr-Commit-Position: refs/heads/master@{#42753}
deps: cherry-pick 6f1639ed1 from V8 upstream
Original commit message:
ValueSerializer: Distinguish between 'undefined' and an absent property.
Dealing with this case requires a wire format change. It is possible that an
element can be absent even in an array where the dense format was chosen
(because the array initially had no holes), if the elements are modified while
they are being serialized. In this case, a new tag for the "hole" is emitted.
The logic to treat undefined in dense arrays as an absent property is restricted
to versions of the wire format that this tag did not exist.
BUG=chromium:686159,chromium:665820
Review-Url: https://codereview.chromium.org/2660093002
Cr-Original-Commit-Position: refs/heads/master@{#42784}
Committed: https://chromium.googlesource.com/v8/v8/+/dc85f4c8338c1c824af4f7ee3274dc9f95d14e49
Review-Url: https://codereview.chromium.org/2660093002
Cr-Commit-Position: refs/heads/master@{#42800}
deps: cherry-pick c3856de37 from V8 upstream
Original commit message:
ValueSerializer: Check for zero length before casting to FixedDoubleArray.
Even though the elements kind is FAST_DOUBLE_ELEMENTS, if length is zero
the isolate's empty_fixed_array is used. It's illegal to cast this to
FixedDoubleArray, so we avoid the cast.
BUG=chromium:686479
Review-Url: https://codereview.chromium.org/2665313003
Cr-Commit-Position: refs/heads/master@{#42867}
deps: cherry-pick 591cc0b4c from V8 upstream
Original commit message:
ValueSerializer: Share string encoding code with String and RegExp objects.
This avoids the need to pull in the UTF-8 encoding code from the public API,
and allows it to take advantage of any supported way that i::String can be
encoded (one- or two-byte).
Backward compatibility is maintained, but this is the behavior beginning
with this version.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2665653004
Cr-Commit-Position: refs/heads/master@{#42872}
deps: cherry-pick 79837f5f6 from V8 upstream
Original commit message:
Improve ValueSerializer perf regression after 96635558
BUG=687196
R=jbroman@chromium.org
Review-Url: https://codereview.chromium.org/2674613002
Cr-Commit-Position: refs/heads/master@{#42938}
deps: cherry-pick 8990399dc from V8 upstream
Original commit message:
ValueDeserializer: Only allow valid keys when deserializing object properties.
The serializer won't ever write a more complex object. Not validating this
allows other things to be used as keys, and converted to string when the
property set actually occurs. It turns out this gives an opportunity to trigger
OOM by giving an object a key which is a very large sparse array (whose string
representation is very large).
This case is now rejected by the deserializer.
BUG=chromium:686511
Review-Url: https://codereview.chromium.org/2697023002
Cr-Commit-Position: refs/heads/master@{#43249}
deps: cherry-pick 68960eeb7 from V8 upstream
Original commit message:
ValueDeserializer: Make sure that an exception is the legacy path.
The entry points to the deserializer are responsible for ensuring that an
exception is pending by the time they return. Some failures throw exceptions
themselves, while others (like errors in the format) are exceptions caused by
the deserializer, not coming from the runtime.
Like the non-legacy path, a default deserialization exception should be thrown
in such cases.
BUG=chromium:693411
Review-Url: https://codereview.chromium.org/2712713002
Cr-Commit-Position: refs/heads/master@{#43390}
deps: cherry-pick 3b15d950e from V8 upstream
Original commit message:
ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag
Add `ValueSerializer::SetTreatArrayBufferViewsAsHostObjects()` which
instructs the `ValueSerializer` to treat ArrayBufferView objects as
host objects.
BUG=v8:5926
Review-Url: https://codereview.chromium.org/2696133007
Cr-Commit-Position: refs/heads/master@{#43281}
deps: cherry-pick 654351997 from V8 upstream
Original commit message:
ValueSerializer: Add an explicit tag for host objects.
This makes it no longer necessary to ensure that V8 and Blink have non-colliding
tags, which makes it easier for them to evolve independently, and also makes
the wire format more suitable for other V8 embedders, who would not
necessarily be surveyed before V8 introduced a new tag that might collide
with theirs.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2709023003
Cr-Commit-Position: refs/heads/master@{#43466}
PR-URL: https://github.com/nodejs/node/pull/11752
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
8 years ago
|
|
|
worker.postMessage({sab: sab, offset: offset});
|
|
|
|
|
|
|
|
// Spin until the worker is waiting on the futex.
|
|
|
|
while (%AtomicsNumWaitersForTesting(i32a, 0) != 1) {}
|
|
|
|
|
|
|
|
Atomics.wake(i32a, 0, 1);
|
|
|
|
assertEquals("ok", worker.getMessage());
|
|
|
|
worker.terminate();
|
|
|
|
|
|
|
|
var worker2 = new Worker(workerScript);
|
|
|
|
var offset = 8;
|
|
|
|
var i32a2 = new Int32Array(sab, offset);
|
deps: cherry-pick V8 ValueSerializer changes
Refs: https://github.com/nodejs/node/pull/11048
Below is the list of commits:
deps: cherry-pick 78c0be52d from V8 upstream
Original commit message:
ValueSerializer: Promote scheduled exceptions from wasm::ErrorThrower.
wasm::ErrorThrower doesn't actually throw exceptions, it just schedules them.
As a result, this exception isn't handled properly by code which expects
ValueDeserializer to actually throw. For instance, the unit tests use a
TryCatch to catch and handle expected exceptions in unit tests.
Before this patch, I see local unit test failures because a wasm decode test
schedules one, but it isn't caught (and instead causes Context::New to fail
at the beginning of the next test).
BUG=685713
Review-Url: https://codereview.chromium.org/2659483004
Cr-Commit-Position: refs/heads/master@{#42718}
deps: cherry-pick 966355585 from V8 upstream
Original commit message:
[d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer)
Review-Url: https://codereview.chromium.org/2643723010
Cr-Commit-Position: refs/heads/master@{#42749}
deps: cherry-pick bf511b426 from V8 upstream
Original commit message:
ValueSerializer: Support efficiently reading and writing one-byte strings.
memcpy is faster than UTF-8 encoding/decoding. This yields 10-20% wins on
serializing and deserializing long ASCII strings, according to
blink_perf.bindings -- and these are already in a fast path where the entire
string is known to be ASCII (but this has to be checked). The win may be
larger for strings in Latin-1 but not ASCII (though I suspect this is an
uncommon case).
A change is also made to make ValueSerializerTest.EncodeTwoByteStringUsesPadding
survive wire format version number changes.
This is the first of a series of wire format changes from the previous Blink
format. The deserializer continues to be able to read the old format, but
Chromium M56 will no longer be able to read the messages written by this, in M58.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2658793004
Cr-Commit-Position: refs/heads/master@{#42753}
deps: cherry-pick 6f1639ed1 from V8 upstream
Original commit message:
ValueSerializer: Distinguish between 'undefined' and an absent property.
Dealing with this case requires a wire format change. It is possible that an
element can be absent even in an array where the dense format was chosen
(because the array initially had no holes), if the elements are modified while
they are being serialized. In this case, a new tag for the "hole" is emitted.
The logic to treat undefined in dense arrays as an absent property is restricted
to versions of the wire format that this tag did not exist.
BUG=chromium:686159,chromium:665820
Review-Url: https://codereview.chromium.org/2660093002
Cr-Original-Commit-Position: refs/heads/master@{#42784}
Committed: https://chromium.googlesource.com/v8/v8/+/dc85f4c8338c1c824af4f7ee3274dc9f95d14e49
Review-Url: https://codereview.chromium.org/2660093002
Cr-Commit-Position: refs/heads/master@{#42800}
deps: cherry-pick c3856de37 from V8 upstream
Original commit message:
ValueSerializer: Check for zero length before casting to FixedDoubleArray.
Even though the elements kind is FAST_DOUBLE_ELEMENTS, if length is zero
the isolate's empty_fixed_array is used. It's illegal to cast this to
FixedDoubleArray, so we avoid the cast.
BUG=chromium:686479
Review-Url: https://codereview.chromium.org/2665313003
Cr-Commit-Position: refs/heads/master@{#42867}
deps: cherry-pick 591cc0b4c from V8 upstream
Original commit message:
ValueSerializer: Share string encoding code with String and RegExp objects.
This avoids the need to pull in the UTF-8 encoding code from the public API,
and allows it to take advantage of any supported way that i::String can be
encoded (one- or two-byte).
Backward compatibility is maintained, but this is the behavior beginning
with this version.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2665653004
Cr-Commit-Position: refs/heads/master@{#42872}
deps: cherry-pick 79837f5f6 from V8 upstream
Original commit message:
Improve ValueSerializer perf regression after 96635558
BUG=687196
R=jbroman@chromium.org
Review-Url: https://codereview.chromium.org/2674613002
Cr-Commit-Position: refs/heads/master@{#42938}
deps: cherry-pick 8990399dc from V8 upstream
Original commit message:
ValueDeserializer: Only allow valid keys when deserializing object properties.
The serializer won't ever write a more complex object. Not validating this
allows other things to be used as keys, and converted to string when the
property set actually occurs. It turns out this gives an opportunity to trigger
OOM by giving an object a key which is a very large sparse array (whose string
representation is very large).
This case is now rejected by the deserializer.
BUG=chromium:686511
Review-Url: https://codereview.chromium.org/2697023002
Cr-Commit-Position: refs/heads/master@{#43249}
deps: cherry-pick 68960eeb7 from V8 upstream
Original commit message:
ValueDeserializer: Make sure that an exception is the legacy path.
The entry points to the deserializer are responsible for ensuring that an
exception is pending by the time they return. Some failures throw exceptions
themselves, while others (like errors in the format) are exceptions caused by
the deserializer, not coming from the runtime.
Like the non-legacy path, a default deserialization exception should be thrown
in such cases.
BUG=chromium:693411
Review-Url: https://codereview.chromium.org/2712713002
Cr-Commit-Position: refs/heads/master@{#43390}
deps: cherry-pick 3b15d950e from V8 upstream
Original commit message:
ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag
Add `ValueSerializer::SetTreatArrayBufferViewsAsHostObjects()` which
instructs the `ValueSerializer` to treat ArrayBufferView objects as
host objects.
BUG=v8:5926
Review-Url: https://codereview.chromium.org/2696133007
Cr-Commit-Position: refs/heads/master@{#43281}
deps: cherry-pick 654351997 from V8 upstream
Original commit message:
ValueSerializer: Add an explicit tag for host objects.
This makes it no longer necessary to ensure that V8 and Blink have non-colliding
tags, which makes it easier for them to evolve independently, and also makes
the wire format more suitable for other V8 embedders, who would not
necessarily be surveyed before V8 introduced a new tag that might collide
with theirs.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2709023003
Cr-Commit-Position: refs/heads/master@{#43466}
PR-URL: https://github.com/nodejs/node/pull/11752
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
8 years ago
|
|
|
worker2.postMessage({sab: sab, offset: offset});
|
|
|
|
|
|
|
|
// Spin until the worker is waiting on the futex.
|
|
|
|
while (%AtomicsNumWaitersForTesting(i32a2, 0) != 1) {}
|
|
|
|
Atomics.wake(i32a2, 0, 1);
|
|
|
|
assertEquals("ok", worker2.getMessage());
|
|
|
|
worker2.terminate();
|
|
|
|
|
|
|
|
// Futex should work when index and buffer views are different, but
|
|
|
|
// the real address is the same.
|
|
|
|
var worker3 = new Worker(workerScript);
|
|
|
|
i32a2 = new Int32Array(sab, 4);
|
deps: cherry-pick V8 ValueSerializer changes
Refs: https://github.com/nodejs/node/pull/11048
Below is the list of commits:
deps: cherry-pick 78c0be52d from V8 upstream
Original commit message:
ValueSerializer: Promote scheduled exceptions from wasm::ErrorThrower.
wasm::ErrorThrower doesn't actually throw exceptions, it just schedules them.
As a result, this exception isn't handled properly by code which expects
ValueDeserializer to actually throw. For instance, the unit tests use a
TryCatch to catch and handle expected exceptions in unit tests.
Before this patch, I see local unit test failures because a wasm decode test
schedules one, but it isn't caught (and instead causes Context::New to fail
at the beginning of the next test).
BUG=685713
Review-Url: https://codereview.chromium.org/2659483004
Cr-Commit-Position: refs/heads/master@{#42718}
deps: cherry-pick 966355585 from V8 upstream
Original commit message:
[d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer)
Review-Url: https://codereview.chromium.org/2643723010
Cr-Commit-Position: refs/heads/master@{#42749}
deps: cherry-pick bf511b426 from V8 upstream
Original commit message:
ValueSerializer: Support efficiently reading and writing one-byte strings.
memcpy is faster than UTF-8 encoding/decoding. This yields 10-20% wins on
serializing and deserializing long ASCII strings, according to
blink_perf.bindings -- and these are already in a fast path where the entire
string is known to be ASCII (but this has to be checked). The win may be
larger for strings in Latin-1 but not ASCII (though I suspect this is an
uncommon case).
A change is also made to make ValueSerializerTest.EncodeTwoByteStringUsesPadding
survive wire format version number changes.
This is the first of a series of wire format changes from the previous Blink
format. The deserializer continues to be able to read the old format, but
Chromium M56 will no longer be able to read the messages written by this, in M58.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2658793004
Cr-Commit-Position: refs/heads/master@{#42753}
deps: cherry-pick 6f1639ed1 from V8 upstream
Original commit message:
ValueSerializer: Distinguish between 'undefined' and an absent property.
Dealing with this case requires a wire format change. It is possible that an
element can be absent even in an array where the dense format was chosen
(because the array initially had no holes), if the elements are modified while
they are being serialized. In this case, a new tag for the "hole" is emitted.
The logic to treat undefined in dense arrays as an absent property is restricted
to versions of the wire format that this tag did not exist.
BUG=chromium:686159,chromium:665820
Review-Url: https://codereview.chromium.org/2660093002
Cr-Original-Commit-Position: refs/heads/master@{#42784}
Committed: https://chromium.googlesource.com/v8/v8/+/dc85f4c8338c1c824af4f7ee3274dc9f95d14e49
Review-Url: https://codereview.chromium.org/2660093002
Cr-Commit-Position: refs/heads/master@{#42800}
deps: cherry-pick c3856de37 from V8 upstream
Original commit message:
ValueSerializer: Check for zero length before casting to FixedDoubleArray.
Even though the elements kind is FAST_DOUBLE_ELEMENTS, if length is zero
the isolate's empty_fixed_array is used. It's illegal to cast this to
FixedDoubleArray, so we avoid the cast.
BUG=chromium:686479
Review-Url: https://codereview.chromium.org/2665313003
Cr-Commit-Position: refs/heads/master@{#42867}
deps: cherry-pick 591cc0b4c from V8 upstream
Original commit message:
ValueSerializer: Share string encoding code with String and RegExp objects.
This avoids the need to pull in the UTF-8 encoding code from the public API,
and allows it to take advantage of any supported way that i::String can be
encoded (one- or two-byte).
Backward compatibility is maintained, but this is the behavior beginning
with this version.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2665653004
Cr-Commit-Position: refs/heads/master@{#42872}
deps: cherry-pick 79837f5f6 from V8 upstream
Original commit message:
Improve ValueSerializer perf regression after 96635558
BUG=687196
R=jbroman@chromium.org
Review-Url: https://codereview.chromium.org/2674613002
Cr-Commit-Position: refs/heads/master@{#42938}
deps: cherry-pick 8990399dc from V8 upstream
Original commit message:
ValueDeserializer: Only allow valid keys when deserializing object properties.
The serializer won't ever write a more complex object. Not validating this
allows other things to be used as keys, and converted to string when the
property set actually occurs. It turns out this gives an opportunity to trigger
OOM by giving an object a key which is a very large sparse array (whose string
representation is very large).
This case is now rejected by the deserializer.
BUG=chromium:686511
Review-Url: https://codereview.chromium.org/2697023002
Cr-Commit-Position: refs/heads/master@{#43249}
deps: cherry-pick 68960eeb7 from V8 upstream
Original commit message:
ValueDeserializer: Make sure that an exception is the legacy path.
The entry points to the deserializer are responsible for ensuring that an
exception is pending by the time they return. Some failures throw exceptions
themselves, while others (like errors in the format) are exceptions caused by
the deserializer, not coming from the runtime.
Like the non-legacy path, a default deserialization exception should be thrown
in such cases.
BUG=chromium:693411
Review-Url: https://codereview.chromium.org/2712713002
Cr-Commit-Position: refs/heads/master@{#43390}
deps: cherry-pick 3b15d950e from V8 upstream
Original commit message:
ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag
Add `ValueSerializer::SetTreatArrayBufferViewsAsHostObjects()` which
instructs the `ValueSerializer` to treat ArrayBufferView objects as
host objects.
BUG=v8:5926
Review-Url: https://codereview.chromium.org/2696133007
Cr-Commit-Position: refs/heads/master@{#43281}
deps: cherry-pick 654351997 from V8 upstream
Original commit message:
ValueSerializer: Add an explicit tag for host objects.
This makes it no longer necessary to ensure that V8 and Blink have non-colliding
tags, which makes it easier for them to evolve independently, and also makes
the wire format more suitable for other V8 embedders, who would not
necessarily be surveyed before V8 introduced a new tag that might collide
with theirs.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2709023003
Cr-Commit-Position: refs/heads/master@{#43466}
PR-URL: https://github.com/nodejs/node/pull/11752
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
8 years ago
|
|
|
worker3.postMessage({sab: sab, offset: 8});
|
|
|
|
|
|
|
|
// Spin until the worker is waiting on the futex.
|
|
|
|
while (%AtomicsNumWaitersForTesting(i32a2, 1) != 1) {}
|
|
|
|
Atomics.wake(i32a2, 1, 1);
|
|
|
|
assertEquals("ok", worker3.getMessage());
|
|
|
|
worker3.terminate();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test various infinite timeouts
|
|
|
|
TestWaitWithTimeout(undefined);
|
|
|
|
TestWaitWithTimeout(NaN);
|
|
|
|
TestWaitWithTimeout(Infinity);
|
|
|
|
|
|
|
|
|
|
|
|
(function TestWakeMulti() {
|
|
|
|
var sab = new SharedArrayBuffer(20);
|
|
|
|
var i32a = new Int32Array(sab);
|
|
|
|
|
|
|
|
// SAB values:
|
|
|
|
// i32a[id], where id in range [0, 3]:
|
|
|
|
// 0 => Worker |id| is still waiting on the futex
|
|
|
|
// 1 => Worker |id| is not waiting on futex, but has not be reaped by the
|
|
|
|
// main thread.
|
|
|
|
// 2 => Worker |id| has been reaped.
|
|
|
|
//
|
|
|
|
// i32a[4]:
|
|
|
|
// always 0. Each worker is waiting on this index.
|
|
|
|
|
|
|
|
var workerScript =
|
|
|
|
`onmessage = function(msg) {
|
|
|
|
var id = msg.id;
|
|
|
|
var i32a = new Int32Array(msg.sab);
|
|
|
|
|
|
|
|
// Wait on i32a[4] (should be zero).
|
|
|
|
var result = Atomics.wait(i32a, 4, 0);
|
|
|
|
// Set i32a[id] to 1 to notify the main thread which workers were
|
|
|
|
// woken up.
|
|
|
|
Atomics.store(i32a, id, 1);
|
|
|
|
postMessage(result);
|
|
|
|
};`;
|
|
|
|
|
|
|
|
var id;
|
|
|
|
var workers = [];
|
|
|
|
for (id = 0; id < 4; id++) {
|
|
|
|
workers[id] = new Worker(workerScript);
|
deps: cherry-pick V8 ValueSerializer changes
Refs: https://github.com/nodejs/node/pull/11048
Below is the list of commits:
deps: cherry-pick 78c0be52d from V8 upstream
Original commit message:
ValueSerializer: Promote scheduled exceptions from wasm::ErrorThrower.
wasm::ErrorThrower doesn't actually throw exceptions, it just schedules them.
As a result, this exception isn't handled properly by code which expects
ValueDeserializer to actually throw. For instance, the unit tests use a
TryCatch to catch and handle expected exceptions in unit tests.
Before this patch, I see local unit test failures because a wasm decode test
schedules one, but it isn't caught (and instead causes Context::New to fail
at the beginning of the next test).
BUG=685713
Review-Url: https://codereview.chromium.org/2659483004
Cr-Commit-Position: refs/heads/master@{#42718}
deps: cherry-pick 966355585 from V8 upstream
Original commit message:
[d8] Use ValueSerializer for postMessage (instead of ad-hoc serializer)
Review-Url: https://codereview.chromium.org/2643723010
Cr-Commit-Position: refs/heads/master@{#42749}
deps: cherry-pick bf511b426 from V8 upstream
Original commit message:
ValueSerializer: Support efficiently reading and writing one-byte strings.
memcpy is faster than UTF-8 encoding/decoding. This yields 10-20% wins on
serializing and deserializing long ASCII strings, according to
blink_perf.bindings -- and these are already in a fast path where the entire
string is known to be ASCII (but this has to be checked). The win may be
larger for strings in Latin-1 but not ASCII (though I suspect this is an
uncommon case).
A change is also made to make ValueSerializerTest.EncodeTwoByteStringUsesPadding
survive wire format version number changes.
This is the first of a series of wire format changes from the previous Blink
format. The deserializer continues to be able to read the old format, but
Chromium M56 will no longer be able to read the messages written by this, in M58.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2658793004
Cr-Commit-Position: refs/heads/master@{#42753}
deps: cherry-pick 6f1639ed1 from V8 upstream
Original commit message:
ValueSerializer: Distinguish between 'undefined' and an absent property.
Dealing with this case requires a wire format change. It is possible that an
element can be absent even in an array where the dense format was chosen
(because the array initially had no holes), if the elements are modified while
they are being serialized. In this case, a new tag for the "hole" is emitted.
The logic to treat undefined in dense arrays as an absent property is restricted
to versions of the wire format that this tag did not exist.
BUG=chromium:686159,chromium:665820
Review-Url: https://codereview.chromium.org/2660093002
Cr-Original-Commit-Position: refs/heads/master@{#42784}
Committed: https://chromium.googlesource.com/v8/v8/+/dc85f4c8338c1c824af4f7ee3274dc9f95d14e49
Review-Url: https://codereview.chromium.org/2660093002
Cr-Commit-Position: refs/heads/master@{#42800}
deps: cherry-pick c3856de37 from V8 upstream
Original commit message:
ValueSerializer: Check for zero length before casting to FixedDoubleArray.
Even though the elements kind is FAST_DOUBLE_ELEMENTS, if length is zero
the isolate's empty_fixed_array is used. It's illegal to cast this to
FixedDoubleArray, so we avoid the cast.
BUG=chromium:686479
Review-Url: https://codereview.chromium.org/2665313003
Cr-Commit-Position: refs/heads/master@{#42867}
deps: cherry-pick 591cc0b4c from V8 upstream
Original commit message:
ValueSerializer: Share string encoding code with String and RegExp objects.
This avoids the need to pull in the UTF-8 encoding code from the public API,
and allows it to take advantage of any supported way that i::String can be
encoded (one- or two-byte).
Backward compatibility is maintained, but this is the behavior beginning
with this version.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2665653004
Cr-Commit-Position: refs/heads/master@{#42872}
deps: cherry-pick 79837f5f6 from V8 upstream
Original commit message:
Improve ValueSerializer perf regression after 96635558
BUG=687196
R=jbroman@chromium.org
Review-Url: https://codereview.chromium.org/2674613002
Cr-Commit-Position: refs/heads/master@{#42938}
deps: cherry-pick 8990399dc from V8 upstream
Original commit message:
ValueDeserializer: Only allow valid keys when deserializing object properties.
The serializer won't ever write a more complex object. Not validating this
allows other things to be used as keys, and converted to string when the
property set actually occurs. It turns out this gives an opportunity to trigger
OOM by giving an object a key which is a very large sparse array (whose string
representation is very large).
This case is now rejected by the deserializer.
BUG=chromium:686511
Review-Url: https://codereview.chromium.org/2697023002
Cr-Commit-Position: refs/heads/master@{#43249}
deps: cherry-pick 68960eeb7 from V8 upstream
Original commit message:
ValueDeserializer: Make sure that an exception is the legacy path.
The entry points to the deserializer are responsible for ensuring that an
exception is pending by the time they return. Some failures throw exceptions
themselves, while others (like errors in the format) are exceptions caused by
the deserializer, not coming from the runtime.
Like the non-legacy path, a default deserialization exception should be thrown
in such cases.
BUG=chromium:693411
Review-Url: https://codereview.chromium.org/2712713002
Cr-Commit-Position: refs/heads/master@{#43390}
deps: cherry-pick 3b15d950e from V8 upstream
Original commit message:
ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag
Add `ValueSerializer::SetTreatArrayBufferViewsAsHostObjects()` which
instructs the `ValueSerializer` to treat ArrayBufferView objects as
host objects.
BUG=v8:5926
Review-Url: https://codereview.chromium.org/2696133007
Cr-Commit-Position: refs/heads/master@{#43281}
deps: cherry-pick 654351997 from V8 upstream
Original commit message:
ValueSerializer: Add an explicit tag for host objects.
This makes it no longer necessary to ensure that V8 and Blink have non-colliding
tags, which makes it easier for them to evolve independently, and also makes
the wire format more suitable for other V8 embedders, who would not
necessarily be surveyed before V8 introduced a new tag that might collide
with theirs.
BUG=chromium:686159
Review-Url: https://codereview.chromium.org/2709023003
Cr-Commit-Position: refs/heads/master@{#43466}
PR-URL: https://github.com/nodejs/node/pull/11752
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
8 years ago
|
|
|
workers[id].postMessage({sab: sab, id: id});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spin until all workers are waiting on the futex.
|
|
|
|
while (%AtomicsNumWaitersForTesting(i32a, 4) != 4) {}
|
|
|
|
|
|
|
|
// Wake up three waiters.
|
|
|
|
assertEquals(3, Atomics.wake(i32a, 4, 3));
|
|
|
|
|
|
|
|
var wokenCount = 0;
|
|
|
|
var waitingId = 0 + 1 + 2 + 3;
|
|
|
|
while (wokenCount < 3) {
|
|
|
|
for (id = 0; id < 4; id++) {
|
|
|
|
// Look for workers that have not yet been reaped. Set i32a[id] to 2
|
|
|
|
// when they've been processed so we don't look at them again.
|
|
|
|
if (Atomics.compareExchange(i32a, id, 1, 2) == 1) {
|
|
|
|
assertEquals("ok", workers[id].getMessage());
|
|
|
|
workers[id].terminate();
|
|
|
|
waitingId -= id;
|
|
|
|
wokenCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(3, wokenCount);
|
|
|
|
assertEquals(0, Atomics.load(i32a, waitingId));
|
|
|
|
assertEquals(1, %AtomicsNumWaitersForTesting(i32a, 4));
|
|
|
|
|
|
|
|
// Finally wake the last waiter.
|
|
|
|
assertEquals(1, Atomics.wake(i32a, 4, 1));
|
|
|
|
assertEquals("ok", workers[waitingId].getMessage());
|
|
|
|
workers[waitingId].terminate();
|
|
|
|
|
|
|
|
assertEquals(0, %AtomicsNumWaitersForTesting(i32a, 4));
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
}
|