Skip to content

Commit 110b579

Browse files
committed
wrap_jso should wrap JsArray as well, not always call wrap on its contents
BUG= Committed: f0e52e4 Review URL: https://codereview.chromium.org/1383903002 .
1 parent 66a122a commit 110b579

File tree

8 files changed

+83
-17
lines changed

8 files changed

+83
-17
lines changed

sdk/lib/html/dartium/html_dartium.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,12 @@ wrap_jso(jsObject) {
11591159
return wrapper;
11601160
}
11611161

1162+
if (jsObject is js.JsArray) {
1163+
var wrappingList = new _DartHtmlWrappingList(jsObject);
1164+
js.setDartHtmlWrapperFor(jsObject, wrappingList);
1165+
return wrappingList;
1166+
}
1167+
11621168
// Try the most general type conversions on it.
11631169
// TODO(alanknight): We may be able to do better. This maintains identity,
11641170
// which is useful, but expensive. And if we nest something that only
@@ -1304,6 +1310,22 @@ convertDartToNative_List(List input) => new js.JsArray()..addAll(input);
13041310
// Conversion function place holder (currently not used in dart2js or dartium).
13051311
List convertDartToNative_StringArray(List<String> input) => input;
13061312

1313+
/**
1314+
* Wraps a JsArray and will call wrap_jso on its entries.
1315+
*/
1316+
class _DartHtmlWrappingList extends ListBase {
1317+
_DartHtmlWrappingList(this._basicList);
1318+
1319+
final js.JsArray _basicList;
1320+
1321+
operator [](int index) => wrap_jso(_basicList[index]);
1322+
1323+
operator []=(int index, value) => _basicList[index] = unwrap_jso(value);
1324+
1325+
int get length => _basicList.length;
1326+
int set length(int newLength) => _basicList.length = newLength;
1327+
}
1328+
13071329
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
13081330
// for details. All rights reserved. Use of this source code is governed by a
13091331
// BSD-style license that can be found in the LICENSE file.
@@ -10138,10 +10160,10 @@ class DirectoryReader extends NativeFieldWrapperClass2 {
1013810160

1013910161
void _readEntries(_EntriesCallback successCallback, [_ErrorCallback errorCallback]) {
1014010162
if (errorCallback != null) {
10141-
_blink.BlinkDirectoryReader.instance.readEntries_Callback_2_(unwrap_jso(this), unwrap_jso((entries) => successCallback(entries)), unwrap_jso((error) => errorCallback(wrap_jso(error))));
10163+
_blink.BlinkDirectoryReader.instance.readEntries_Callback_2_(unwrap_jso(this), unwrap_jso((entries) => successCallback(wrap_jso(entries))), unwrap_jso((error) => errorCallback(wrap_jso(error))));
1014210164
return;
1014310165
}
10144-
_blink.BlinkDirectoryReader.instance.readEntries_Callback_1_(unwrap_jso(this), unwrap_jso((entries) => successCallback(entries)));
10166+
_blink.BlinkDirectoryReader.instance.readEntries_Callback_1_(unwrap_jso(this), unwrap_jso((entries) => successCallback(wrap_jso(entries))));
1014510167
return;
1014610168
}
1014710169

@@ -18438,7 +18460,7 @@ class FontFaceSetLoadEvent extends Event {
1843818460
@DomName('FontFaceSetLoadEvent.fontfaces')
1843918461
@DocsEditable()
1844018462
@Experimental() // untriaged
18441-
List<FontFace> get fontfaces => _blink.BlinkFontFaceSetLoadEvent.instance.fontfaces_Getter_(unwrap_jso(this));
18463+
List<FontFace> get fontfaces => wrap_jso(_blink.BlinkFontFaceSetLoadEvent.instance.fontfaces_Getter_(unwrap_jso(this)));
1844218464

1844318465
}
1844418466
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
@@ -18668,7 +18690,7 @@ class Gamepad extends NativeFieldWrapperClass2 {
1866818690

1866918691
@DomName('Gamepad.axes')
1867018692
@DocsEditable()
18671-
List<num> get axes => _blink.BlinkGamepad.instance.axes_Getter_(unwrap_jso(this));
18693+
List<num> get axes => wrap_jso(_blink.BlinkGamepad.instance.axes_Getter_(unwrap_jso(this)));
1867218694

1867318695
@DomName('Gamepad.connected')
1867418696
@DocsEditable()
@@ -22881,7 +22903,7 @@ class InputElement extends HtmlElement implements
2288122903
@SupportedBrowser(SupportedBrowser.SAFARI)
2288222904
@Experimental()
2288322905
// http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#concept-input-type-file-selected
22884-
List<Entry> get entries => _blink.BlinkHTMLInputElement.instance.webkitEntries_Getter_(unwrap_jso(this));
22906+
List<Entry> get entries => wrap_jso(_blink.BlinkHTMLInputElement.instance.webkitEntries_Getter_(unwrap_jso(this)));
2288522907

2288622908
@DomName('HTMLInputElement.webkitdirectory')
2288722909
@DocsEditable()
@@ -26134,7 +26156,7 @@ class MessageEvent extends Event {
2613426156

2613526157
@DomName('MessageEvent.initMessageEvent')
2613626158
@DocsEditable()
26137-
void _initMessageEvent(String typeArg, bool canBubbleArg, bool cancelableArg, Object dataArg, String originArg, String lastEventIdArg, Window sourceArg, List<MessagePort> messagePorts) => _blink.BlinkMessageEvent.instance.initMessageEvent_Callback_8_(unwrap_jso(this), typeArg, canBubbleArg, cancelableArg, dataArg, originArg, lastEventIdArg, unwrap_jso(sourceArg), messagePorts);
26159+
void _initMessageEvent(String typeArg, bool canBubbleArg, bool cancelableArg, Object dataArg, String originArg, String lastEventIdArg, Window sourceArg, List<MessagePort> messagePorts) => _blink.BlinkMessageEvent.instance.initMessageEvent_Callback_8_(unwrap_jso(this), typeArg, canBubbleArg, cancelableArg, dataArg, originArg, lastEventIdArg, unwrap_jso(sourceArg), unwrap_jso(messagePorts));
2613826160

2613926161
}
2614026162
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
@@ -27240,7 +27262,7 @@ class MutationObserver extends NativeFieldWrapperClass2 {
2724027262
}
2724127263
@DocsEditable()
2724227264
static MutationObserver _create(callback) => wrap_jso(_blink.BlinkMutationObserver.instance.constructorCallback_1_((mutations, observer) {
27243-
callback(mutations, wrap_jso(observer));
27265+
callback(wrap_jso(mutations), wrap_jso(observer));
2724427266
}));
2724527267

2724627268
/**

sdk/lib/js/dartium/js_dartium.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,7 @@ class JsArray<E> extends JsObject with ListMixin<E> {
807807
_checkIndex(index);
808808
}
809809

810-
// Lazily create the Dart class that wraps the JS object when the object in
811-
// a list if fetched.
812-
var wrap_entry = html.wrap_jso(super[index]);
813-
super[index] = wrap_entry;
814-
return wrap_entry;
810+
return super[index];
815811
}
816812

817813
void operator []=(index, E value) {

sdk/lib/web_sql/dartium/web_sql_dartium.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,6 @@ class SqlTransaction extends NativeFieldWrapperClass2 {
412412

413413
@DomName('SQLTransaction.executeSql')
414414
@DocsEditable()
415-
void executeSql(String sqlStatement, List<Object> arguments, [SqlStatementCallback callback, SqlStatementErrorCallback errorCallback]) => _blink.BlinkSQLTransaction.instance.executeSql_Callback_4_(unwrap_jso(this), sqlStatement, arguments, unwrap_jso((transaction, resultSet) => callback(wrap_jso(transaction), wrap_jso(resultSet))), unwrap_jso((transaction, error) => errorCallback(wrap_jso(transaction), wrap_jso(error))));
415+
void executeSql(String sqlStatement, List<Object> arguments, [SqlStatementCallback callback, SqlStatementErrorCallback errorCallback]) => _blink.BlinkSQLTransaction.instance.executeSql_Callback_4_(unwrap_jso(this), sqlStatement, unwrap_jso(arguments), unwrap_jso((transaction, resultSet) => callback(wrap_jso(transaction), wrap_jso(resultSet))), unwrap_jso((transaction, error) => errorCallback(wrap_jso(transaction), wrap_jso(error))));
416416

417417
}

tests/html/html.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ canvasrenderingcontext2d_test/drawImage_video_element_dataUrl: Pass,Fail # Issue
6161
[ $compiler == none && ($runtime == drt || $runtime == dartium || $runtime == ContentShellOnAndroid) ]
6262
# postMessage in dartium always transfers the typed array buffer, never a view
6363
postmessage_structured_test/typed_arrays: Fail
64-
postmessage_structured_test/primitives: RuntimeError # Bug 24432
6564
# Dartium seems to lose the data from the dispatchEvent.
6665
async_test: Fail # Uses spawn, not implemented from a DOM isolate in Dartium
6766
keyboard_event_test: Fail # Issue 13902
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library wrapping_collection_test;
2+
3+
import 'dart:html';
4+
import 'dart:js' as js;
5+
import 'package:unittest/unittest.dart';
6+
import 'package:unittest/html_config.dart';
7+
8+
/// Test that if we access objects through JS-interop we get the
9+
/// appropriate objects, even if dart:html maps them.
10+
main() {
11+
test("Access through JS-interop", () {
12+
var performance = js.context['performance'];
13+
var entries = performance.callMethod('getEntries', const []);
14+
entries.forEach((x) {
15+
expect(x is js.JsObject, isTrue);
16+
});
17+
});
18+
19+
test("Access through dart:html", () {
20+
var dartPerformance = wrap_jso(js.context['performance']);
21+
var dartEntries = dartPerformance.getEntries();
22+
dartEntries.forEach((x) {
23+
expect(x is PerformanceEntry, isTrue);
24+
});
25+
});
26+
}

tools/dom/scripts/generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def param_name(param_info):
515515
return ', '.join(map(param_name, self.param_infos[:parameter_count]))
516516

517517
def isCallback(self, type_registry, type_id):
518-
if type_id:
518+
if type_id and not type_id.endswith('[]'):
519519
callback_type = type_registry._database._all_interfaces[type_id]
520520
return callback_type.operations[0].id == 'handleEvent' if len(callback_type.operations) > 0 else False
521521
else:
@@ -1446,7 +1446,8 @@ def wrap_unwrap_type_blink(return_type, type_registry):
14461446
return_type == 'Future' or
14471447
return_type == 'SqlDatabase' or # renamed to Database
14481448
return_type == 'HTMLElement' or
1449-
return_type == 'MutationObserver')
1449+
return_type == 'MutationObserver' or
1450+
return_type.endswith('[]'))
14501451

14511452
def wrap_type_blink(return_type, type_registry):
14521453
"""Returns True if the type is a blink type that requires wrap_jso but

tools/dom/templates/html/dartium/html_dartium.darttemplate

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ wrap_jso(jsObject) {
404404
return wrapper;
405405
}
406406

407+
if (jsObject is js.JsArray) {
408+
var wrappingList = new _DartHtmlWrappingList(jsObject);
409+
js.setDartHtmlWrapperFor(jsObject, wrappingList);
410+
return wrappingList;
411+
}
412+
407413
// Try the most general type conversions on it.
408414
// TODO(alanknight): We may be able to do better. This maintains identity,
409415
// which is useful, but expensive. And if we nest something that only
@@ -549,6 +555,22 @@ convertDartToNative_List(List input) => new js.JsArray()..addAll(input);
549555
// Conversion function place holder (currently not used in dart2js or dartium).
550556
List convertDartToNative_StringArray(List<String> input) => input;
551557

558+
/**
559+
* Wraps a JsArray and will call wrap_jso on its entries.
560+
*/
561+
class _DartHtmlWrappingList extends ListBase {
562+
_DartHtmlWrappingList(this._basicList);
563+
564+
final js.JsArray _basicList;
565+
566+
operator [](int index) => wrap_jso(_basicList[index]);
567+
568+
operator []=(int index, value) => _basicList[index] = unwrap_jso(value);
569+
570+
int get length => _basicList.length;
571+
int set length(int newLength) => _basicList.length = newLength;
572+
}
573+
552574
$else
553575
class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {}
554576

tools/dom/templates/html/impl/impl_MutationObserver.darttemplate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $if DARTIUM
2222
@DocsEditable()
2323
$if JSINTEROP
2424
static MutationObserver _create(callback) => wrap_jso(_blink.BlinkMutationObserver.instance.constructorCallback_1_((mutations, observer) {
25-
callback(mutations, wrap_jso(observer));
25+
callback(wrap_jso(mutations), wrap_jso(observer));
2626
}));
2727
$else
2828
static MutationObserver _create(callback) => _blink.BlinkMutationObserver.instance.constructorCallback_1_(callback);

0 commit comments

Comments
 (0)