From 5883649a35f092bfa7bcef62f070bdd725ce6249 Mon Sep 17 00:00:00 2001 From: "sra@google.com" Date: Thu, 6 Oct 2011 22:08:36 +0000 Subject: [PATCH] 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 --- client/dom/generated/wrapping_dom.js | 79 +++++++++++---------- client/dom/scripts/dartgenerator.py | 4 ++ client/dom/scripts/template_wrapping_dom.js | 47 ++++++++++-- 3 files changed, 90 insertions(+), 40 deletions(-) diff --git a/client/dom/generated/wrapping_dom.js b/client/dom/generated/wrapping_dom.js index 253086e2e55..b165b7077a8 100644 --- a/client/dom/generated/wrapping_dom.js +++ b/client/dom/generated/wrapping_dom.js @@ -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? diff --git a/client/dom/scripts/dartgenerator.py b/client/dom/scripts/dartgenerator.py index 170015814fc..2a3e08ff88e 100755 --- a/client/dom/scripts/dartgenerator.py +++ b/client/dom/scripts/dartgenerator.py @@ -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'), diff --git a/client/dom/scripts/template_wrapping_dom.js b/client/dom/scripts/template_wrapping_dom.js index 33ebcb44119..1634ff35b58 100644 --- a/client/dom/scripts/template_wrapping_dom.js +++ b/client/dom/scripts/template_wrapping_dom.js @@ -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?