Chromium Code Reviews| Index: tool/input_sdk/private/ddc_runtime/operations.dart |
| diff --git a/tool/input_sdk/private/ddc_runtime/operations.dart b/tool/input_sdk/private/ddc_runtime/operations.dart |
| index 97359b68e263c0fb5b73c9a93407d39f31b294e6..bdd31e2e3fdbae9908e2ef4a87fba5e2d1e1f301 100644 |
| --- a/tool/input_sdk/private/ddc_runtime/operations.dart |
| +++ b/tool/input_sdk/private/ddc_runtime/operations.dart |
| @@ -121,7 +121,7 @@ _checkAndCall(f, ftype, obj, typeArgs, args, name) => JS('', '''(() => { |
| let formalCount = $ftype[$_typeFormalCount]; |
| if (formalCount != null) { |
| if ($typeArgs == null) { |
| - $typeArgs = Array(formalCount).fill($dynamicR); |
| + $typeArgs = Array(formalCount).fill($dynamic); |
| } else if ($typeArgs.length != formalCount) { |
| // TODO(jmesserly): is this the right error? |
| $throwStrongModeError( |
| @@ -268,10 +268,10 @@ equals(x, y) => JS('', '''(() => { |
| })()'''); |
| /// Checks that `x` is not null or undefined. */ |
| -notNull(x) => JS('', '''(() => { |
| - if ($x == null) $throwNullValueError(); |
| - return $x; |
| -})()'''); |
| +notNull(x) { |
| + if (x == null) throwNullValueError(); |
| + return x; |
| +} |
| /// |
| /// Creates a dart:collection LinkedHashMap. |
| @@ -290,8 +290,8 @@ notNull(x) => JS('', '''(() => { |
| // TODO(jmesserly): we can use default values `= dynamic` once #417 is fixed. |
| // TODO(jmesserly): move this to classes for consistentcy with list literals? |
| map(values, [K, V]) => JS('', '''(() => { |
| - if ($K == null) $K = $dynamicR; |
| - if ($V == null) $V = $dynamicR; |
| + if ($K == null) $K = $dynamic; |
| + if ($V == null) $V = $dynamic; |
| let map = ${getGenericClass(LinkedHashMap)}($K, $V).new(); |
| if (Array.isArray($values)) { |
| for (let i = 0, end = $values.length - 1; i < end; i += 2) { |
| @@ -419,43 +419,61 @@ const_(obj) => JS('', '''(() => { |
| // The following are helpers for Object methods when the receiver |
| // may be null or primitive. These should only be generated by |
| // the compiler. |
| -hashCode(obj) => JS('', '''(() => { |
| - if ($obj == null) { |
| - return 0; |
| +hashCode(obj) { |
| + if (obj == null) return 0; |
| + |
| + switch (JS('String', 'typeof #', obj)) { |
| + case "number": |
| + return JS('','# & 0x1FFFFFFF', obj); |
| + case "boolean": |
| + // From JSBool.hashCode, see comment there. |
| + return JS('', '# ? (2 * 3 * 23 * 3761) : (269 * 811)', obj); |
| } |
| - // TODO(vsm): What should we do for primitives and non-Dart objects? |
| - switch (typeof $obj) { |
| - case "number": |
| - case "boolean": |
| - return $obj & 0x1FFFFFFF; |
| - case "string": |
| - // TODO(vsm): Call the JSString hashCode? |
| - return $obj.length; |
| + |
| + var extension = getExtensionType(obj); |
| + if (extension != null) { |
| + return JS('', '#[dartx.hashCode]', obj); |
| } |
| - return $obj.hashCode; |
| -})()'''); |
| + return JS('', '#.hashCode', obj); |
| +} |
| -toString(obj) => JS('', '''(() => { |
| - if ($obj == null) { |
| - return "null"; |
| +@JSExportName('toString') |
| +_toString(obj) { |
| + if (obj == null) return "null"; |
| + |
| + var extension = getExtensionType(obj); |
| + if (extension != null) { |
| + return JS('', '#[dartx.toString]()', obj); |
| } |
| - return $obj.toString(); |
| -})()'''); |
| + return JS('', '#.toString()', obj); |
| +} |
| -noSuchMethod(obj, invocation) => JS('', '''(() => { |
| - if ($obj == null) { |
| - $throwNoSuchMethod($obj, $invocation.memberName, |
| - $invocation.positionalArguments, $invocation.namedArguments); |
| +// TODO(jmesserly): is the argument type verified statically? |
| +noSuchMethod(obj, Invocation invocation) { |
| + if (obj == null) { |
| + throw new NoSuchMethodError( |
| + null, |
| + invocation.memberName, |
| + invocation.positionalArguments, |
| + invocation.namedArguments); |
| } |
| - switch (typeof $obj) { |
| - case "number": |
| - case "boolean": |
| - case "string": |
| - $throwNoSuchMethod($obj, $invocation.memberName, |
| - $invocation.positionalArguments, $invocation.namedArguments); |
| + // TODO(jmesserly): I don't think any extension types define nSM. If they |
| + // do we need to add a cast here. |
|
vsm
2016/05/09 20:55:56
Can we sanity check?
var extension = getExtension
Jennifer Messerly
2016/05/10 00:33:57
Not sure I follow that code example, but yes I wen
|
| + return JS('', '#.noSuchMethod(#)', obj, invocation); |
| +} |
| + |
| +runtimeType(obj) { |
| + // Handle primitives where the method isn't on the object. |
| + var result = _checkPrimitiveType(obj); |
| + if (result != null) return wrapType(result); |
| + |
| + // Delegate to the (possibly user-defined) method on the object. |
| + var extension = getExtensionType(obj); |
| + if (extension != null) { |
| + return JS('', '#[dartx.runtimeType]', obj); |
| } |
| - return $obj.noSuchMethod($invocation); |
| -})()'''); |
| + return JS('', '#.runtimeType', obj); |
| +} |
| final JsIterator = JS('', ''' |
| class JsIterator { |