Serialize the data argument to History's state-related APIs.

BUG=

Review URL: https://codereview.chromium.org/1414903007 .
This commit is contained in:
Alan Knight 2015-11-05 16:23:44 -08:00
parent 82e83bb34d
commit 42b9d7b702
4 changed files with 73 additions and 5 deletions

View file

@ -17864,7 +17864,32 @@ class History extends Interceptor implements HistoryBase {
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void pushState(Object data, String title, [String url]) native;
void pushState(/*any*/ data, String title, [String url]) {
if (url != null) {
var data_1 = convertDartToNative_SerializedScriptValue(data);
_pushState_1(data_1, title, url);
return;
}
var data_1 = convertDartToNative_SerializedScriptValue(data);
_pushState_2(data_1, title);
return;
}
@JSName('pushState')
@DomName('History.pushState')
@DocsEditable()
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void _pushState_1(data, title, url) native;
@JSName('pushState')
@DomName('History.pushState')
@DocsEditable()
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void _pushState_2(data, title) native;
@DomName('History.replaceState')
@DocsEditable()
@ -17872,7 +17897,32 @@ class History extends Interceptor implements HistoryBase {
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void replaceState(Object data, String title, [String url]) native;
void replaceState(/*any*/ data, String title, [String url]) {
if (url != null) {
var data_1 = convertDartToNative_SerializedScriptValue(data);
_replaceState_1(data_1, title, url);
return;
}
var data_1 = convertDartToNative_SerializedScriptValue(data);
_replaceState_2(data_1, title);
return;
}
@JSName('replaceState')
@DomName('History.replaceState')
@DocsEditable()
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void _replaceState_1(data, title, url) native;
@JSName('replaceState')
@DomName('History.replaceState')
@DocsEditable()
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void _replaceState_2(data, title) native;
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a

View file

@ -19940,7 +19940,7 @@ class History extends DartHtmlDomObject implements HistoryBase {
@DomName('History.state')
@DocsEditable()
dynamic get state => _blink.BlinkHistory.instance.state_Getter_(unwrap_jso(this));
dynamic get state => wrap_jso(_blink.BlinkHistory.instance.state_Getter_(unwrap_jso(this)));
@DomName('History.back')
@DocsEditable()
@ -19960,7 +19960,7 @@ class History extends DartHtmlDomObject implements HistoryBase {
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void pushState(Object data, String title, [String url]) => _blink.BlinkHistory.instance.pushState_Callback_3_(unwrap_jso(this), data, title, url);
void pushState(Object data, String title, [String url]) => _blink.BlinkHistory.instance.pushState_Callback_3_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(data), title, url);
@DomName('History.replaceState')
@DocsEditable()
@ -19968,7 +19968,7 @@ class History extends DartHtmlDomObject implements HistoryBase {
@SupportedBrowser(SupportedBrowser.FIREFOX)
@SupportedBrowser(SupportedBrowser.IE, '10')
@SupportedBrowser(SupportedBrowser.SAFARI)
void replaceState(Object data, String title, [String url]) => _blink.BlinkHistory.instance.replaceState_Callback_3_(unwrap_jso(this), data, title, url);
void replaceState(Object data, String title, [String url]) => _blink.BlinkHistory.instance.replaceState_Callback_3_(unwrap_jso(this), convertDartToNative_SerializedScriptValue(data), title, url);
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a

View file

@ -34,6 +34,17 @@ main() {
}, expectation);
});
test('pushState with data', () {
expect(() {
window.history.pushState({'one' : 1}, document.title, '?dummy');
expect(window.history.state, equals({'one' : 1}));
window.history.pushState(null, document.title, '?foo=bar');
expect(window.location.href.endsWith('foo=bar'), isTrue);
}, expectation);
});
test('back', () {
expect(() {
window.history.pushState(null, document.title, '?dummy1');

View file

@ -732,6 +732,12 @@ dart2js_conversions = monitored.Dict('generator.dart2js_conversions', {
Conversion('convertNativeToDart_SerializedScriptValue',
'dynamic', 'dynamic'),
# TODO(alanknight): This generates two variations for dart2js, because of
# the optional argument, but not in Dartium. Should do the same for both.
'any set History.pushState': _serialize_SSV,
'any set History.replaceState': _serialize_SSV,
'* get History.state':
Conversion('convertNativeToDart_SerializedScriptValue',
'dynamic', 'dynamic'),
@ -1443,6 +1449,7 @@ def wrap_unwrap_type_blink(return_type, type_registry):
return_type = return_type.replace('Html', 'HTML', 1)
return (type_registry.HasInterface(return_type) or not(return_type) or
return_type == 'Object' or
return_type == 'dynamic' or
return_type == 'Future' or
return_type == 'SqlDatabase' or # renamed to Database
return_type == 'HTMLElement' or