Skip to content

Commit 4140853

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[dart2js/ddc] Add null checks to with<X|Y|Z|W> methods
Fixes test failures in lib/typed_data/simd_type_null_params_weak_test. It appears that these methods are intended to retain the null checks and failures in weak mode based on the discussion in the migration https://dart-review.googlesource.com/c/sdk/+/132341. Change-Id: Ieeb1730059a57b2edf1b5d235cd7a4133d4844df Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152909 Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
1 parent 0d44449 commit 4140853

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

sdk/lib/_internal/js_dev_runtime/private/native_typed_data.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,21 +1361,25 @@ class NativeFloat32x4 implements Float32x4 {
13611361

13621362
/// Copy [this] and replace the [x] lane.
13631363
Float32x4 withX(double newX) {
1364+
ArgumentError.checkNotNull(newX);
13641365
return NativeFloat32x4._truncated(_truncate(newX), y, z, w);
13651366
}
13661367

13671368
/// Copy [this] and replace the [y] lane.
13681369
Float32x4 withY(double newY) {
1370+
ArgumentError.checkNotNull(newY);
13691371
return NativeFloat32x4._truncated(x, _truncate(newY), z, w);
13701372
}
13711373

13721374
/// Copy [this] and replace the [z] lane.
13731375
Float32x4 withZ(double newZ) {
1376+
ArgumentError.checkNotNull(newZ);
13741377
return NativeFloat32x4._truncated(x, y, _truncate(newZ), w);
13751378
}
13761379

13771380
/// Copy [this] and replace the [w] lane.
13781381
Float32x4 withW(double newW) {
1382+
ArgumentError.checkNotNull(newW);
13791383
return NativeFloat32x4._truncated(x, y, z, _truncate(newW));
13801384
}
13811385

@@ -1583,24 +1587,28 @@ class NativeInt32x4 implements Int32x4 {
15831587

15841588
/// Returns a new [Int32x4] copied from [this] with a new x value.
15851589
Int32x4 withX(int x) {
1590+
ArgumentError.checkNotNull(x);
15861591
int _x = _truncate(x);
15871592
return NativeInt32x4._truncated(_x, y, z, w);
15881593
}
15891594

15901595
/// Returns a new [Int32x4] copied from [this] with a new y value.
15911596
Int32x4 withY(int y) {
1597+
ArgumentError.checkNotNull(y);
15921598
int _y = _truncate(y);
15931599
return NativeInt32x4._truncated(x, _y, z, w);
15941600
}
15951601

15961602
/// Returns a new [Int32x4] copied from [this] with a new z value.
15971603
Int32x4 withZ(int z) {
1604+
ArgumentError.checkNotNull(z);
15981605
int _z = _truncate(z);
15991606
return NativeInt32x4._truncated(x, y, _z, w);
16001607
}
16011608

16021609
/// Returns a new [Int32x4] copied from [this] with a new w value.
16031610
Int32x4 withW(int w) {
1611+
ArgumentError.checkNotNull(w);
16041612
int _w = _truncate(w);
16051613
return NativeInt32x4._truncated(x, y, z, _w);
16061614
}

sdk/lib/_internal/js_runtime/lib/native_typed_data.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'dart:_internal' show FixedLengthListMixin hide Symbol;
1111
import 'dart:_interceptors' show JSIndexable, JSUInt32, JSUInt31;
1212
import 'dart:_js_helper'
1313
show
14+
checkNum,
1415
Creates,
1516
JavaScriptIndexingBehavior,
1617
JSName,
@@ -1351,22 +1352,26 @@ class NativeFloat32x4 implements Float32x4 {
13511352

13521353
/// Copy [this] and replace the [x] lane.
13531354
Float32x4 withX(double newX) {
1354-
return NativeFloat32x4._truncated(_truncate(newX), y, z, w);
1355+
double _newX = _truncate(checkNum(newX));
1356+
return NativeFloat32x4._truncated(_newX, y, z, w);
13551357
}
13561358

13571359
/// Copy [this] and replace the [y] lane.
13581360
Float32x4 withY(double newY) {
1359-
return NativeFloat32x4._truncated(x, _truncate(newY), z, w);
1361+
double _newY = _truncate(checkNum(newY));
1362+
return NativeFloat32x4._truncated(x, _newY, z, w);
13601363
}
13611364

13621365
/// Copy [this] and replace the [z] lane.
13631366
Float32x4 withZ(double newZ) {
1364-
return NativeFloat32x4._truncated(x, y, _truncate(newZ), w);
1367+
double _newZ = _truncate(checkNum(newZ));
1368+
return NativeFloat32x4._truncated(x, y, _newZ, w);
13651369
}
13661370

13671371
/// Copy [this] and replace the [w] lane.
13681372
Float32x4 withW(double newW) {
1369-
return NativeFloat32x4._truncated(x, y, z, _truncate(newW));
1373+
double _newW = _truncate(checkNum(newW));
1374+
return NativeFloat32x4._truncated(x, y, z, _newW);
13701375
}
13711376

13721377
/// Returns the lane-wise minimum value in [this] or [other].
@@ -1573,25 +1578,25 @@ class NativeInt32x4 implements Int32x4 {
15731578

15741579
/// Returns a new [Int32x4] copied from [this] with a new x value.
15751580
Int32x4 withX(int x) {
1576-
int _x = _truncate(x);
1581+
int _x = _truncate(checkNum(x));
15771582
return NativeInt32x4._truncated(_x, y, z, w);
15781583
}
15791584

15801585
/// Returns a new [Int32x4] copied from [this] with a new y value.
15811586
Int32x4 withY(int y) {
1582-
int _y = _truncate(y);
1587+
int _y = _truncate(checkNum(y));
15831588
return NativeInt32x4._truncated(x, _y, z, w);
15841589
}
15851590

15861591
/// Returns a new [Int32x4] copied from [this] with a new z value.
15871592
Int32x4 withZ(int z) {
1588-
int _z = _truncate(z);
1593+
int _z = _truncate(checkNum(z));
15891594
return NativeInt32x4._truncated(x, y, _z, w);
15901595
}
15911596

15921597
/// Returns a new [Int32x4] copied from [this] with a new w value.
15931598
Int32x4 withW(int w) {
1594-
int _w = _truncate(w);
1599+
int _w = _truncate(checkNum(w));
15951600
return NativeInt32x4._truncated(x, y, z, _w);
15961601
}
15971602

0 commit comments

Comments
 (0)