Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: tool/input_sdk/private/ddc_runtime/operations.dart

Issue 1962823002: fix #552, Object members on native types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tool/input_sdk/private/ddc_runtime/generators.dart ('k') | tool/input_sdk/private/ddc_runtime/rtti.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 dcf385485b2c6dbd08d11071679ff401c1c3fee2..9f4891f4158adf4e6562d5a6907fb0245a4484bc 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(
@@ -290,10 +290,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.
@@ -312,8 +312,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) {
@@ -441,43 +441,64 @@ 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);
+ // Delegate to the (possibly user-defined) method on the object.
+ var extension = getExtensionType(obj);
+ if (extension != null) {
+ return JS('', '#[dartx.noSuchMethod](#)', obj, invocation);
}
- return $obj.noSuchMethod($invocation);
-})()''');
+ 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 JS('', '#.runtimeType', obj);
+}
final JsIterator = JS('', '''
class JsIterator {
« no previous file with comments | « tool/input_sdk/private/ddc_runtime/generators.dart ('k') | tool/input_sdk/private/ddc_runtime/rtti.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698