|
| 1 | +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +// Test of various space-saving contractions of calls to |
| 6 | +// `throwUnsupportedOperation`. |
| 7 | + |
| 8 | +import 'dart:_foreign_helper' show ArrayFlags, HArrayFlagsCheck; |
| 9 | + |
| 10 | +@pragma('dart2js:never-inline') |
| 11 | +// The operation and verb are both elided. |
| 12 | +/*member: indexSetter:function() { |
| 13 | + A.throwUnsupportedOperation(B.List_empty); |
| 14 | +}*/ |
| 15 | +indexSetter() { |
| 16 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 17 | + '[]=', 'modify'); |
| 18 | +} |
| 19 | + |
| 20 | +@pragma('dart2js:never-inline') |
| 21 | +// The operation is reduced to an index but cannot be elided because it is |
| 22 | +// followed by a non-elided verb. |
| 23 | +/*member: indexSetterUnusualVerb:function() { |
| 24 | + A.throwUnsupportedOperation(B.List_empty, 0, "change contents of"); |
| 25 | +}*/ |
| 26 | +indexSetterUnusualVerb() { |
| 27 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 28 | + '[]=', 'change contents of'); |
| 29 | +} |
| 30 | + |
| 31 | +@pragma('dart2js:never-inline') |
| 32 | +// The verb is elided. |
| 33 | +/*member: unusualOperationModify:function() { |
| 34 | + A.throwUnsupportedOperation(B.List_empty, "rub"); |
| 35 | +}*/ |
| 36 | +unusualOperationModify() { |
| 37 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 38 | + 'rub', 'modify'); |
| 39 | +} |
| 40 | + |
| 41 | +@pragma('dart2js:never-inline') |
| 42 | +// The operation is left as a string and verb is |
| 43 | +/*member: unusualOperationRemoveFrom:function() { |
| 44 | + A.throwUnsupportedOperation(B.List_empty, "rub", 1); |
| 45 | +}*/ |
| 46 | +unusualOperationRemoveFrom() { |
| 47 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 48 | + 'rub', 'remove from'); |
| 49 | +} |
| 50 | + |
| 51 | +@pragma('dart2js:never-inline') |
| 52 | +// The operation and verb are left as strings. |
| 53 | +/*member: unusualOperationAndVerb:function() { |
| 54 | + A.throwUnsupportedOperation(B.List_empty, "rub", "burnish"); |
| 55 | +}*/ |
| 56 | +unusualOperationAndVerb() { |
| 57 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 58 | + 'rub', 'burnish'); |
| 59 | +} |
| 60 | + |
| 61 | +@pragma('dart2js:never-inline') |
| 62 | +// The operation is reduced to an index and the verb is elided. |
| 63 | +/*member: knownOperationModify:function() { |
| 64 | + A.throwUnsupportedOperation(B.List_empty, 10); |
| 65 | +}*/ |
| 66 | +knownOperationModify() { |
| 67 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 68 | + 'setUint16', 'modify'); |
| 69 | +} |
| 70 | + |
| 71 | +@pragma('dart2js:never-inline') |
| 72 | +// The operation and verb are combined to a single number. |
| 73 | +/*member: knownOperationAndVerb:function() { |
| 74 | + A.throwUnsupportedOperation(B.List_empty, 16); |
| 75 | +}*/ |
| 76 | +knownOperationAndVerb() { |
| 77 | + HArrayFlagsCheck(const [], ArrayFlags.constant, ArrayFlags.unmodifiableCheck, |
| 78 | + 'removeWhere', 'remove from'); |
| 79 | +} |
| 80 | + |
| 81 | +/*member: main:ignore*/ |
| 82 | +main() { |
| 83 | + indexSetter(); |
| 84 | + indexSetterUnusualVerb(); |
| 85 | + unusualOperationModify(); |
| 86 | + unusualOperationRemoveFrom(); |
| 87 | + unusualOperationAndVerb(); |
| 88 | + knownOperationModify(); |
| 89 | + knownOperationAndVerb(); |
| 90 | +} |
0 commit comments