mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:37:12 +00:00
Start using the dart2js type conversions in Dartium as well.
BUG= Review URL: https://codereview.chromium.org//1349293006 .
This commit is contained in:
parent
14b726f3e6
commit
aebb870b13
|
@ -1149,20 +1149,18 @@ wrap_jso(jsObject) {
|
|||
// JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
|
||||
return jsObject;
|
||||
}
|
||||
// Try the most general type conversions on it.
|
||||
// TODO(alanknight): We may be able to do better. This maintains identity,
|
||||
// which is useful, but expensive. And if we nest something that only
|
||||
// this conversion handles, how does that work? e.g. a list of maps of elements.
|
||||
var converted = convertNativeToDart_SerializedScriptValue(jsObject);
|
||||
if (!identical(converted, jsObject)) {
|
||||
return converted;
|
||||
}
|
||||
var constructor = jsObject['constructor'];
|
||||
if (__interop_checks) {
|
||||
if (jsObject is js.JsArray) {
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
debug_or_assert("constructor != null", constructor != null);
|
||||
}
|
||||
if (constructor == js.context['Object']) {
|
||||
return convertNativeObjectToDartMap(jsObject);
|
||||
}
|
||||
if (constructor == js.context['Promise']) {
|
||||
return convertNativePromiseToDartFuture(jsObject);
|
||||
}
|
||||
var jsTypeName = constructor['name'];
|
||||
if (__interop_checks) {
|
||||
debug_or_assert("constructor != null && jsTypeName.length > 0", constructor != null && jsTypeName.length > 0);
|
||||
|
@ -1193,7 +1191,7 @@ wrap_jso(jsObject) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create Dart class that maps to the JS Type that is the JS type being
|
||||
* Create Dart class that maps to the JS Type that is the JS type being
|
||||
* extended using JS interop createCallback (we need the base type of the
|
||||
* custom element) not the Dart created constructor.
|
||||
*/
|
||||
|
@ -1270,6 +1268,8 @@ Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) {
|
|||
|
||||
// Converts a flat Dart map into a JavaScript object with properties this is
|
||||
// is the Dartium only version it uses dart:js.
|
||||
// TODO(alanknight): This could probably be unified with the dart2js conversions
|
||||
// code in html_common and be more general.
|
||||
convertDartToNative_Dictionary(Map dict) {
|
||||
if (dict == null) return null;
|
||||
var jsObject = new js.JsObject(js.context['Object']);
|
||||
|
@ -1293,14 +1293,6 @@ convertDartToNative_List(List input) => new js.JsArray()..addAll(input);
|
|||
// Conversion function place holder (currently not used in dart2js or dartium).
|
||||
List convertDartToNative_StringArray(List<String> input) => input;
|
||||
|
||||
Future convertNativePromiseToDartFuture(js.JsObject promise) {
|
||||
var completer = new Completer();
|
||||
var newPromise = promise
|
||||
.callMethod("then", [(result) => completer.complete(result)])
|
||||
.callMethod("catch", [(result) => completer.completeError(result)]);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
@ -3378,7 +3370,7 @@ class CanvasElement extends HtmlElement implements CanvasImageSource {
|
|||
|
||||
@DomName('HTMLCanvasElement.getContext')
|
||||
@DocsEditable()
|
||||
Object getContext(String contextId, [Map attrs]) => wrap_jso(_blink.BlinkHTMLCanvasElement.instance.getContext_Callback_2_(unwrap_jso(this), contextId, attrs != null ? new js.JsObject.jsify(attrs) : attrs));
|
||||
Object getContext(String contextId, [Map attrs]) => wrap_jso(_blink.BlinkHTMLCanvasElement.instance.getContext_Callback_2_(unwrap_jso(this), contextId, convertDartToNative_Dictionary(attrs)));
|
||||
|
||||
@DomName('HTMLCanvasElement.toDataURL')
|
||||
@DocsEditable()
|
||||
|
@ -3818,7 +3810,7 @@ class CanvasRenderingContext2D extends NativeFieldWrapperClass2 implements Canva
|
|||
|
||||
void addHitRegion([Map options]) {
|
||||
if (options != null) {
|
||||
_blink.BlinkCanvasRenderingContext2D.instance.addHitRegion_Callback_1_(unwrap_jso(this), options != null ? new js.JsObject.jsify(options) : options);
|
||||
_blink.BlinkCanvasRenderingContext2D.instance.addHitRegion_Callback_1_(unwrap_jso(this), convertDartToNative_Dictionary(options));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkCanvasRenderingContext2D.instance.addHitRegion_Callback_0_(unwrap_jso(this));
|
||||
|
@ -5058,7 +5050,7 @@ class CredentialsContainer extends NativeFieldWrapperClass2 {
|
|||
|
||||
Future request([Map options]) {
|
||||
if (options != null) {
|
||||
return wrap_jso(_blink.BlinkCredentialsContainer.instance.request_Callback_1_(unwrap_jso(this), options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkCredentialsContainer.instance.request_Callback_1_(unwrap_jso(this), convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkCredentialsContainer.instance.request_Callback_0_(unwrap_jso(this)));
|
||||
}
|
||||
|
@ -10037,15 +10029,15 @@ class DirectoryEntry extends Entry {
|
|||
|
||||
void __getDirectory(String path, {Map options, _EntryCallback successCallback, _ErrorCallback errorCallback}) {
|
||||
if (errorCallback != null) {
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_4_(unwrap_jso(this), path, options != null ? new js.JsObject.jsify(options) : options, unwrap_jso((entry) => successCallback(wrap_jso(entry))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_4_(unwrap_jso(this), path, convertDartToNative_Dictionary(options), unwrap_jso((entry) => successCallback(wrap_jso(entry))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
return;
|
||||
}
|
||||
if (successCallback != null) {
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_3_(unwrap_jso(this), path, options != null ? new js.JsObject.jsify(options) : options, unwrap_jso((entry) => successCallback(wrap_jso(entry))));
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_3_(unwrap_jso(this), path, convertDartToNative_Dictionary(options), unwrap_jso((entry) => successCallback(wrap_jso(entry))));
|
||||
return;
|
||||
}
|
||||
if (options != null) {
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_2_(unwrap_jso(this), path, options != null ? new js.JsObject.jsify(options) : options);
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_2_(unwrap_jso(this), path, convertDartToNative_Dictionary(options));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkDirectoryEntry.instance.getDirectory_Callback_1_(unwrap_jso(this), path);
|
||||
|
@ -10062,15 +10054,15 @@ class DirectoryEntry extends Entry {
|
|||
|
||||
void __getFile(String path, {Map options, _EntryCallback successCallback, _ErrorCallback errorCallback}) {
|
||||
if (errorCallback != null) {
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_4_(unwrap_jso(this), path, options != null ? new js.JsObject.jsify(options) : options, unwrap_jso((entry) => successCallback(wrap_jso(entry))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_4_(unwrap_jso(this), path, convertDartToNative_Dictionary(options), unwrap_jso((entry) => successCallback(wrap_jso(entry))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
return;
|
||||
}
|
||||
if (successCallback != null) {
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_3_(unwrap_jso(this), path, options != null ? new js.JsObject.jsify(options) : options, unwrap_jso((entry) => successCallback(wrap_jso(entry))));
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_3_(unwrap_jso(this), path, convertDartToNative_Dictionary(options), unwrap_jso((entry) => successCallback(wrap_jso(entry))));
|
||||
return;
|
||||
}
|
||||
if (options != null) {
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_2_(unwrap_jso(this), path, options != null ? new js.JsObject.jsify(options) : options);
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_2_(unwrap_jso(this), path, convertDartToNative_Dictionary(options));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkDirectoryEntry.instance.getFile_Callback_1_(unwrap_jso(this), path);
|
||||
|
@ -18619,7 +18611,7 @@ class FormElement extends HtmlElement {
|
|||
@DocsEditable()
|
||||
// http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-October/037711.html
|
||||
@Experimental()
|
||||
void requestAutocomplete(Map details) => _blink.BlinkHTMLFormElement.instance.requestAutocomplete_Callback_1_(unwrap_jso(this), details != null ? new js.JsObject.jsify(details) : details);
|
||||
void requestAutocomplete(Map details) => _blink.BlinkHTMLFormElement.instance.requestAutocomplete_Callback_1_(unwrap_jso(this), convertDartToNative_Dictionary(details));
|
||||
|
||||
@DomName('HTMLFormElement.reset')
|
||||
@DocsEditable()
|
||||
|
@ -18943,7 +18935,7 @@ class Geolocation extends NativeFieldWrapperClass2 {
|
|||
|
||||
void _getCurrentPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Map options]) {
|
||||
if (options != null) {
|
||||
_blink.BlinkGeolocation.instance.getCurrentPosition_Callback_3_(unwrap_jso(this), unwrap_jso((position) => successCallback(wrap_jso(position))), unwrap_jso((error) => errorCallback(wrap_jso(error))), options != null ? new js.JsObject.jsify(options) : options);
|
||||
_blink.BlinkGeolocation.instance.getCurrentPosition_Callback_3_(unwrap_jso(this), unwrap_jso((position) => successCallback(wrap_jso(position))), unwrap_jso((error) => errorCallback(wrap_jso(error))), convertDartToNative_Dictionary(options));
|
||||
return;
|
||||
}
|
||||
if (errorCallback != null) {
|
||||
|
@ -18956,7 +18948,7 @@ class Geolocation extends NativeFieldWrapperClass2 {
|
|||
|
||||
int _watchPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Map options]) {
|
||||
if (options != null) {
|
||||
return _blink.BlinkGeolocation.instance.watchPosition_Callback_3_(unwrap_jso(this), unwrap_jso((position) => successCallback(wrap_jso(position))), unwrap_jso((error) => errorCallback(wrap_jso(error))), options != null ? new js.JsObject.jsify(options) : options);
|
||||
return _blink.BlinkGeolocation.instance.watchPosition_Callback_3_(unwrap_jso(this), unwrap_jso((position) => successCallback(wrap_jso(position))), unwrap_jso((error) => errorCallback(wrap_jso(error))), convertDartToNative_Dictionary(options));
|
||||
}
|
||||
if (errorCallback != null) {
|
||||
return _blink.BlinkGeolocation.instance.watchPosition_Callback_2_(unwrap_jso(this), unwrap_jso((position) => successCallback(wrap_jso(position))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
|
@ -26083,7 +26075,7 @@ class MessagePort extends EventTarget {
|
|||
|
||||
@DomName('MessagePort.postMessage')
|
||||
@DocsEditable()
|
||||
void postMessage(Object message, [List<MessagePort> transfer]) => _blink.BlinkMessagePort.instance.postMessage_Callback_2_(unwrap_jso(this), message, transfer);
|
||||
void postMessage(Object message, [List<MessagePort> transfer]) => _blink.BlinkMessagePort.instance.postMessage_Callback_2_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(message), transfer);
|
||||
|
||||
@DomName('MessagePort.start')
|
||||
@DocsEditable()
|
||||
|
@ -27129,7 +27121,7 @@ class MutationObserver extends NativeFieldWrapperClass2 {
|
|||
|
||||
@DomName('MutationObserver.observe')
|
||||
@DocsEditable()
|
||||
void _observe(Node target, Map options) => _blink.BlinkMutationObserver.instance.observe_Callback_2_(unwrap_jso(this), unwrap_jso(target), options != null ? new js.JsObject.jsify(options) : options);
|
||||
void _observe(Node target, Map options) => _blink.BlinkMutationObserver.instance.observe_Callback_2_(unwrap_jso(this), unwrap_jso(target), convertDartToNative_Dictionary(options));
|
||||
|
||||
@DomName('MutationObserver.takeRecords')
|
||||
@DocsEditable()
|
||||
|
@ -27487,7 +27479,7 @@ class Navigator extends NativeFieldWrapperClass2 implements NavigatorCpu, Naviga
|
|||
@DocsEditable()
|
||||
// http://dev.w3.org/2011/webrtc/editor/getusermedia.html#navigatorusermedia
|
||||
@Experimental()
|
||||
void _getUserMedia(Map options, _NavigatorUserMediaSuccessCallback successCallback, _NavigatorUserMediaErrorCallback errorCallback) => _blink.BlinkNavigator.instance.webkitGetUserMedia_Callback_3_(unwrap_jso(this), options != null ? new js.JsObject.jsify(options) : options, unwrap_jso((stream) => successCallback(wrap_jso(stream))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
void _getUserMedia(Map options, _NavigatorUserMediaSuccessCallback successCallback, _NavigatorUserMediaErrorCallback errorCallback) => _blink.BlinkNavigator.instance.webkitGetUserMedia_Callback_3_(unwrap_jso(this), convertDartToNative_Dictionary(options), unwrap_jso((stream) => successCallback(wrap_jso(stream))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
|
||||
|
||||
@DomName('Navigator.hardwareConcurrency')
|
||||
@DocsEditable()
|
||||
|
@ -31608,7 +31600,7 @@ class RtcPeerConnection extends EventTarget {
|
|||
|
||||
void addStream(MediaStream stream, [Map mediaConstraints]) {
|
||||
if (mediaConstraints != null) {
|
||||
_blink.BlinkRTCPeerConnection.instance.addStream_Callback_2_(unwrap_jso(this), unwrap_jso(stream), mediaConstraints != null ? new js.JsObject.jsify(mediaConstraints) : mediaConstraints);
|
||||
_blink.BlinkRTCPeerConnection.instance.addStream_Callback_2_(unwrap_jso(this), unwrap_jso(stream), convertDartToNative_Dictionary(mediaConstraints));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkRTCPeerConnection.instance.addStream_Callback_1_(unwrap_jso(this), unwrap_jso(stream));
|
||||
|
@ -31621,7 +31613,7 @@ class RtcPeerConnection extends EventTarget {
|
|||
|
||||
void _createAnswer(_RtcSessionDescriptionCallback successCallback, [_RtcErrorCallback failureCallback, Map mediaConstraints]) {
|
||||
if (mediaConstraints != null) {
|
||||
_blink.BlinkRTCPeerConnection.instance.createAnswer_Callback_3_(unwrap_jso(this), unwrap_jso((sdp) => successCallback(wrap_jso(sdp))), unwrap_jso((errorInformation) => failureCallback(errorInformation)), mediaConstraints != null ? new js.JsObject.jsify(mediaConstraints) : mediaConstraints);
|
||||
_blink.BlinkRTCPeerConnection.instance.createAnswer_Callback_3_(unwrap_jso(this), unwrap_jso((sdp) => successCallback(wrap_jso(sdp))), unwrap_jso((errorInformation) => failureCallback(errorInformation)), convertDartToNative_Dictionary(mediaConstraints));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkRTCPeerConnection.instance.createAnswer_Callback_2_(unwrap_jso(this), unwrap_jso((sdp) => successCallback(wrap_jso(sdp))), unwrap_jso((errorInformation) => failureCallback(errorInformation)));
|
||||
|
@ -31634,14 +31626,14 @@ class RtcPeerConnection extends EventTarget {
|
|||
|
||||
RtcDataChannel createDataChannel(String label, [Map options]) {
|
||||
if (options != null) {
|
||||
return wrap_jso(_blink.BlinkRTCPeerConnection.instance.createDataChannel_Callback_2_(unwrap_jso(this), label, options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkRTCPeerConnection.instance.createDataChannel_Callback_2_(unwrap_jso(this), label, convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkRTCPeerConnection.instance.createDataChannel_Callback_1_(unwrap_jso(this), label));
|
||||
}
|
||||
|
||||
void _createOffer(_RtcSessionDescriptionCallback successCallback, [_RtcErrorCallback failureCallback, Map rtcOfferOptions]) {
|
||||
if (rtcOfferOptions != null) {
|
||||
_blink.BlinkRTCPeerConnection.instance.createOffer_Callback_3_(unwrap_jso(this), unwrap_jso((sdp) => successCallback(wrap_jso(sdp))), unwrap_jso((errorInformation) => failureCallback(errorInformation)), rtcOfferOptions != null ? new js.JsObject.jsify(rtcOfferOptions) : rtcOfferOptions);
|
||||
_blink.BlinkRTCPeerConnection.instance.createOffer_Callback_3_(unwrap_jso(this), unwrap_jso((sdp) => successCallback(wrap_jso(sdp))), unwrap_jso((errorInformation) => failureCallback(errorInformation)), convertDartToNative_Dictionary(rtcOfferOptions));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkRTCPeerConnection.instance.createOffer_Callback_2_(unwrap_jso(this), unwrap_jso((sdp) => successCallback(wrap_jso(sdp))), unwrap_jso((errorInformation) => failureCallback(errorInformation)));
|
||||
|
@ -31694,11 +31686,11 @@ class RtcPeerConnection extends EventTarget {
|
|||
|
||||
void updateIce([Map configuration, Map mediaConstraints]) {
|
||||
if (mediaConstraints != null) {
|
||||
_blink.BlinkRTCPeerConnection.instance.updateIce_Callback_2_(unwrap_jso(this), configuration != null ? new js.JsObject.jsify(configuration) : configuration, mediaConstraints != null ? new js.JsObject.jsify(mediaConstraints) : mediaConstraints);
|
||||
_blink.BlinkRTCPeerConnection.instance.updateIce_Callback_2_(unwrap_jso(this), convertDartToNative_Dictionary(configuration), convertDartToNative_Dictionary(mediaConstraints));
|
||||
return;
|
||||
}
|
||||
if (configuration != null) {
|
||||
_blink.BlinkRTCPeerConnection.instance.updateIce_Callback_1_(unwrap_jso(this), configuration != null ? new js.JsObject.jsify(configuration) : configuration);
|
||||
_blink.BlinkRTCPeerConnection.instance.updateIce_Callback_1_(unwrap_jso(this), convertDartToNative_Dictionary(configuration));
|
||||
return;
|
||||
}
|
||||
_blink.BlinkRTCPeerConnection.instance.updateIce_Callback_0_(unwrap_jso(this));
|
||||
|
@ -32606,7 +32598,7 @@ class ServiceWorkerClients extends NativeFieldWrapperClass2 {
|
|||
|
||||
Future getAll([Map options]) {
|
||||
if (options != null) {
|
||||
return wrap_jso(_blink.BlinkServiceWorkerClients.instance.getAll_Callback_1_(unwrap_jso(this), options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkServiceWorkerClients.instance.getAll_Callback_1_(unwrap_jso(this), convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkServiceWorkerClients.instance.getAll_Callback_0_(unwrap_jso(this)));
|
||||
}
|
||||
|
@ -32660,7 +32652,7 @@ class ServiceWorkerContainer extends NativeFieldWrapperClass2 {
|
|||
|
||||
Future register(String url, [Map options]) {
|
||||
if (options != null) {
|
||||
return wrap_jso(_blink.BlinkServiceWorkerContainer.instance.register_Callback_2_(unwrap_jso(this), url, options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkServiceWorkerContainer.instance.register_Callback_2_(unwrap_jso(this), url, convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkServiceWorkerContainer.instance.register_Callback_1_(unwrap_jso(this), url));
|
||||
}
|
||||
|
@ -32722,13 +32714,13 @@ class ServiceWorkerGlobalScope extends WorkerGlobalScope {
|
|||
return wrap_jso(_blink.BlinkServiceWorkerGlobalScope.instance.fetch_Callback_1_(unwrap_jso(this), unwrap_jso(request)));
|
||||
}
|
||||
if ((requestInitDict is Map || requestInitDict == null) && (request is String || request == null)) {
|
||||
return wrap_jso(_blink.BlinkServiceWorkerGlobalScope.instance.fetch_Callback_2_(unwrap_jso(this), unwrap_jso(request), requestInitDict != null ? new js.JsObject.jsify(requestInitDict) : requestInitDict));
|
||||
return wrap_jso(_blink.BlinkServiceWorkerGlobalScope.instance.fetch_Callback_2_(unwrap_jso(this), unwrap_jso(request), convertDartToNative_Dictionary(requestInitDict)));
|
||||
}
|
||||
if ((request is _Request || request == null) && requestInitDict == null) {
|
||||
return wrap_jso(_blink.BlinkServiceWorkerGlobalScope.instance.fetch_Callback_1_(unwrap_jso(this), unwrap_jso(request)));
|
||||
}
|
||||
if ((requestInitDict is Map || requestInitDict == null) && (request is _Request || request == null)) {
|
||||
return wrap_jso(_blink.BlinkServiceWorkerGlobalScope.instance.fetch_Callback_2_(unwrap_jso(this), unwrap_jso(request), requestInitDict != null ? new js.JsObject.jsify(requestInitDict) : requestInitDict));
|
||||
return wrap_jso(_blink.BlinkServiceWorkerGlobalScope.instance.fetch_Callback_2_(unwrap_jso(this), unwrap_jso(request), convertDartToNative_Dictionary(requestInitDict)));
|
||||
}
|
||||
throw new ArgumentError("Incorrect number or type of arguments");
|
||||
}
|
||||
|
@ -37076,10 +37068,10 @@ class Url extends NativeFieldWrapperClass2 implements UrlUtils {
|
|||
if ((blob_OR_source_OR_stream is Blob || blob_OR_source_OR_stream == null)) {
|
||||
return _blink.BlinkURL.instance.createObjectURL_Callback_1_(unwrap_jso(blob_OR_source_OR_stream));
|
||||
}
|
||||
if ((blob_OR_source_OR_stream is MediaStream)) {
|
||||
if ((blob_OR_source_OR_stream is MediaSource)) {
|
||||
return _blink.BlinkURL.instance.createObjectURL_Callback_1_(unwrap_jso(blob_OR_source_OR_stream));
|
||||
}
|
||||
if ((blob_OR_source_OR_stream is MediaSource)) {
|
||||
if ((blob_OR_source_OR_stream is MediaStream)) {
|
||||
return _blink.BlinkURL.instance.createObjectURL_Callback_1_(unwrap_jso(blob_OR_source_OR_stream));
|
||||
}
|
||||
throw new ArgumentError("Incorrect number or type of arguments");
|
||||
|
@ -39344,7 +39336,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
|
||||
@DomName('Window.postMessage')
|
||||
@DocsEditable()
|
||||
void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List<MessagePort> transfer]) => _blink.BlinkWindow.instance.postMessage_Callback_3_(unwrap_jso(this), message, targetOrigin, transfer);
|
||||
void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List<MessagePort> transfer]) => _blink.BlinkWindow.instance.postMessage_Callback_3_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(message), targetOrigin, transfer);
|
||||
|
||||
/**
|
||||
* Opens the print dialog for this window.
|
||||
|
@ -39392,7 +39384,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
return;
|
||||
}
|
||||
if ((scrollOptions is Map) && (y is num) && (x is num)) {
|
||||
_blink.BlinkWindow.instance.scroll_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), scrollOptions != null ? new js.JsObject.jsify(scrollOptions) : scrollOptions);
|
||||
_blink.BlinkWindow.instance.scroll_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), convertDartToNative_Dictionary(scrollOptions));
|
||||
return;
|
||||
}
|
||||
if ((y is int) && (x is int) && scrollOptions == null) {
|
||||
|
@ -39400,7 +39392,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
return;
|
||||
}
|
||||
if ((scrollOptions is Map) && (y is int) && (x is int)) {
|
||||
_blink.BlinkWindow.instance.scroll_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), scrollOptions != null ? new js.JsObject.jsify(scrollOptions) : scrollOptions);
|
||||
_blink.BlinkWindow.instance.scroll_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), convertDartToNative_Dictionary(scrollOptions));
|
||||
return;
|
||||
}
|
||||
throw new ArgumentError("Incorrect number or type of arguments");
|
||||
|
@ -39412,7 +39404,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
return;
|
||||
}
|
||||
if ((scrollOptions is Map) && (y is num) && (x is num)) {
|
||||
_blink.BlinkWindow.instance.scrollBy_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), scrollOptions != null ? new js.JsObject.jsify(scrollOptions) : scrollOptions);
|
||||
_blink.BlinkWindow.instance.scrollBy_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), convertDartToNative_Dictionary(scrollOptions));
|
||||
return;
|
||||
}
|
||||
if ((y is int) && (x is int) && scrollOptions == null) {
|
||||
|
@ -39420,7 +39412,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
return;
|
||||
}
|
||||
if ((scrollOptions is Map) && (y is int) && (x is int)) {
|
||||
_blink.BlinkWindow.instance.scrollBy_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), scrollOptions != null ? new js.JsObject.jsify(scrollOptions) : scrollOptions);
|
||||
_blink.BlinkWindow.instance.scrollBy_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), convertDartToNative_Dictionary(scrollOptions));
|
||||
return;
|
||||
}
|
||||
throw new ArgumentError("Incorrect number or type of arguments");
|
||||
|
@ -39432,7 +39424,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
return;
|
||||
}
|
||||
if ((scrollOptions is Map) && (y is num) && (x is num)) {
|
||||
_blink.BlinkWindow.instance.scrollTo_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), scrollOptions != null ? new js.JsObject.jsify(scrollOptions) : scrollOptions);
|
||||
_blink.BlinkWindow.instance.scrollTo_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), convertDartToNative_Dictionary(scrollOptions));
|
||||
return;
|
||||
}
|
||||
if ((y is int) && (x is int) && scrollOptions == null) {
|
||||
|
@ -39440,7 +39432,7 @@ class Window extends EventTarget implements WindowEventHandlers, WindowBase, Glo
|
|||
return;
|
||||
}
|
||||
if ((scrollOptions is Map) && (y is int) && (x is int)) {
|
||||
_blink.BlinkWindow.instance.scrollTo_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), scrollOptions != null ? new js.JsObject.jsify(scrollOptions) : scrollOptions);
|
||||
_blink.BlinkWindow.instance.scrollTo_Callback_3_(unwrap_jso(this), unwrap_jso(x), unwrap_jso(y), convertDartToNative_Dictionary(scrollOptions));
|
||||
return;
|
||||
}
|
||||
throw new ArgumentError("Incorrect number or type of arguments");
|
||||
|
|
|
@ -28,55 +28,9 @@
|
|||
|
||||
part of html_common;
|
||||
|
||||
|
||||
/// Converts a JavaScript object with properties into a Dart Map.
|
||||
/// Not suitable for nested objects.
|
||||
Map convertNativeToDart_Dictionary(object) {
|
||||
if (object == null) return null;
|
||||
var dict = {};
|
||||
var keys = JS('JSExtendableArray', 'Object.getOwnPropertyNames(#)', object);
|
||||
for (final key in keys) {
|
||||
dict[key] = JS('var', '#[#]', object, key);
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
/// Converts a flat Dart map into a JavaScript object with properties.
|
||||
convertDartToNative_Dictionary(Map dict) {
|
||||
if (dict == null) return null;
|
||||
var object = JS('var', '{}');
|
||||
dict.forEach((String key, value) {
|
||||
JS('void', '#[#] = #', object, key, value);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensures that the input is a JavaScript Array.
|
||||
*
|
||||
* Creates a new JavaScript array if necessary, otherwise returns the original.
|
||||
*/
|
||||
List convertDartToNative_StringArray(List<String> input) {
|
||||
// TODO(sra). Implement this.
|
||||
return input;
|
||||
}
|
||||
|
||||
DateTime convertNativeToDart_DateTime(date) {
|
||||
var millisSinceEpoch = JS('int', '#.getTime()', date);
|
||||
return new DateTime.fromMillisecondsSinceEpoch(millisSinceEpoch, isUtc: true);
|
||||
}
|
||||
|
||||
convertDartToNative_DateTime(DateTime date) {
|
||||
return JS('', 'new Date(#)', date.millisecondsSinceEpoch);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// Converts a Dart value into a JavaScript SerializedScriptValue.
|
||||
convertDartToNative_SerializedScriptValue(value) {
|
||||
return _convertDartToNative_PrepareForStructuredClone(value);
|
||||
return convertDartToNative_PrepareForStructuredClone(value);
|
||||
}
|
||||
|
||||
/// Since the source object may be viewed via a JavaScript event listener the
|
||||
|
@ -102,7 +56,7 @@ convertNativeToDart_SerializedScriptValue(object) {
|
|||
* operations that perform the structured clone algorithm which does not mutate
|
||||
* its output, the result may share structure with the input [value].
|
||||
*/
|
||||
_convertDartToNative_PrepareForStructuredClone(value) {
|
||||
abstract class _StructuredClone {
|
||||
|
||||
// TODO(sra): Replace slots with identity hash table.
|
||||
var values = [];
|
||||
|
@ -120,6 +74,10 @@ _convertDartToNative_PrepareForStructuredClone(value) {
|
|||
readSlot(int i) => copies[i];
|
||||
writeSlot(int i, x) { copies[i] = x; }
|
||||
cleanupSlots() {} // Will be needed if we mark objects with a property.
|
||||
bool cloneNotRequired(object);
|
||||
newJsMap();
|
||||
newJsList(length);
|
||||
void putIntoMap(map, key, value);
|
||||
|
||||
// Returns the input, or a clone of the input.
|
||||
walk(e) {
|
||||
|
@ -148,57 +106,52 @@ _convertDartToNative_PrepareForStructuredClone(value) {
|
|||
|
||||
// TODO(sra): Firefox: How to convert _TypedImageData on the other end?
|
||||
if (e is ImageData) return e;
|
||||
if (e is NativeByteBuffer) return e;
|
||||
|
||||
if (e is NativeTypedData) return e;
|
||||
if (cloneNotRequired(e)) return e;
|
||||
|
||||
if (e is Map) {
|
||||
var slot = findSlot(e);
|
||||
var copy = readSlot(slot);
|
||||
if (copy != null) return copy;
|
||||
copy = JS('var', '{}');
|
||||
copy = newJsMap();
|
||||
writeSlot(slot, copy);
|
||||
e.forEach((key, value) {
|
||||
JS('void', '#[#] = #', copy, key, walk(value));
|
||||
});
|
||||
putIntoMap(copy, key, walk(value));
|
||||
});
|
||||
return copy;
|
||||
}
|
||||
|
||||
if (e is List) {
|
||||
// Since a JavaScript Array is an instance of Dart List it is possible to
|
||||
// avoid making a copy of the list if there is no need to copy anything
|
||||
// reachable from the array. We defer creating a new array until a cycle
|
||||
// is detected or a subgraph was copied.
|
||||
int length = e.length;
|
||||
// Since a JavaScript Array is an instance of Dart List it is tempting
|
||||
// in dart2js to avoid making a copy of the list if there is no need
|
||||
// to copy anything reachable from the array. However, the list may have
|
||||
// non-native properties or methods from interceptors and such, e.g.
|
||||
// an immutability marker. So we had to stop doing that.
|
||||
var slot = findSlot(e);
|
||||
var copy = readSlot(slot);
|
||||
if (copy != null) {
|
||||
if (true == copy) { // Cycle, so commit to making a copy.
|
||||
copy = JS('JSExtendableArray', 'new Array(#)', length);
|
||||
writeSlot(slot, copy);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
// Always clone the list, as it may have non-native properties or methods
|
||||
// from interceptors and such.
|
||||
copy = JS('JSExtendableArray', 'new Array(#)', length);
|
||||
writeSlot(slot, copy);
|
||||
|
||||
for ( ; i < length; i++) {
|
||||
copy[i] = walk(e[i]);
|
||||
}
|
||||
if (copy != null) return copy;
|
||||
copy = copyList(e, slot);
|
||||
return copy;
|
||||
}
|
||||
|
||||
throw new UnimplementedError('structured clone of other type');
|
||||
}
|
||||
|
||||
var copy = walk(value);
|
||||
cleanupSlots();
|
||||
return copy;
|
||||
copyList(List e, int slot) {
|
||||
int i = 0;
|
||||
int length = e.length;
|
||||
var copy = newJsList(length);
|
||||
writeSlot(slot, copy);
|
||||
for ( ; i < length; i++) {
|
||||
copy[i] = walk(e[i]);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
convertDartToNative_PrepareForStructuredClone(value) {
|
||||
var copy = walk(value);
|
||||
cleanupSlots();
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,25 +172,36 @@ _convertDartToNative_PrepareForStructuredClone(value) {
|
|||
* MessageEvents. Mutating the object to make it more 'Dart-like' would corrupt
|
||||
* the value as seen from the JavaScript listeners.
|
||||
*/
|
||||
convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) {
|
||||
abstract class _AcceptStructuredClone {
|
||||
|
||||
// TODO(sra): Replace slots with identity hash table that works on non-dart
|
||||
// objects.
|
||||
// TODO(sra): Replace slots with identity hash table.
|
||||
var values = [];
|
||||
var copies = [];
|
||||
var copies = []; // initially 'null', 'true' during initial DFS, then a copy.
|
||||
bool mustCopy = false;
|
||||
|
||||
int findSlot(value) {
|
||||
int length = values.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (identical(values[i], value)) return i;
|
||||
if (identicalInJs(values[i], value)) return i;
|
||||
}
|
||||
values.add(value);
|
||||
copies.add(null);
|
||||
return length;
|
||||
}
|
||||
|
||||
/// Are the two objects identical, but taking into account that two JsObject
|
||||
/// wrappers may not be identical, but their underlying Js Object might be.
|
||||
bool identicalInJs(a, b);
|
||||
readSlot(int i) => copies[i];
|
||||
writeSlot(int i, x) { copies[i] = x; }
|
||||
|
||||
/// Iterate over the JS properties.
|
||||
forEachJsField(object, action);
|
||||
|
||||
/// Create a new Dart list of the given length. May create a native List or
|
||||
/// a JsArray, depending if we're in Dartium or dart2js.
|
||||
newDartList(length);
|
||||
|
||||
walk(e) {
|
||||
if (e == null) return e;
|
||||
if (e is bool) return e;
|
||||
|
@ -253,6 +217,10 @@ convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) {
|
|||
throw new UnimplementedError('structured clone of RegExp');
|
||||
}
|
||||
|
||||
if (isJavaScriptPromise(e)) {
|
||||
return convertNativePromiseToDartFuture(e);
|
||||
}
|
||||
|
||||
if (isJavaScriptSimpleObject(e)) {
|
||||
// TODO(sra): If mustCopy is false, swizzle the prototype for one of a Map
|
||||
// implementation that uses the properies as storage.
|
||||
|
@ -262,9 +230,7 @@ convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) {
|
|||
copy = {};
|
||||
|
||||
writeSlot(slot, copy);
|
||||
for (final key in JS('JSExtendableArray', 'Object.keys(#)', e)) {
|
||||
copy[key] = walk(JS('var', '#[#]', e, key));
|
||||
}
|
||||
forEachJsField(e, (key, value) => copy[key] = walk(value));
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
@ -276,7 +242,7 @@ convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) {
|
|||
int length = e.length;
|
||||
// Since a JavaScript Array is an instance of Dart List, we can modify it
|
||||
// in-place unless we must copy.
|
||||
copy = mustCopy ? JS('JSExtendableArray', 'new Array(#)', length) : e;
|
||||
copy = mustCopy ? newDartList(length) : e;
|
||||
writeSlot(slot, copy);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -290,8 +256,11 @@ convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) {
|
|||
return e;
|
||||
}
|
||||
|
||||
var copy = walk(object);
|
||||
return copy;
|
||||
convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) {
|
||||
this.mustCopy = mustCopy;
|
||||
var copy = walk(object);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
// Conversions for ContextAttributes.
|
||||
|
@ -388,20 +357,6 @@ convertDartToNative_ImageData(ImageData imageData) {
|
|||
return imageData;
|
||||
}
|
||||
|
||||
|
||||
bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value);
|
||||
bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value);
|
||||
bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value);
|
||||
bool isJavaScriptSimpleObject(value) {
|
||||
var proto = JS('', 'Object.getPrototypeOf(#)', value);
|
||||
return JS('bool', '# === Object.prototype', proto) ||
|
||||
JS('bool', '# === null', proto);
|
||||
}
|
||||
bool isImmutableJavaScriptArray(value) =>
|
||||
JS('bool', r'!!(#.immutable$list)', value);
|
||||
|
||||
|
||||
|
||||
const String _serializedScriptValue =
|
||||
'num|String|bool|'
|
||||
'JSExtendableArray|=Object|'
|
||||
|
|
92
sdk/lib/html/html_common/conversions_dart2js.dart
Normal file
92
sdk/lib/html/html_common/conversions_dart2js.dart
Normal file
|
@ -0,0 +1,92 @@
|
|||
part of html_common;
|
||||
|
||||
/// Converts a JavaScript object with properties into a Dart Map.
|
||||
/// Not suitable for nested objects.
|
||||
Map convertNativeToDart_Dictionary(object) {
|
||||
if (object == null) return null;
|
||||
var dict = {};
|
||||
var keys = JS('JSExtendableArray', 'Object.getOwnPropertyNames(#)', object);
|
||||
for (final key in keys) {
|
||||
dict[key] = JS('var', '#[#]', object, key);
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
/// Converts a flat Dart map into a JavaScript object with properties.
|
||||
convertDartToNative_Dictionary(Map dict, [void postCreate(dynamic)]) {
|
||||
if (dict == null) return null;
|
||||
var object = JS('var', '{}');
|
||||
if (postCreate != null) {
|
||||
postCreate(object);
|
||||
}
|
||||
dict.forEach((String key, value) {
|
||||
JS('void', '#[#] = #', object, key, value);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensures that the input is a JavaScript Array.
|
||||
*
|
||||
* Creates a new JavaScript array if necessary, otherwise returns the original.
|
||||
*/
|
||||
List convertDartToNative_StringArray(List<String> input) {
|
||||
// TODO(sra). Implement this.
|
||||
return input;
|
||||
}
|
||||
|
||||
DateTime convertNativeToDart_DateTime(date) {
|
||||
var millisSinceEpoch = JS('int', '#.getTime()', date);
|
||||
return new DateTime.fromMillisecondsSinceEpoch(millisSinceEpoch, isUtc: true);
|
||||
}
|
||||
|
||||
convertDartToNative_DateTime(DateTime date) {
|
||||
return JS('', 'new Date(#)', date.millisecondsSinceEpoch);
|
||||
}
|
||||
|
||||
convertDartToNative_PrepareForStructuredClone(value) =>
|
||||
new _StructuredCloneDart2Js().convertDartToNative_PrepareForStructuredClone(value);
|
||||
|
||||
convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) =>
|
||||
new _AcceptStructuredCloneDart2Js().convertNativeToDart_AcceptStructuredClone(object, mustCopy: mustCopy);
|
||||
|
||||
class _StructuredCloneDart2Js extends _StructuredClone {
|
||||
newJsMap() => JS('var', '{}');
|
||||
putIntoMap(map, key, value) => JS('void', '#[#] = #', map, key, value);
|
||||
newJsList(length) => JS('JSExtendableArray', 'new Array(#)', length);
|
||||
cloneNotRequired(e) => (e is NativeByteBuffer || e is NativeTypedData);
|
||||
}
|
||||
|
||||
class _AcceptStructuredCloneDart2Js extends _AcceptStructuredClone {
|
||||
|
||||
newJsList(length) => JS('JSExtendableArray', 'new Array(#)', length);
|
||||
newDartList(length) => newJsList(length);
|
||||
identicalInJs(a, b) => identical(a, b);
|
||||
|
||||
void forEachJsField(object, action) {
|
||||
for (final key in JS('JSExtendableArray', 'Object.keys(#)', object)) {
|
||||
action(key, JS('var', '#[#]', object, key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isJavaScriptDate(value) => JS('bool', '# instanceof Date', value);
|
||||
bool isJavaScriptRegExp(value) => JS('bool', '# instanceof RegExp', value);
|
||||
bool isJavaScriptArray(value) => JS('bool', '# instanceof Array', value);
|
||||
bool isJavaScriptSimpleObject(value) {
|
||||
var proto = JS('', 'Object.getPrototypeOf(#)', value);
|
||||
return JS('bool', '# === Object.prototype', proto) ||
|
||||
JS('bool', '# === null', proto);
|
||||
}
|
||||
bool isImmutableJavaScriptArray(value) =>
|
||||
JS('bool', r'!!(#.immutable$list)', value);
|
||||
bool isJavaScriptPromise(value) => JS('bool', r'# instanceof Promise', value);
|
||||
|
||||
Future convertNativePromiseToDartFuture(promise) {
|
||||
var completer = new Completer();
|
||||
var then = convertDartClosureToJS((result) => completer.complete(result), 1);
|
||||
var error = convertDartClosureToJS((result) => completer.completeError(result), 1);
|
||||
var newPromise = JS('', '#.then(#).catch(#)', promise, then, error);
|
||||
return completer.future;
|
||||
}
|
63
sdk/lib/html/html_common/conversions_dartium.dart
Normal file
63
sdk/lib/html/html_common/conversions_dartium.dart
Normal file
|
@ -0,0 +1,63 @@
|
|||
part of html_common;
|
||||
|
||||
convertDartToNative_PrepareForStructuredClone(value) =>
|
||||
new _StructuredCloneDartium().convertDartToNative_PrepareForStructuredClone(value);
|
||||
|
||||
convertNativeToDart_AcceptStructuredClone(object, {mustCopy: false}) =>
|
||||
new _AcceptStructuredCloneDartium().convertNativeToDart_AcceptStructuredClone(object, mustCopy: mustCopy);
|
||||
|
||||
class _StructuredCloneDartium extends _StructuredClone {
|
||||
newJsMap() => new js.JsObject(js.context["Object"]);
|
||||
putIntoMap(map, key, value) => map[key] = value;
|
||||
newJSList(length) => new js.JsArray();
|
||||
cloneNotRequired(e) => e is js.JsObject;
|
||||
}
|
||||
|
||||
class _AcceptStructuredCloneDartium extends _AcceptStructuredClone {
|
||||
newDartList(length) => new List(length);
|
||||
|
||||
// JsObjects won't be identical, but will be equal only if the underlying
|
||||
// Js entities are identical.
|
||||
bool identicalInJs(a, b) =>
|
||||
(a is js.JsObject) ? a == b : identical(a, b);
|
||||
|
||||
void forEachJsField(jsObject, action) {
|
||||
var keys = js.context["Object"].callMethod("keys", [jsObject]);
|
||||
for (var key in keys) {
|
||||
action(key, jsObject[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final _dateConstructor = js.context["Date"];
|
||||
final _regexConstructor = js.context["RegExp"];
|
||||
|
||||
bool isJavaScriptDate(value) => value is js.JsObject && value.instanceof(_dateConstructor);
|
||||
bool isJavaScriptRegExp(value) => value is js.JsObject && value.instanceof(_regexConstructor);
|
||||
bool isJavaScriptArray(value) => value is js.JsArray;
|
||||
|
||||
final _object = js.context["Object"];
|
||||
final _getPrototypeOf = _object["getPrototypeOf"];
|
||||
_getProto(object) {
|
||||
return _getPrototypeOf.apply([object]);
|
||||
}
|
||||
final _objectProto = js.context["Object"]["prototype"];
|
||||
|
||||
bool isJavaScriptSimpleObject(value) {
|
||||
if (!value is js.JsObject) return false;
|
||||
var proto = _getProto(value);
|
||||
return proto == _objectProto || proto == null;
|
||||
}
|
||||
bool isImmutableJavaScriptArray(value) =>
|
||||
isJavaScriptArray(value) && value["immutable$list"] != null;
|
||||
|
||||
final _promiseConstructor = js.context['Promise'];
|
||||
bool isJavaScriptPromise(value) => value is js.JsObject && value['constructor'] == _promiseConstructor;
|
||||
|
||||
Future convertNativePromiseToDartFuture(js.JsObject promise) {
|
||||
var completer = new Completer();
|
||||
var newPromise = promise
|
||||
.callMethod("then", [(result) => completer.complete(result)])
|
||||
.callMethod("catch", [(result) => completer.completeError(result)]);
|
||||
return completer.future;
|
||||
}
|
|
@ -4,9 +4,12 @@
|
|||
|
||||
library html_common;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:html';
|
||||
import 'dart:js' as js;
|
||||
import 'dart:_internal' show WhereIterable;
|
||||
import 'dart:web_gl' as gl;
|
||||
|
||||
import 'metadata.dart';
|
||||
export 'metadata.dart';
|
||||
|
@ -15,3 +18,5 @@ part 'css_class_set.dart';
|
|||
part 'device.dart';
|
||||
part 'filtered_element_list.dart';
|
||||
part 'lists.dart';
|
||||
part 'conversions.dart';
|
||||
part 'conversions_dartium.dart';
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'dart:html';
|
|||
import 'dart:_internal' show WhereIterable;
|
||||
import 'dart:web_gl' as gl;
|
||||
import 'dart:_native_typed_data';
|
||||
import 'dart:_js_helper' show Creates, Returns;
|
||||
import 'dart:_js_helper' show Creates, Returns, convertDartClosureToJS;
|
||||
import 'dart:_foreign_helper' show JS;
|
||||
import 'dart:_interceptors' show Interceptor, JSExtendableArray;
|
||||
|
||||
|
@ -18,6 +18,7 @@ export 'dart:_metadata';
|
|||
|
||||
part 'css_class_set.dart';
|
||||
part 'conversions.dart';
|
||||
part 'conversions_dart2js.dart';
|
||||
part 'device.dart';
|
||||
part 'filtered_element_list.dart';
|
||||
part 'lists.dart';
|
||||
|
|
|
@ -222,7 +222,7 @@ class Cursor extends NativeFieldWrapperClass2 {
|
|||
|
||||
@DomName('IDBCursor.update')
|
||||
@DocsEditable()
|
||||
Request _update(Object value) => wrap_jso(_blink.BlinkIDBCursor.instance.update_Callback_1_(unwrap_jso(this), value));
|
||||
Request _update(Object value) => wrap_jso(_blink.BlinkIDBCursor.instance.update_Callback_1_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(value)));
|
||||
|
||||
}
|
||||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
|
@ -364,7 +364,7 @@ class Database extends EventTarget {
|
|||
|
||||
ObjectStore _createObjectStore(String name, [Map options]) {
|
||||
if (options != null) {
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.createObjectStore_Callback_2_(unwrap_jso(this), name, options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.createObjectStore_Callback_2_(unwrap_jso(this), name, convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.createObjectStore_Callback_1_(unwrap_jso(this), name));
|
||||
}
|
||||
|
@ -397,9 +397,9 @@ class Database extends EventTarget {
|
|||
|
||||
Transaction transactionList(List<String> storeNames, [String mode]) {
|
||||
if (mode != null) {
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.transaction_Callback_2_(unwrap_jso(this), storeNames, mode));
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.transaction_Callback_2_(unwrap_jso(this), convertDartToNative_StringArray(storeNames), mode));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.transaction_Callback_1_(unwrap_jso(this), storeNames));
|
||||
return wrap_jso(_blink.BlinkIDBDatabase.instance.transaction_Callback_1_(unwrap_jso(this), convertDartToNative_StringArray(storeNames)));
|
||||
}
|
||||
|
||||
Transaction transactionStore(String storeName, [String mode]) {
|
||||
|
@ -1008,9 +1008,9 @@ class ObjectStore extends NativeFieldWrapperClass2 {
|
|||
|
||||
Request _add(Object value, [Object key]) {
|
||||
if (key != null) {
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.add_Callback_2_(unwrap_jso(this), value, key));
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.add_Callback_2_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(value), convertDartToNative_SerializedScriptValue(key)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.add_Callback_1_(unwrap_jso(this), value));
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.add_Callback_1_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(value)));
|
||||
}
|
||||
|
||||
@DomName('IDBObjectStore.clear')
|
||||
|
@ -1026,13 +1026,13 @@ class ObjectStore extends NativeFieldWrapperClass2 {
|
|||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.createIndex_Callback_2_(unwrap_jso(this), name, unwrap_jso(keyPath)));
|
||||
}
|
||||
if ((options is Map || options == null) && (keyPath is String || keyPath == null) && (name is String || name == null)) {
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.createIndex_Callback_3_(unwrap_jso(this), name, unwrap_jso(keyPath), options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.createIndex_Callback_3_(unwrap_jso(this), name, unwrap_jso(keyPath), convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
if ((keyPath is List<String> || keyPath == null) && (name is String || name == null) && options == null) {
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.createIndex_Callback_2_(unwrap_jso(this), name, unwrap_jso(keyPath)));
|
||||
}
|
||||
if ((options is Map || options == null) && (keyPath is List<String> || keyPath == null) && (name is String || name == null)) {
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.createIndex_Callback_3_(unwrap_jso(this), name, unwrap_jso(keyPath), options != null ? new js.JsObject.jsify(options) : options));
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.createIndex_Callback_3_(unwrap_jso(this), name, unwrap_jso(keyPath), convertDartToNative_Dictionary(options)));
|
||||
}
|
||||
throw new ArgumentError("Incorrect number or type of arguments");
|
||||
}
|
||||
|
@ -1069,9 +1069,9 @@ class ObjectStore extends NativeFieldWrapperClass2 {
|
|||
|
||||
Request _put(Object value, [Object key]) {
|
||||
if (key != null) {
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.put_Callback_2_(unwrap_jso(this), value, key));
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.put_Callback_2_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(value), convertDartToNative_SerializedScriptValue(key)));
|
||||
}
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.put_Callback_1_(unwrap_jso(this), value));
|
||||
return wrap_jso(_blink.BlinkIDBObjectStore.instance.put_Callback_1_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(value)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -521,7 +521,7 @@ class OperationInfo(object):
|
|||
else:
|
||||
return False
|
||||
|
||||
def ParametersAsListOfVariables(self, parameter_count=None, type_registry=None, dart_js_interop=False):
|
||||
def ParametersAsListOfVariables(self, parameter_count=None, type_registry=None, dart_js_interop=False, backend = None):
|
||||
"""Returns a list of the first parameter_count parameter names
|
||||
as raw variables.
|
||||
"""
|
||||
|
@ -588,10 +588,11 @@ class OperationInfo(object):
|
|||
parameters.append('unwrap_jso(%s)' % p.name)
|
||||
else:
|
||||
if dart_js_interop:
|
||||
conversion = backend._InputConversion(p.type_id, self.declared_name)
|
||||
passParam = p.name
|
||||
if type_id == 'Dictionary':
|
||||
if conversion:
|
||||
# Need to pass the IDL Dictionary from Dart Map to JavaScript object.
|
||||
passParam = '{0} != null ? new js.JsObject.jsify({0}) : {0}'.format(p.name)
|
||||
passParam = '{0}({1})'.format(conversion.function_name, p.name)
|
||||
else:
|
||||
passParam = p.name
|
||||
parameters.append(passParam)
|
||||
|
|
|
@ -1195,7 +1195,8 @@ class DartiumBackend(HtmlDartGenerator):
|
|||
|
||||
parameters = info.ParametersAsListOfVariables(None,
|
||||
self._type_registry if self._dart_use_blink else None,
|
||||
dart_js_interop)
|
||||
dart_js_interop,
|
||||
self)
|
||||
dart_declaration = '%s%s %s(%s)' % (
|
||||
'static ' if info.IsStatic() else '',
|
||||
return_type,
|
||||
|
@ -1258,7 +1259,8 @@ class DartiumBackend(HtmlDartGenerator):
|
|||
native_suffix = 'Callback'
|
||||
actuals = info.ParametersAsListOfVariables(argument_count,
|
||||
self._type_registry if self._dart_use_blink else None,
|
||||
self._dart_js_interop)
|
||||
self._dart_js_interop,
|
||||
self)
|
||||
actuals_s = ", ".join(actuals)
|
||||
formals=actuals
|
||||
return_type = self.SecureOutputType(operation.type.id)
|
||||
|
|
|
@ -394,20 +394,18 @@ wrap_jso(jsObject) {
|
|||
// JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
|
||||
return jsObject;
|
||||
}
|
||||
// Try the most general type conversions on it.
|
||||
// TODO(alanknight): We may be able to do better. This maintains identity,
|
||||
// which is useful, but expensive. And if we nest something that only
|
||||
// this conversion handles, how does that work? e.g. a list of maps of elements.
|
||||
var converted = convertNativeToDart_SerializedScriptValue(jsObject);
|
||||
if (!identical(converted, jsObject)) {
|
||||
return converted;
|
||||
}
|
||||
var constructor = jsObject['constructor'];
|
||||
if (__interop_checks) {
|
||||
if (jsObject is js.JsArray) {
|
||||
return jsObject;
|
||||
}
|
||||
|
||||
debug_or_assert("constructor != null", constructor != null);
|
||||
}
|
||||
if (constructor == js.context['Object']) {
|
||||
return convertNativeObjectToDartMap(jsObject);
|
||||
}
|
||||
if (constructor == js.context['Promise']) {
|
||||
return convertNativePromiseToDartFuture(jsObject);
|
||||
}
|
||||
var jsTypeName = constructor['name'];
|
||||
if (__interop_checks) {
|
||||
debug_or_assert("constructor != null && jsTypeName.length > 0", constructor != null && jsTypeName.length > 0);
|
||||
|
@ -438,7 +436,7 @@ wrap_jso(jsObject) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create Dart class that maps to the JS Type that is the JS type being
|
||||
* Create Dart class that maps to the JS Type that is the JS type being
|
||||
* extended using JS interop createCallback (we need the base type of the
|
||||
* custom element) not the Dart created constructor.
|
||||
*/
|
||||
|
@ -515,6 +513,8 @@ Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) {
|
|||
|
||||
// Converts a flat Dart map into a JavaScript object with properties this is
|
||||
// is the Dartium only version it uses dart:js.
|
||||
// TODO(alanknight): This could probably be unified with the dart2js conversions
|
||||
// code in html_common and be more general.
|
||||
convertDartToNative_Dictionary(Map dict) {
|
||||
if (dict == null) return null;
|
||||
var jsObject = new js.JsObject(js.context['Object']);
|
||||
|
@ -538,21 +538,13 @@ convertDartToNative_List(List input) => new js.JsArray()..addAll(input);
|
|||
// Conversion function place holder (currently not used in dart2js or dartium).
|
||||
List convertDartToNative_StringArray(List<String> input) => input;
|
||||
|
||||
Future convertNativePromiseToDartFuture(js.JsObject promise) {
|
||||
var completer = new Completer();
|
||||
var newPromise = promise
|
||||
.callMethod("then", [(result) => completer.complete(result)])
|
||||
.callMethod("catch", [(result) => completer.completeError(result)]);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
$else
|
||||
class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {}
|
||||
|
||||
unwrap_jso(dartClass_instance) => dartClass_instance;
|
||||
wrap_jso(jsObject) => jsObject;
|
||||
make_dart_rectangle(r) => r;
|
||||
convertDartToNative_Dictionary(Map dict) => dict;
|
||||
convertDartToNative_Dictionary(Map dict) => dict;
|
||||
List convertDartToNative_StringArray(List<String> input) => input;
|
||||
convertDartToNative_List(List input) => input;
|
||||
|
||||
|
|
Loading…
Reference in a new issue