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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart

Issue 2980853002: Registration-based approach to cross frame support. (Closed)
Patch Set: Created 3 years, 5 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: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
index 4a8670bd65178dbd7914982df4ac822520dfaddc..8a9cd63fb563c914a6490b3cf637e773d1cd4a9c 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart
@@ -410,7 +410,10 @@ defineExtensionNames(names) =>
/// Install properties in prototype-first order. Properties / descriptors from
/// more specific types should overwrite ones from less specific types.
void _installProperties(jsProto, dartType, installedParent) {
- if (JS('bool', '# === #', dartType, Object)) {
+ // Extension types should bottom out at core.Object. The one exception
+ // is JSArray, which we rewire to the native Array type.
Jennifer Messerly 2017/07/14 19:38:08 hmmm wait I don't understand the JSArray comment.
+ if (JS('bool', '# === # || # === #.Object', dartType, Object, dartType,
+ global_)) {
_installPropertiesForObject(jsProto);
return;
}
@@ -437,15 +440,20 @@ void _installPropertiesForObject(jsProto) {
}
}
-/// Copy symbols from the prototype of the source to destination.
-/// These are the only properties safe to copy onto an existing public
-/// JavaScript class.
-registerExtension(jsType, dartExtType) => JS(
+var _extensionMap;
Jennifer Messerly 2017/07/14 19:38:08 this can be eager initialized: final _extensi
vsm 2017/07/19 15:59:02 Done.
+
+_cacheExtension(name, dartExtType) {
+ if (_extensionMap == null) _extensionMap = JS('', 'new Map()');
+ JS('', '#.set(#, #)', _extensionMap, name, dartExtType);
+}
+
+_applyExtension(jsType, dartExtType) => JS(
'',
'''(() => {
// TODO(vsm): Not all registered js types are real.
if (!jsType) return;
+ let extProto = $dartExtType.prototype;
Jennifer Messerly 2017/07/14 19:38:08 this line is unused. I'm guessing it was a merge c
vsm 2017/07/19 15:59:02 Done.
let jsProto = $jsType.prototype;
// TODO(vsm): This sometimes doesn't exist on FF. These types will be
@@ -462,7 +470,7 @@ registerExtension(jsType, dartExtType) => JS(
if (originalDesc === void 0) return;
let originalSigFn = originalDesc.get;
$assert_(originalSigFn);
- $defineMemoizedGetter($jsType, sigF, originalSigFn);
+ $defineMemoizedGetter(jsType, sigF, originalSigFn);
}
updateSig($_methodSig);
updateSig($_fieldSig);
@@ -470,6 +478,22 @@ registerExtension(jsType, dartExtType) => JS(
updateSig($_setterSig);
})()''');
+/// Apply all registered extensions to a window. This is intended for
+/// different frames, where registrations need to be reapplied.
+applyAllExtensions(global) {
+ JS('', '#.forEach((dartExtType, name) => #(#[name], dartExtType))',
+ _extensionMap, _applyExtension, global);
+}
+
+/// Copy symbols from the prototype of the source to destination.
+/// These are the only properties safe to copy onto an existing public
+/// JavaScript class.
+registerExtension(name, dartExtType) {
+ _cacheExtension(name, dartExtType);
Jennifer Messerly 2017/07/14 19:38:08 based on suggestion above this is a 1-liner now an
vsm 2017/07/19 15:59:01 Done.
+ var jsType = JS('', '#[#]', global_, name);
+ _applyExtension(jsType, dartExtType);
+}
+
///
/// Mark a concrete type as implementing extension methods.
/// For example: `class MyIter implements Iterable`.

Powered by Google App Engine
This is Rietveld 408576698