mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Allow passing arguments to setTimeout/setInterval callbacks
This commit is contained in:
parent
05bd182538
commit
4b2b0d0723
12 changed files with 88 additions and 45 deletions
|
@ -146,7 +146,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
Worker::handle_release(addr)
|
||||
},
|
||||
Ok(FireTimerMsg(FromWorker, timer_id)) => {
|
||||
scope.handle_fire_timer(timer_id, js_context.ptr);
|
||||
scope.handle_fire_timer(timer_id);
|
||||
}
|
||||
Ok(_) => panic!("Unexpected message"),
|
||||
Err(_) => break,
|
||||
|
|
14
components/script/dom/webidls/Function.webidl
Normal file
14
components/script/dom/webidls/Function.webidl
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/#functiocn
|
||||
*
|
||||
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
|
||||
* Opera Software ASA. You are granted a license to use, reproduce
|
||||
* and create derivative works of this document.
|
||||
*/
|
||||
|
||||
callback Function = any(any... arguments);
|
|
@ -64,13 +64,11 @@ Window implements WindowEventHandlers;
|
|||
// http://www.whatwg.org/html/#windowtimers
|
||||
[NoInterfaceObject/*, Exposed=Window,Worker*/]
|
||||
interface WindowTimers {
|
||||
//long setTimeout(Function handler, optional long timeout = 0, any... arguments);
|
||||
long setTimeout(Function handler, optional long timeout = 0, any... arguments);
|
||||
//long setTimeout(DOMString handler, optional long timeout = 0, any... arguments);
|
||||
long setTimeout(any handler, optional long timeout = 0);
|
||||
void clearTimeout(optional long handle = 0);
|
||||
//long setInterval(Function handler, optional long timeout = 0, any... arguments);
|
||||
long setInterval(Function handler, optional long timeout = 0, any... arguments);
|
||||
//long setInterval(DOMString handler, optional long timeout = 0, any... arguments);
|
||||
long setInterval(any handler, optional long timeout = 0);
|
||||
void clearInterval(optional long handle = 0);
|
||||
};
|
||||
Window implements WindowTimers;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerNonNull, EventHandlerNonNull};
|
||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
||||
|
@ -223,8 +224,9 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
|||
self.navigator.get().unwrap()
|
||||
}
|
||||
|
||||
fn SetTimeout(self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 {
|
||||
fn SetTimeout(self, _cx: *mut JSContext, callback: Function, timeout: i32, args: Vec<JSVal>) -> i32 {
|
||||
self.timers.set_timeout_or_interval(callback,
|
||||
args,
|
||||
timeout,
|
||||
false, // is_interval
|
||||
FromWindow(self.page.id.clone()),
|
||||
|
@ -235,8 +237,9 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
|||
self.timers.clear_timeout_or_interval(handle);
|
||||
}
|
||||
|
||||
fn SetInterval(self, _cx: *mut JSContext, callback: JSVal, timeout: i32) -> i32 {
|
||||
fn SetInterval(self, _cx: *mut JSContext, callback: Function, timeout: i32, args: Vec<JSVal>) -> i32 {
|
||||
self.timers.set_timeout_or_interval(callback,
|
||||
args,
|
||||
timeout,
|
||||
true, // is_interval
|
||||
FromWindow(self.page.id.clone()),
|
||||
|
@ -317,7 +320,7 @@ pub trait WindowHelpers {
|
|||
fn wait_until_safe_to_modify_dom(self);
|
||||
fn init_browser_context(self, doc: JSRef<Document>);
|
||||
fn load_url(self, href: DOMString);
|
||||
fn handle_fire_timer(self, timer_id: TimerId, cx: *mut JSContext);
|
||||
fn handle_fire_timer(self, timer_id: TimerId);
|
||||
fn evaluate_js_with_result(self, code: &str) -> JSVal;
|
||||
fn evaluate_script_with_result(self, code: &str, filename: &str) -> JSVal;
|
||||
}
|
||||
|
@ -380,9 +383,8 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_fire_timer(self, timer_id: TimerId, cx: *mut JSContext) {
|
||||
let this_value = self.reflector().get_jsobject();
|
||||
self.timers.fire_timer(timer_id, this_value, cx);
|
||||
fn handle_fire_timer(self, timer_id: TimerId) {
|
||||
self.timers.fire_timer(timer_id, self.clone());
|
||||
self.flush_layout();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use dom::bindings::error::{ErrorResult, Fallible, Syntax, Network, FailureUnknown};
|
||||
use dom::bindings::global;
|
||||
use dom::bindings::js::{MutNullableJS, JSRef, Temporary, OptionalSettable};
|
||||
|
@ -155,8 +156,9 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
|||
base64_atob(atob)
|
||||
}
|
||||
|
||||
fn SetTimeout(self, _cx: *mut JSContext, handler: JSVal, timeout: i32) -> i32 {
|
||||
self.timers.set_timeout_or_interval(handler,
|
||||
fn SetTimeout(self, _cx: *mut JSContext, callback: Function, timeout: i32, args: Vec<JSVal>) -> i32 {
|
||||
self.timers.set_timeout_or_interval(callback,
|
||||
args,
|
||||
timeout,
|
||||
false, // is_interval
|
||||
FromWorker,
|
||||
|
@ -167,8 +169,9 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
|||
self.timers.clear_timeout_or_interval(handle);
|
||||
}
|
||||
|
||||
fn SetInterval(self, _cx: *mut JSContext, handler: JSVal, timeout: i32) -> i32 {
|
||||
self.timers.set_timeout_or_interval(handler,
|
||||
fn SetInterval(self, _cx: *mut JSContext, callback: Function, timeout: i32, args: Vec<JSVal>) -> i32 {
|
||||
self.timers.set_timeout_or_interval(callback,
|
||||
args,
|
||||
timeout,
|
||||
true, // is_interval
|
||||
FromWorker,
|
||||
|
@ -181,14 +184,13 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
|||
}
|
||||
|
||||
pub trait WorkerGlobalScopeHelpers {
|
||||
fn handle_fire_timer(self, timer_id: TimerId, cx: *mut JSContext);
|
||||
fn handle_fire_timer(self, timer_id: TimerId);
|
||||
}
|
||||
|
||||
impl<'a> WorkerGlobalScopeHelpers for JSRef<'a, WorkerGlobalScope> {
|
||||
|
||||
fn handle_fire_timer(self, timer_id: TimerId, cx: *mut JSContext) {
|
||||
let this_value = self.reflector().get_jsobject();
|
||||
self.timers.fire_timer(timer_id, this_value, cx);
|
||||
fn handle_fire_timer(self, timer_id: TimerId) {
|
||||
self.timers.fire_timer(timer_id, self.clone());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue