mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Implement WorkerGlobalScope.importScripts.
This commit is contained in:
parent
061e7e1620
commit
aed642babe
14 changed files with 44 additions and 54 deletions
|
@ -18,7 +18,8 @@ interface WorkerGlobalScope : EventTarget {
|
|||
// http://www.whatwg.org/html/#WorkerGlobalScope-partial
|
||||
//[Exposed=Worker]
|
||||
partial interface WorkerGlobalScope { // not obsolete
|
||||
//void importScripts(DOMString... urls);
|
||||
[Throws]
|
||||
void importScripts(DOMString... urls);
|
||||
readonly attribute WorkerNavigator navigator;
|
||||
};
|
||||
//WorkerGlobalScope implements WindowTimers;
|
||||
|
|
|
@ -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::error::{ErrorResult, Syntax, Network, FailureUnknown};
|
||||
use dom::bindings::trace::Untraceable;
|
||||
use dom::bindings::global;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
|
||||
|
@ -13,14 +14,15 @@ use dom::workerlocation::WorkerLocation;
|
|||
use dom::workernavigator::WorkerNavigator;
|
||||
use script_task::ScriptChan;
|
||||
|
||||
use servo_net::resource_task::ResourceTask;
|
||||
use servo_net::resource_task::{ResourceTask, load_whole_resource};
|
||||
use servo_util::str::DOMString;
|
||||
|
||||
use js::jsapi::JSContext;
|
||||
use js::rust::Cx;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
use url::Url;
|
||||
use url::{Url, UrlParser};
|
||||
|
||||
#[deriving(PartialEq,Encodable)]
|
||||
pub enum WorkerGlobalScopeId {
|
||||
|
@ -87,6 +89,38 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
|||
Temporary::new(self.location.get().get_ref().clone())
|
||||
}
|
||||
|
||||
fn ImportScripts(&self, url_strings: Vec<DOMString>) -> ErrorResult {
|
||||
let mut urls = Vec::with_capacity(url_strings.len());
|
||||
for url in url_strings.move_iter() {
|
||||
let url = UrlParser::new().base_url(&*self.worker_url)
|
||||
.parse(url.as_slice());
|
||||
match url {
|
||||
Ok(url) => urls.push(url),
|
||||
Err(_) => return Err(Syntax),
|
||||
};
|
||||
}
|
||||
|
||||
for url in urls.move_iter() {
|
||||
let (url, source) = match load_whole_resource(&*self.resource_task, url) {
|
||||
Err(_) => return Err(Network),
|
||||
Ok((metadata, bytes)) => {
|
||||
(metadata.final_url, String::from_utf8(bytes).unwrap())
|
||||
}
|
||||
};
|
||||
|
||||
match self.js_context.evaluate_script(
|
||||
self.reflector().get_jsobject(), source, url.serialize(), 1) {
|
||||
Ok(_) => (),
|
||||
Err(_) => {
|
||||
println!("evaluate_script failed");
|
||||
return Err(FailureUnknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn Navigator(&self) -> Temporary<WorkerNavigator> {
|
||||
if self.navigator.get().is_none() {
|
||||
let navigator = WorkerNavigator::new(self);
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[WorkerGlobalScope_importScripts.htm]
|
||||
type: testharness
|
||||
[Test Description: WorkerGlobalScope API: importScripts().]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
[WorkerGlobalScope_importScripts_NetworkErr.htm]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[Test Description: importScripts(): Throw NETWORK_ERR exception whenever attempt to fetch script is failed.]
|
||||
expected: FAIL
|
||||
expected: NOTRUN
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[001.html]
|
||||
type: testharness
|
||||
[importScripts no arguments]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[002.html]
|
||||
type: testharness
|
||||
[importScripts resolving urls]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[003.html]
|
||||
type: testharness
|
||||
[importScripts running scripts]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
[004.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[importScripts broken script]
|
||||
expected: FAIL
|
||||
expected: TIMEOUT
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[007.html]
|
||||
[005.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[postMessage in importScripts]
|
||||
[importScripts separate scripts]
|
||||
expected: TIMEOUT
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[008.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[variables and functions crossing importScripts boundary]
|
||||
expected: TIMEOUT
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[009.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[variables and functions crossing importScripts boundary, take 2]
|
||||
expected: TIMEOUT
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[010.html]
|
||||
type: testharness
|
||||
[importScripts(undefined)]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[011.html]
|
||||
type: testharness
|
||||
[importScripts(null)]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[012.html]
|
||||
type: testharness
|
||||
[importScripts(1)]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue