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

Unified Diff: sdk/lib/_internal/lib/native_helper.dart

Issue 35893008: Preemptive initialization of dispatch records (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « sdk/lib/_internal/lib/interceptors.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/native_helper.dart
diff --git a/sdk/lib/_internal/lib/native_helper.dart b/sdk/lib/_internal/lib/native_helper.dart
index bbee3a5797a58263f1eed33c5e5d5f6118e813d5..8592e917605e6f42770121f4d0ac3a60c343aaf6 100644
--- a/sdk/lib/_internal/lib/native_helper.dart
+++ b/sdk/lib/_internal/lib/native_helper.dart
@@ -285,8 +285,7 @@ lookupDispatchRecord(obj) {
return null;
}
var interceptor = JS('', '#.prototype', interceptorClass);
- var isLeaf =
- (leafTags != null) && JS('bool', '(#[#]) === true', leafTags, tag);
+ var isLeaf = JS('bool', '(#[#]) === true', leafTags, tag);
if (isLeaf) {
return makeLeafDispatchRecord(interceptor);
} else {
@@ -301,6 +300,44 @@ makeLeafDispatchRecord(interceptor) {
return makeDispatchRecord(interceptor, false, null, indexability);
}
+makeDefaultDispatchRecord(tag, interceptorClass, proto) {
+ var interceptor = JS('', '#.prototype', interceptorClass);
+ var isLeaf = JS('bool', '(#[#]) === true', leafTags, tag);
+ if (isLeaf) {
+ return makeLeafDispatchRecord(interceptor);
+ } else {
+ return makeDispatchRecord(interceptor, proto, null, null);
+ }
+}
+
+var initNativeDispatchFlag; // null or true
+
+void initNativeDispatch() {
+ initNativeDispatchFlag = true;
+
+ // Try to pro-actively patch prototypes of DOM objects. For each of our known
+ // tags `TAG`, if `window.TAG` is a (constructor) function, set the dispatch
+ // property if the function's prototype to a dispatch record.
+ if (JS('bool', 'typeof window != "undefined"')) {
+ var context = JS('=Object', 'window');
+ var map = interceptorsByTag;
+ var tags = JS('JSMutableArray', 'Object.getOwnPropertyNames(#)', map);
+ for (int i = 0; i < tags.length; i++) {
+ var tag = tags[i];
+ if (JS('bool', 'typeof (#[#]) == "function"', context, tag)) {
+ var constructor = JS('', '#[#]', context, tag);
+ var proto = JS('', '#.prototype', constructor);
+ var interceptorClass = JS('', '#[#]', map, tag);
+ var record = makeDefaultDispatchRecord(tag, interceptorClass, proto);
+ if (record != null) {
+ setDispatchProperty(proto, record);
+ }
+ }
+ }
+ }
+}
+
+
/**
* [proto] should have no shadowing prototypes that are not also assigned a
* dispatch rescord.
« no previous file with comments | « sdk/lib/_internal/lib/interceptors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698