| Index: lib/runtime/dart_runtime.js
|
| diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js
|
| index bb9353b2e7b7f08ba8dcb91f82337d55240bb279..3e9d6baad776f3e51fff074dbb3496224f50b61f 100644
|
| --- a/lib/runtime/dart_runtime.js
|
| +++ b/lib/runtime/dart_runtime.js
|
| @@ -96,7 +96,7 @@ var dart, _js_helper;
|
| function dindex(obj, index) {
|
| // TODO(jmesserly): remove this special case once Array extensions are
|
| // hooked up.
|
| - if (obj instanceof Array && getRuntimeType(index) == core.int) {
|
| + if (obj instanceof Array && realRuntimeType(index) == core.int) {
|
| return obj[index];
|
| }
|
| return checkAndCall(obj.get, obj, [index], '[]');
|
| @@ -122,7 +122,7 @@ var dart, _js_helper;
|
| function cast(obj, type) {
|
| // TODO(vsm): handle non-nullable types
|
| if (obj == null) return obj;
|
| - let actual = getRuntimeType(obj);
|
| + let actual = realRuntimeType(obj);
|
| if (isSubtype(actual, type)) return obj;
|
| throw new _js_helper.CastErrorImplementation(actual, type);
|
| }
|
| @@ -130,15 +130,9 @@ var dart, _js_helper;
|
|
|
|
|
| // TODO(vsm): How should we encode the runtime type?
|
| - let runtimeType = Symbol('runtimeType');
|
| + let _runtimeType = Symbol('_runtimeType');
|
|
|
| - /**
|
| - * Returns the runtime type of obj. This is the same as `obj.runtimeType`
|
| - * but will not call an overridden getter.
|
| - *
|
| - * Currently this will return null for non-Dart objects.
|
| - */
|
| - function getRuntimeType(obj) {
|
| + function checkPrimitiveType(obj) {
|
| switch (typeof obj) {
|
| case "undefined":
|
| return core.Null;
|
| @@ -154,9 +148,21 @@ var dart, _js_helper;
|
| // Undefined is handled above. For historical reasons,
|
| // typeof null == "object" in JS.
|
| if (obj === null) return core.Null;
|
| + return null;
|
| + }
|
| +
|
| + /**
|
| + * Returns the runtime type of obj. This is the same as `obj.realRuntimeType`
|
| + * but will not call an overridden getter.
|
| + *
|
| + * Currently this will return null for non-Dart objects.
|
| + */
|
| + function realRuntimeType(obj) {
|
| + var result = checkPrimitiveType(obj);
|
| + if (result !== null) return result;
|
| // TODO(vsm): Should we treat Dart and JS objects differently here?
|
| // E.g., we can check if obj instanceof core.Object to differentiate.
|
| - var result = obj[runtimeType];
|
| + result = obj[_runtimeType];
|
| if (result) return result;
|
| result = obj.constructor;
|
| if (result == Function) {
|
| @@ -164,10 +170,10 @@ var dart, _js_helper;
|
| }
|
| return result;
|
| }
|
| - dart.getRuntimeType = getRuntimeType;
|
| + dart.realRuntimeType = realRuntimeType;
|
|
|
| function instanceOf(obj, type) {
|
| - return isSubtype(getRuntimeType(obj), type);
|
| + return isSubtype(realRuntimeType(obj), type);
|
| }
|
| dart.is = instanceOf;
|
|
|
| @@ -848,7 +854,7 @@ var dart, _js_helper;
|
| * - nested values of the object are themselves already canonicalized.
|
| */
|
| function constant(obj) {
|
| - let objectKey = [getRuntimeType(obj)];
|
| + let objectKey = [realRuntimeType(obj)];
|
| // There's no guarantee in JS that names/symbols are returned in the same
|
| // order. We could probably get the same order if we're judicious about
|
| // initializing them, but easier to not depend on that.
|
| @@ -863,10 +869,61 @@ var dart, _js_helper;
|
|
|
| /** Sets the runtime type of `obj` to be `type` */
|
| function setType(obj, type) {
|
| - obj[runtimeType] = type;
|
| + obj[_runtimeType] = type;
|
| }
|
| dart.setType = setType;
|
|
|
| + // The following are helpers for Object methods when the receiver
|
| + // may be null or primitive. These should only be generated by
|
| + // the compiler.
|
| + function hashCode(obj) {
|
| + if (obj == null) {
|
| + return 0;
|
| + }
|
| + // 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;
|
| + }
|
| + return obj.hashCode;
|
| + }
|
| + dart.hashCode = hashCode;
|
| +
|
| + function runtimeType(obj) {
|
| + var result = checkPrimitiveType(obj);
|
| + if (result !== null) return result;
|
| + return obj.runtimeType;
|
| + }
|
| + dart.runtimeType = runtimeType;
|
| +
|
| + function toString(obj) {
|
| + if (obj == null) {
|
| + return "null";
|
| + }
|
| + return obj.toString();
|
| + }
|
| + dart.toString = toString;
|
| +
|
| + function noSuchMethod(obj, invocation) {
|
| + if (obj == null) {
|
| + throw new core.NoSuchMethodError(obj, invocation.memberName,
|
| + invocation.positionalArguments, invocation.namedArguments);
|
| + }
|
| + switch (typeof obj) {
|
| + case "number":
|
| + case "boolean":
|
| + case "string":
|
| + throw new core.NoSuchMethodError(obj, invocation.memberName,
|
| + invocation.positionalArguments, invocation.namedArguments);
|
| + }
|
| + return obj.noSuchMethod(invocation);
|
| + }
|
| + dart.noSuchMethod = noSuchMethod;
|
| +
|
| // TODO(jmesserly): right now this is a sentinel. It should be a type object
|
| // of some sort, assuming we keep around `dynamic` at runtime.
|
| dart.dynamic = { toString() { return 'dynamic'; } };
|
|
|