Browser compat fix for setInterval and SetTimeout.

Firefox passes an argument to the TimeoutHander, Chrome doesn't.  Fix
by dropping all arguments before calling the strict Dart function.

BUG=
TEST=

Review URL: https://chromereviews.googleplex.com/3544020

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@163 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
sra@google.com 2011-10-06 22:08:36 +00:00
parent acd85abe79
commit 5883649a35
3 changed files with 90 additions and 40 deletions

View file

@ -4830,22 +4830,6 @@ function native__DOMWindowWrappingImplementation__scrollTo(_this, x, y) {
}
}
function native__DOMWindowWrappingImplementation__setInterval(_this, handler, timeout) {
try {
return __dom_wrap(_this.$dom.setInterval(__dom_unwrap(handler), __dom_unwrap(timeout)));
} catch (e) {
throw __dom_wrap_exception(e);
}
}
function native__DOMWindowWrappingImplementation__setTimeout(_this, handler, timeout) {
try {
return __dom_wrap(_this.$dom.setTimeout(__dom_unwrap(handler), __dom_unwrap(timeout)));
} catch (e) {
throw __dom_wrap_exception(e);
}
}
function native__DOMWindowWrappingImplementation__showModalDialog(_this, url) {
try {
return __dom_wrap(_this.$dom.showModalDialog(__dom_unwrap(url)));
@ -25295,22 +25279,6 @@ function native__WorkerContextWrappingImplementation__removeEventListener_2(_thi
}
}
function native__WorkerContextWrappingImplementation__setInterval(_this, handler, timeout) {
try {
return __dom_wrap(_this.$dom.setInterval(__dom_unwrap(handler), __dom_unwrap(timeout)));
} catch (e) {
throw __dom_wrap_exception(e);
}
}
function native__WorkerContextWrappingImplementation__setTimeout(_this, handler, timeout) {
try {
return __dom_wrap(_this.$dom.setTimeout(__dom_unwrap(handler), __dom_unwrap(timeout)));
} catch (e) {
throw __dom_wrap_exception(e);
}
}
function native__WorkerLocationWrappingImplementation__get__WorkerLocation_hash(_this) {
try {
return __dom_wrap(_this.$dom.hash);
@ -26120,6 +26088,31 @@ function native__XSLTProcessorWrappingImplementation__transformToFragment(_this,
}
function __dom_native_TimeoutHander_method(_this, callback, timeout, operation) {
try {
return _this.$dom[operation](__dom_unwrap_TimeoutHandler_function(callback),
__dom_unwrap(timeout));
} catch (e) {
throw __dom_wrap_exception(e);
}
}
function native__DOMWindowWrappingImplementation__setInterval(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setInterval');
}
function native__DOMWindowWrappingImplementation__setTimeout(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setTimeout');
}
function native__WorkerContextWrappingImplementation__setInterval(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setInterval');
}
function native__WorkerContextWrappingImplementation__setTimeout(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setTimeout');
}
function native__DOMWindowWrappingImplementation__createFileReader(_this) {
try {
return __dom_wrap(new FileReader());
@ -26704,6 +26697,14 @@ function __dom_wrap_primitive(ptr) {
return (ptr === null) ? (void 0) : ptr;
}
function __dom_finish_unwrap_function(fn, unwrapped) {
fn.$dom = unwrapped;
var isolatetoken = __dom_isolate_token();
__dom_set_cached('dart_wrapper', unwrapped, isolatetoken, fn);
return unwrapped;
}
/** @suppress {duplicate} */
function __dom_unwrap(obj) {
if (obj == null) {
@ -26718,14 +26719,20 @@ function __dom_unwrap(obj) {
return $dartcall(obj, args.map(__dom_wrap));
// BUGBUG? Should the result be unwrapped? Or is it always void/bool ?
};
obj.$dom = unwrapped;
var isolatetoken = __dom_isolate_token();
__dom_set_cached('dart_wrapper', unwrapped, isolatetoken, obj);
return unwrapped;
return __dom_finish_unwrap_function(obj, unwrapped);
}
return obj;
}
function __dom_unwrap_TimeoutHandler_function(fn) {
// Some browsers (e.g. FF) pass data to the timeout function, others do not.
// Dart's TimeoutHandler takes no arguments, so drop any arguments passed to
// the unwrapped callback.
return __dom_finish_unwrap_function(
fn,
function() { return $dartcall(fn, []); });
}
// Declared in src/GlobalProperties.dart
function native__NativeDomGlobalProperties_getWindow() {
// TODO: Should the window be obtained from an isolate?

View file

@ -69,6 +69,10 @@ _custom_methods = set([
('DOMWindow', 'createWebKitCSSMatrix'),
('DOMWindow', 'createWebKitPoint'),
('DOMWindow', 'createXMLHttpRequest'),
('DOMWindow', 'setInterval'),
('DOMWindow', 'setTimeout'),
('WorkerContext', 'setInterval'),
('WorkerContext', 'setTimeout'),
('CanvasRenderingContext2D', 'setFillStyle'),
('CanvasRenderingContext2D', 'setStrokeStyle'),
('CanvasRenderingContext2D', 'setFillStyle'),

View file

@ -7,6 +7,31 @@
$!CODE
function __dom_native_TimeoutHander_method(_this, callback, timeout, operation) {
try {
return _this.$dom[operation](__dom_unwrap_TimeoutHandler_function(callback),
__dom_unwrap(timeout));
} catch (e) {
throw __dom_wrap_exception(e);
}
}
function native__DOMWindowWrappingImplementation__setInterval(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setInterval');
}
function native__DOMWindowWrappingImplementation__setTimeout(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setTimeout');
}
function native__WorkerContextWrappingImplementation__setInterval(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setInterval');
}
function native__WorkerContextWrappingImplementation__setTimeout(_this, callback, timeout) {
return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setTimeout');
}
function native__DOMWindowWrappingImplementation__createFileReader(_this) {
try {
return __dom_wrap(new FileReader());
@ -254,6 +279,14 @@ function __dom_wrap_primitive(ptr) {
return (ptr === null) ? (void 0) : ptr;
}
function __dom_finish_unwrap_function(fn, unwrapped) {
fn.$dom = unwrapped;
var isolatetoken = __dom_isolate_token();
__dom_set_cached('dart_wrapper', unwrapped, isolatetoken, fn);
return unwrapped;
}
/** @suppress {duplicate} */
function __dom_unwrap(obj) {
if (obj == null) {
@ -268,14 +301,20 @@ function __dom_unwrap(obj) {
return $dartcall(obj, args.map(__dom_wrap));
// BUGBUG? Should the result be unwrapped? Or is it always void/bool ?
};
obj.$dom = unwrapped;
var isolatetoken = __dom_isolate_token();
__dom_set_cached('dart_wrapper', unwrapped, isolatetoken, obj);
return unwrapped;
return __dom_finish_unwrap_function(obj, unwrapped);
}
return obj;
}
function __dom_unwrap_TimeoutHandler_function(fn) {
// Some browsers (e.g. FF) pass data to the timeout function, others do not.
// Dart's TimeoutHandler takes no arguments, so drop any arguments passed to
// the unwrapped callback.
return __dom_finish_unwrap_function(
fn,
function() { return $dartcall(fn, []); });
}
// Declared in src/GlobalProperties.dart
function native__NativeDomGlobalProperties_getWindow() {
// TODO: Should the window be obtained from an isolate?