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

Unified Diff: lib/runtime/dart_runtime.js

Issue 1100633006: Generate static calls for Object fields and methods (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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
Index: lib/runtime/dart_runtime.js
diff --git a/lib/runtime/dart_runtime.js b/lib/runtime/dart_runtime.js
index 01791fdc06a5c9cc1c9e6bc0251e7edd0d6cdf44..263b8798bd9191d458ca08300f39d34b94b9c094 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 && runtimeType(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 = runtimeType(obj);
if (isSubtype(actual, type)) return obj;
throw new _js_helper.CastErrorImplementation(actual, type);
}
@@ -130,7 +130,7 @@ 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`
@@ -138,7 +138,7 @@ var dart, _js_helper;
*
* Currently this will return null for non-Dart objects.
*/
- function getRuntimeType(obj) {
+ function runtimeType(obj) {
Jennifer Messerly 2015/04/23 19:01:42 The intent of this method was "get the _real_ runt
vsm 2015/04/23 20:35:55 I've split this back out for now. The other optio
switch (typeof obj) {
case "undefined":
return core.Null;
@@ -156,7 +156,7 @@ var dart, _js_helper;
if (obj === null) return core.Null;
// 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];
+ var result = obj[_runtimeType];
if (result) return result;
result = obj.constructor;
if (result == Function) {
@@ -164,10 +164,10 @@ var dart, _js_helper;
}
return result;
}
- dart.getRuntimeType = getRuntimeType;
+ dart.runtimeType = runtimeType;
function instanceOf(obj, type) {
- return isSubtype(getRuntimeType(obj), type);
+ return isSubtype(runtimeType(obj), type);
}
dart.is = instanceOf;
@@ -832,7 +832,7 @@ var dart, _js_helper;
* - nested values of the object are themselves already canonicalized.
*/
function constant(obj) {
- let objectKey = [getRuntimeType(obj)];
+ let objectKey = [runtimeType(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.
@@ -847,10 +847,38 @@ 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;
+ function hashCode(obj) {
+ if (obj == null) {
+ return 0;
+ }
+ // TODO(vsm): What should we do for primitives and non-Dart objects?
+ switch (typeof obj) {
+ case "undefined":
+ return core.Null;
Jennifer Messerly 2015/04/23 19:01:41 copy+paste error? this code can't be reached. `obj
vsm 2015/04/23 20:35:55 Done.
+ case "number":
+ return obj & 0x1FFFFFFF;
+ case "boolean":
+ return obj & 0x1FFFFFFF;
+ case "string":
+ // TODO(vsm): Call the JSString hashCode?
Jennifer Messerly 2015/04/23 19:01:42 +1
vsm 2015/04/23 20:35:55 Will look at primitives next.
+ return obj.length;
+ }
+ return obj.hashCode;
+ }
+ dart.hashCode = hashCode;
+
+ function toString(obj) {
Jennifer Messerly 2015/04/23 19:02:54 oh, just noticed noSuchMethod helper is missing?
vsm 2015/04/23 20:35:55 Added.
+ if (obj == null) {
+ return "null";
+ }
+ return obj.toString();
Jennifer Messerly 2015/04/23 19:02:54 we'll have to make sure to never call dart.toStrin
vsm 2015/04/23 20:35:55 Good point! I added a check to the codegen that s
+ }
+ dart.toString = toString;
+
// 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'; } };

Powered by Google App Engine
This is Rietveld 408576698