mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
script creates methods taking '*mut JSContext' unsafe
rebase + marked the necessary new code as unsafe
This commit is contained in:
parent
9fd6f0acd5
commit
b372e7c98f
28 changed files with 274 additions and 226 deletions
|
@ -2316,10 +2316,13 @@ class CGAbstractMethod(CGThing):
|
||||||
arguments.
|
arguments.
|
||||||
|
|
||||||
docs is None or documentation for the method in a string.
|
docs is None or documentation for the method in a string.
|
||||||
|
|
||||||
|
unsafe is used to add the decorator 'unsafe' to a function, giving as a result
|
||||||
|
an 'unsafe fn()' declaration.
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, name, returnType, args, inline=False,
|
def __init__(self, descriptor, name, returnType, args, inline=False,
|
||||||
alwaysInline=False, extern=False, unsafe_fn=False, pub=False,
|
alwaysInline=False, extern=False, unsafe=False, pub=False,
|
||||||
templateArgs=None, unsafe=False, docs=None, doesNotPanic=False):
|
templateArgs=None, docs=None, doesNotPanic=False):
|
||||||
CGThing.__init__(self)
|
CGThing.__init__(self)
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -2327,10 +2330,9 @@ class CGAbstractMethod(CGThing):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.alwaysInline = alwaysInline
|
self.alwaysInline = alwaysInline
|
||||||
self.extern = extern
|
self.extern = extern
|
||||||
self.unsafe_fn = extern or unsafe_fn
|
self.unsafe = extern or unsafe
|
||||||
self.templateArgs = templateArgs
|
self.templateArgs = templateArgs
|
||||||
self.pub = pub
|
self.pub = pub
|
||||||
self.unsafe = unsafe
|
|
||||||
self.docs = docs
|
self.docs = docs
|
||||||
self.catchPanic = self.extern and not doesNotPanic
|
self.catchPanic = self.extern and not doesNotPanic
|
||||||
|
|
||||||
|
@ -2357,7 +2359,7 @@ class CGAbstractMethod(CGThing):
|
||||||
if self.pub:
|
if self.pub:
|
||||||
decorators.append('pub')
|
decorators.append('pub')
|
||||||
|
|
||||||
if self.unsafe_fn:
|
if self.unsafe:
|
||||||
decorators.append('unsafe')
|
decorators.append('unsafe')
|
||||||
|
|
||||||
if self.extern:
|
if self.extern:
|
||||||
|
@ -2373,10 +2375,6 @@ class CGAbstractMethod(CGThing):
|
||||||
def define(self):
|
def define(self):
|
||||||
body = self.definition_body()
|
body = self.definition_body()
|
||||||
|
|
||||||
# Method will already be marked `unsafe` if `self.extern == True`
|
|
||||||
if self.unsafe and not self.extern:
|
|
||||||
body = CGWrapper(CGIndenter(body), pre="unsafe {\n", post="\n}")
|
|
||||||
|
|
||||||
if self.catchPanic:
|
if self.catchPanic:
|
||||||
body = CGWrapper(CGIndenter(body),
|
body = CGWrapper(CGIndenter(body),
|
||||||
pre="return wrap_panic(|| {\n",
|
pre="return wrap_panic(|| {\n",
|
||||||
|
@ -2409,7 +2407,7 @@ class CGConstructorEnabled(CGAbstractMethod):
|
||||||
'ConstructorEnabled', 'bool',
|
'ConstructorEnabled', 'bool',
|
||||||
[Argument("*mut JSContext", "aCx"),
|
[Argument("*mut JSContext", "aCx"),
|
||||||
Argument("HandleObject", "aObj")],
|
Argument("HandleObject", "aObj")],
|
||||||
unsafe_fn=True)
|
unsafe=True)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
conditions = []
|
conditions = []
|
||||||
|
@ -3089,7 +3087,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
|
||||||
Argument('HandleObject', 'global'),
|
Argument('HandleObject', 'global'),
|
||||||
]
|
]
|
||||||
CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface',
|
CGAbstractMethod.__init__(self, descriptor, 'DefineDOMInterface',
|
||||||
'void', args, pub=True, unsafe_fn=True)
|
'void', args, pub=True, unsafe=True)
|
||||||
|
|
||||||
def define(self):
|
def define(self):
|
||||||
return CGAbstractMethod.define(self)
|
return CGAbstractMethod.define(self)
|
||||||
|
@ -5349,10 +5347,19 @@ class CGInterfaceTrait(CGThing):
|
||||||
def fmt(arguments):
|
def fmt(arguments):
|
||||||
return "".join(", %s: %s" % argument for argument in arguments)
|
return "".join(", %s: %s" % argument for argument in arguments)
|
||||||
|
|
||||||
methods = [
|
def contains_unsafe_arg(arguments):
|
||||||
CGGeneric("fn %s(&self%s) -> %s;\n" % (name, fmt(arguments), rettype))
|
if not arguments or len(arguments) == 0:
|
||||||
for name, arguments, rettype in members()
|
return False
|
||||||
]
|
return reduce((lambda x, y: x or y[1] == '*mut JSContext'), arguments, False)
|
||||||
|
|
||||||
|
methods = []
|
||||||
|
for name, arguments, rettype in members():
|
||||||
|
arguments = list(arguments)
|
||||||
|
methods.append(CGGeneric("%sfn %s(&self%s) -> %s;\n" % (
|
||||||
|
'unsafe ' if contains_unsafe_arg(arguments) else '',
|
||||||
|
name, fmt(arguments), rettype))
|
||||||
|
)
|
||||||
|
|
||||||
if methods:
|
if methods:
|
||||||
self.cgRoot = CGWrapper(CGIndenter(CGList(methods, "")),
|
self.cgRoot = CGWrapper(CGIndenter(CGList(methods, "")),
|
||||||
pre="pub trait %sMethods {\n" % descriptor.interface.identifier.name,
|
pre="pub trait %sMethods {\n" % descriptor.interface.identifier.name,
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl<T: Reflectable + JSTraceable + Iterable> IterableIterator<T> {
|
||||||
/// Create a new iterator instance for the provided iterable DOM interface.
|
/// Create a new iterator instance for the provided iterable DOM interface.
|
||||||
pub fn new(iterable: &T,
|
pub fn new(iterable: &T,
|
||||||
type_: IteratorType,
|
type_: IteratorType,
|
||||||
wrap: fn(*mut JSContext, &GlobalScope, Box<IterableIterator<T>>)
|
wrap: unsafe fn(*mut JSContext, &GlobalScope, Box<IterableIterator<T>>)
|
||||||
-> Root<Self>) -> Root<Self> {
|
-> Root<Self>) -> Root<Self> {
|
||||||
let iterator = box IterableIterator {
|
let iterator = box IterableIterator {
|
||||||
reflector: Reflector::new(),
|
reflector: Reflector::new(),
|
||||||
|
|
|
@ -16,13 +16,15 @@ use std::ptr;
|
||||||
pub fn reflect_dom_object<T, U>(
|
pub fn reflect_dom_object<T, U>(
|
||||||
obj: Box<T>,
|
obj: Box<T>,
|
||||||
global: &U,
|
global: &U,
|
||||||
wrap_fn: fn(*mut JSContext, &GlobalScope, Box<T>) -> Root<T>)
|
wrap_fn: unsafe fn(*mut JSContext, &GlobalScope, Box<T>) -> Root<T>)
|
||||||
-> Root<T>
|
-> Root<T>
|
||||||
where T: Reflectable, U: DerivedFrom<GlobalScope>
|
where T: Reflectable, U: DerivedFrom<GlobalScope>
|
||||||
{
|
{
|
||||||
let global_scope = global.upcast();
|
let global_scope = global.upcast();
|
||||||
|
unsafe {
|
||||||
wrap_fn(global_scope.get_cx(), global_scope, obj)
|
wrap_fn(global_scope.get_cx(), global_scope, obj)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A struct to store a reference to the reflector of a DOM object.
|
/// A struct to store a reference to the reflector of a DOM object.
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
|
|
|
@ -41,12 +41,12 @@ impl Crypto {
|
||||||
impl CryptoMethods for Crypto {
|
impl CryptoMethods for Crypto {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#Crypto-method-getRandomValues
|
// https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#Crypto-method-getRandomValues
|
||||||
fn GetRandomValues(&self,
|
unsafe fn GetRandomValues(&self,
|
||||||
_cx: *mut JSContext,
|
_cx: *mut JSContext,
|
||||||
input: *mut JSObject)
|
input: *mut JSObject)
|
||||||
-> Fallible<NonZero<*mut JSObject>> {
|
-> Fallible<NonZero<*mut JSObject>> {
|
||||||
assert!(!input.is_null());
|
assert!(!input.is_null());
|
||||||
let mut data = match unsafe { array_buffer_view_data::<u8>(input) } {
|
let mut data = match array_buffer_view_data::<u8>(input) {
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::Type("Argument to Crypto.getRandomValues is not an ArrayBufferView"
|
return Err(Error::Type("Argument to Crypto.getRandomValues is not an ArrayBufferView"
|
||||||
|
@ -64,7 +64,7 @@ impl CryptoMethods for Crypto {
|
||||||
|
|
||||||
self.rng.borrow_mut().fill_bytes(&mut data);
|
self.rng.borrow_mut().fill_bytes(&mut data);
|
||||||
|
|
||||||
Ok(unsafe { NonZero::new(input) })
|
Ok(NonZero::new(input))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,13 +76,15 @@ impl CustomEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomEventMethods for CustomEvent {
|
impl CustomEventMethods for CustomEvent {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://dom.spec.whatwg.org/#dom-customevent-detail
|
// https://dom.spec.whatwg.org/#dom-customevent-detail
|
||||||
fn Detail(&self, _cx: *mut JSContext) -> JSVal {
|
unsafe fn Detail(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
self.detail.get()
|
self.detail.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://dom.spec.whatwg.org/#dom-customevent-initcustomevent
|
// https://dom.spec.whatwg.org/#dom-customevent-initcustomevent
|
||||||
fn InitCustomEvent(&self,
|
unsafe fn InitCustomEvent(&self,
|
||||||
_cx: *mut JSContext,
|
_cx: *mut JSContext,
|
||||||
type_: DOMString,
|
type_: DOMString,
|
||||||
can_bubble: bool,
|
can_bubble: bool,
|
||||||
|
|
|
@ -117,6 +117,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
pub fn new(init: WorkerGlobalScopeInit,
|
pub fn new(init: WorkerGlobalScopeInit,
|
||||||
worker_url: Url,
|
worker_url: Url,
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
|
@ -139,8 +140,10 @@ impl DedicatedWorkerGlobalScope {
|
||||||
timer_event_chan,
|
timer_event_chan,
|
||||||
timer_event_port,
|
timer_event_port,
|
||||||
closing);
|
closing);
|
||||||
|
unsafe {
|
||||||
DedicatedWorkerGlobalScopeBinding::Wrap(cx, scope)
|
DedicatedWorkerGlobalScopeBinding::Wrap(cx, scope)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn run_worker_scope(init: WorkerGlobalScopeInit,
|
pub fn run_worker_scope(init: WorkerGlobalScopeInit,
|
||||||
|
@ -366,8 +369,9 @@ unsafe extern "C" fn interrupt_callback(cx: *mut JSContext) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
|
impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-dedicatedworkerglobalscope-postmessage
|
// https://html.spec.whatwg.org/multipage/#dom-dedicatedworkerglobalscope-postmessage
|
||||||
fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
unsafe fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
||||||
let data = try!(StructuredCloneData::write(cx, message));
|
let data = try!(StructuredCloneData::write(cx, message));
|
||||||
let worker = self.worker.borrow().as_ref().unwrap().clone();
|
let worker = self.worker.borrow().as_ref().unwrap().clone();
|
||||||
self.parent_sender
|
self.parent_sender
|
||||||
|
|
|
@ -2802,7 +2802,7 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
||||||
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
||||||
#[derive(JSTraceable, HeapSizeOf)]
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
struct NamedElementFilter {
|
struct NamedElementFilter {
|
||||||
name: Atom,
|
name: Atom,
|
||||||
|
@ -2870,9 +2870,7 @@ impl DocumentMethods for Document {
|
||||||
if elements.peek().is_none() {
|
if elements.peek().is_none() {
|
||||||
// TODO: Step 2.
|
// TODO: Step 2.
|
||||||
// Step 3.
|
// Step 3.
|
||||||
return unsafe {
|
return Some(NonZero::new(first.reflector().get_jsobject().get()));
|
||||||
Some(NonZero::new(first.reflector().get_jsobject().get()))
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
|
@ -2883,10 +2881,8 @@ impl DocumentMethods for Document {
|
||||||
name: name,
|
name: name,
|
||||||
};
|
};
|
||||||
let collection = HTMLCollection::create(self.window(), root, box filter);
|
let collection = HTMLCollection::create(self.window(), root, box filter);
|
||||||
unsafe {
|
|
||||||
Some(NonZero::new(collection.reflector().get_jsobject().get()))
|
Some(NonZero::new(collection.reflector().get_jsobject().get()))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
||||||
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
||||||
|
|
|
@ -130,8 +130,9 @@ impl ErrorEventMethods for ErrorEvent {
|
||||||
self.filename.borrow().clone()
|
self.filename.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-errorevent-error
|
// https://html.spec.whatwg.org/multipage/#dom-errorevent-error
|
||||||
fn Error(&self, _cx: *mut JSContext) -> JSVal {
|
unsafe fn Error(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
self.error.get()
|
self.error.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@ pub enum CompiledEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompiledEventListener {
|
impl CompiledEventListener {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm
|
// https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm
|
||||||
pub fn call_or_handle_event<T: Reflectable>(&self,
|
pub fn call_or_handle_event<T: Reflectable>(&self,
|
||||||
object: &T,
|
object: &T,
|
||||||
|
@ -155,7 +156,7 @@ impl CompiledEventListener {
|
||||||
CommonEventHandler::ErrorEventHandler(ref handler) => {
|
CommonEventHandler::ErrorEventHandler(ref handler) => {
|
||||||
if let Some(event) = event.downcast::<ErrorEvent>() {
|
if let Some(event) = event.downcast::<ErrorEvent>() {
|
||||||
let cx = object.global().get_cx();
|
let cx = object.global().get_cx();
|
||||||
rooted!(in(cx) let error = event.Error(cx));
|
rooted!(in(cx) let error = unsafe { event.Error(cx) });
|
||||||
let return_value = handler.Call_(object,
|
let return_value = handler.Call_(object,
|
||||||
EventOrString::String(event.Message()),
|
EventOrString::String(event.Message()),
|
||||||
Some(event.Filename()),
|
Some(event.Filename()),
|
||||||
|
|
|
@ -74,8 +74,9 @@ impl ExtendableMessageEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtendableMessageEventMethods for ExtendableMessageEvent {
|
impl ExtendableMessageEventMethods for ExtendableMessageEvent {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://w3c.github.io/ServiceWorker/#extendablemessage-event-data-attribute
|
// https://w3c.github.io/ServiceWorker/#extendablemessage-event-data-attribute
|
||||||
fn Data(&self, _cx: *mut JSContext) -> JSVal {
|
unsafe fn Data(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
self.data.get()
|
self.data.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -339,15 +339,13 @@ impl FileReaderMethods for FileReader {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://w3c.github.io/FileAPI/#dfn-result
|
// https://w3c.github.io/FileAPI/#dfn-result
|
||||||
fn GetResult(&self, _: *mut JSContext) -> Option<StringOrObject> {
|
unsafe fn GetResult(&self, _: *mut JSContext) -> Option<StringOrObject> {
|
||||||
self.result.borrow().as_ref().map(|r| match *r {
|
self.result.borrow().as_ref().map(|r| match *r {
|
||||||
FileReaderResult::String(ref string) =>
|
FileReaderResult::String(ref string) =>
|
||||||
StringOrObject::String(string.clone()),
|
StringOrObject::String(string.clone()),
|
||||||
FileReaderResult::ArrayBuffer(ref arr_buffer) => {
|
FileReaderResult::ArrayBuffer(ref arr_buffer) => {
|
||||||
unsafe {
|
|
||||||
StringOrObject::Object((*arr_buffer.ptr.get()).to_object())
|
StringOrObject::Object((*arr_buffer.ptr.get()).to_object())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,8 +235,9 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
||||||
make_uint_setter!(SetHeight, "height", DEFAULT_HEIGHT);
|
make_uint_setter!(SetHeight, "height", DEFAULT_HEIGHT);
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext
|
// https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext
|
||||||
fn GetContext(&self,
|
unsafe fn GetContext(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
id: DOMString,
|
id: DOMString,
|
||||||
attributes: Vec<HandleValue>)
|
attributes: Vec<HandleValue>)
|
||||||
|
@ -254,8 +255,9 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl
|
// https://html.spec.whatwg.org/multipage/#dom-canvas-todataurl
|
||||||
fn ToDataURL(&self,
|
unsafe fn ToDataURL(&self,
|
||||||
_context: *mut JSContext,
|
_context: *mut JSContext,
|
||||||
_mime_type: Option<DOMString>,
|
_mime_type: Option<DOMString>,
|
||||||
_arguments: Vec<HandleValue>) -> Fallible<DOMString> {
|
_arguments: Vec<HandleValue>) -> Fallible<DOMString> {
|
||||||
|
|
|
@ -85,8 +85,8 @@ impl ImageDataMethods for ImageData {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
|
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data
|
||||||
fn Data(&self, _: *mut JSContext) -> NonZero<*mut JSObject> {
|
unsafe fn Data(&self, _: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
assert!(!self.data.get().is_null());
|
assert!(!self.data.get().is_null());
|
||||||
unsafe { NonZero::new(self.data.get()) }
|
NonZero::new(self.data.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,8 +95,9 @@ impl MessageEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageEventMethods for MessageEvent {
|
impl MessageEventMethods for MessageEvent {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-messageevent-data
|
// https://html.spec.whatwg.org/multipage/#dom-messageevent-data
|
||||||
fn Data(&self, _cx: *mut JSContext) -> JSVal {
|
unsafe fn Data(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
self.data.get()
|
self.data.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1364,7 +1364,7 @@ impl Node {
|
||||||
pub fn reflect_node<N>(
|
pub fn reflect_node<N>(
|
||||||
node: Box<N>,
|
node: Box<N>,
|
||||||
document: &Document,
|
document: &Document,
|
||||||
wrap_fn: extern "Rust" fn(*mut JSContext, &GlobalScope, Box<N>) -> Root<N>)
|
wrap_fn: unsafe extern "Rust" fn(*mut JSContext, &GlobalScope, Box<N>) -> Root<N>)
|
||||||
-> Root<N>
|
-> Root<N>
|
||||||
where N: DerivedFrom<Node> + Reflectable
|
where N: DerivedFrom<Node> + Reflectable
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,8 +67,9 @@ impl PopStateEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PopStateEventMethods for PopStateEvent {
|
impl PopStateEventMethods for PopStateEvent {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-popstateevent-state
|
// https://html.spec.whatwg.org/multipage/#dom-popstateevent-state
|
||||||
fn State(&self, _cx: *mut JSContext) -> JSVal {
|
unsafe fn State(&self, _cx: *mut JSContext) -> JSVal {
|
||||||
self.state.get()
|
self.state.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,9 @@ impl ServiceWorkerMethods for ServiceWorker {
|
||||||
USVString(self.script_url.borrow().clone())
|
USVString(self.script_url.borrow().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://w3c.github.io/ServiceWorker/#service-worker-postmessage
|
// https://w3c.github.io/ServiceWorker/#service-worker-postmessage
|
||||||
fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
unsafe fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
||||||
// Step 1
|
// Step 1
|
||||||
if let ServiceWorkerState::Redundant = self.state.get() {
|
if let ServiceWorkerState::Redundant = self.state.get() {
|
||||||
return Err(Error::InvalidState);
|
return Err(Error::InvalidState);
|
||||||
|
|
|
@ -110,6 +110,7 @@ impl ServiceWorkerGlobalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
pub fn new(init: WorkerGlobalScopeInit,
|
pub fn new(init: WorkerGlobalScopeInit,
|
||||||
worker_url: Url,
|
worker_url: Url,
|
||||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||||
|
@ -132,8 +133,10 @@ impl ServiceWorkerGlobalScope {
|
||||||
timer_event_port,
|
timer_event_port,
|
||||||
swmanager_sender,
|
swmanager_sender,
|
||||||
scope_url);
|
scope_url);
|
||||||
|
unsafe {
|
||||||
ServiceWorkerGlobalScopeBinding::Wrap(cx, scope)
|
ServiceWorkerGlobalScopeBinding::Wrap(cx, scope)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn run_serviceworker_scope(scope_things: ScopeThings,
|
pub fn run_serviceworker_scope(scope_things: ScopeThings,
|
||||||
|
|
|
@ -149,24 +149,23 @@ impl TestBindingMethods for TestBinding {
|
||||||
}
|
}
|
||||||
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn ArrayAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
unsafe {
|
|
||||||
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
|
||||||
assert!(!array.is_null());
|
assert!(!array.is_null());
|
||||||
NonZero::new(array.get())
|
NonZero::new(array.get())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
|
||||||
fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn ObjectAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
unsafe {
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
rooted!(in(cx) let obj = JS_NewPlainObject(cx));
|
||||||
assert!(!obj.is_null());
|
assert!(!obj.is_null());
|
||||||
NonZero::new(obj.get())
|
NonZero::new(obj.get())
|
||||||
}
|
}
|
||||||
}
|
#[allow(unsafe_code)]
|
||||||
fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
|
|
||||||
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
fn GetBooleanAttributeNullable(&self) -> Option<bool> { Some(false) }
|
||||||
fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
fn SetBooleanAttributeNullable(&self, _: Option<bool>) {}
|
||||||
|
@ -218,8 +217,10 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
|
fn SetInterfaceAttributeWeak(&self, url: Option<&URL>) {
|
||||||
self.url.set(url);
|
self.url.set(url);
|
||||||
}
|
}
|
||||||
fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonZero<*mut JSObject>> { None }
|
#[allow(unsafe_code)]
|
||||||
fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
|
unsafe fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonZero<*mut JSObject>> { None }
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
|
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
|
||||||
Some(HTMLElementOrLong::Long(0))
|
Some(HTMLElementOrLong::Long(0))
|
||||||
}
|
}
|
||||||
|
@ -266,8 +267,10 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveInterface(&self) -> Root<Blob> {
|
fn ReceiveInterface(&self) -> Root<Blob> {
|
||||||
Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned())
|
Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned())
|
||||||
}
|
}
|
||||||
fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
#[allow(unsafe_code)]
|
||||||
fn ReceiveObject(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
unsafe fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> {
|
||||||
self.ObjectAttribute(cx)
|
self.ObjectAttribute(cx)
|
||||||
}
|
}
|
||||||
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) }
|
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) }
|
||||||
|
@ -310,7 +313,8 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> {
|
fn ReceiveNullableInterface(&self) -> Option<Root<Blob>> {
|
||||||
Some(Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned()))
|
Some(Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned()))
|
||||||
}
|
}
|
||||||
fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonZero<*mut JSObject>> {
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonZero<*mut JSObject>> {
|
||||||
self.GetObjectAttributeNullable(cx)
|
self.GetObjectAttributeNullable(cx)
|
||||||
}
|
}
|
||||||
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
|
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {
|
||||||
|
@ -432,8 +436,10 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassUnion8(&self, _: ByteStringSequenceOrLong) {}
|
fn PassUnion8(&self, _: ByteStringSequenceOrLong) {}
|
||||||
fn PassUnionWithTypedef(&self, _: DocumentOrTestTypedef) {}
|
fn PassUnionWithTypedef(&self, _: DocumentOrTestTypedef) {}
|
||||||
fn PassUnionWithTypedef2(&self, _: LongSequenceOrTestTypedef) {}
|
fn PassUnionWithTypedef2(&self, _: LongSequenceOrTestTypedef) {}
|
||||||
fn PassAny(&self, _: *mut JSContext, _: HandleValue) {}
|
#[allow(unsafe_code)]
|
||||||
fn PassObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
unsafe fn PassAny(&self, _: *mut JSContext, _: HandleValue) {}
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
fn PassCallbackFunction(&self, _: Rc<Function>) {}
|
fn PassCallbackFunction(&self, _: Rc<Function>) {}
|
||||||
fn PassCallbackInterface(&self, _: Rc<EventListener>) {}
|
fn PassCallbackInterface(&self, _: Rc<EventListener>) {}
|
||||||
fn PassSequence(&self, _: Vec<i32>) {}
|
fn PassSequence(&self, _: Vec<i32>) {}
|
||||||
|
@ -458,7 +464,8 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassNullableByteString(&self, _: Option<ByteString>) {}
|
fn PassNullableByteString(&self, _: Option<ByteString>) {}
|
||||||
// fn PassNullableEnum(self, _: Option<TestEnum>) {}
|
// fn PassNullableEnum(self, _: Option<TestEnum>) {}
|
||||||
fn PassNullableInterface(&self, _: Option<&Blob>) {}
|
fn PassNullableInterface(&self, _: Option<&Blob>) {}
|
||||||
fn PassNullableObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassNullableObject(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
|
fn PassNullableUnion(&self, _: Option<HTMLElementOrLong>) {}
|
||||||
fn PassNullableUnion2(&self, _: Option<EventOrString>) {}
|
fn PassNullableUnion2(&self, _: Option<EventOrString>) {}
|
||||||
fn PassNullableUnion3(&self, _: Option<StringOrLongSequence>) {}
|
fn PassNullableUnion3(&self, _: Option<StringOrLongSequence>) {}
|
||||||
|
@ -493,8 +500,10 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassOptionalUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
|
fn PassOptionalUnion4(&self, _: Option<LongSequenceOrBoolean>) {}
|
||||||
fn PassOptionalUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
|
fn PassOptionalUnion5(&self, _: Option<UnsignedLongOrBoolean>) {}
|
||||||
fn PassOptionalUnion6(&self, _: Option<ByteStringOrLong>) {}
|
fn PassOptionalUnion6(&self, _: Option<ByteStringOrLong>) {}
|
||||||
fn PassOptionalAny(&self, _: *mut JSContext, _: HandleValue) {}
|
#[allow(unsafe_code)]
|
||||||
fn PassOptionalObject(&self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
unsafe fn PassOptionalAny(&self, _: *mut JSContext, _: HandleValue) {}
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassOptionalObject(&self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
||||||
fn PassOptionalCallbackFunction(&self, _: Option<Rc<Function>>) {}
|
fn PassOptionalCallbackFunction(&self, _: Option<Rc<Function>>) {}
|
||||||
fn PassOptionalCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
|
fn PassOptionalCallbackInterface(&self, _: Option<Rc<EventListener>>) {}
|
||||||
fn PassOptionalSequence(&self, _: Option<Vec<i32>>) {}
|
fn PassOptionalSequence(&self, _: Option<Vec<i32>>) {}
|
||||||
|
@ -517,7 +526,8 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
fn PassOptionalNullableByteString(&self, _: Option<Option<ByteString>>) {}
|
||||||
// fn PassOptionalNullableEnum(self, _: Option<Option<TestEnum>>) {}
|
// fn PassOptionalNullableEnum(self, _: Option<Option<TestEnum>>) {}
|
||||||
fn PassOptionalNullableInterface(&self, _: Option<Option<&Blob>>) {}
|
fn PassOptionalNullableInterface(&self, _: Option<Option<&Blob>>) {}
|
||||||
fn PassOptionalNullableObject(&self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassOptionalNullableObject(&self, _: *mut JSContext, _: Option<*mut JSObject>) {}
|
||||||
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
|
fn PassOptionalNullableUnion(&self, _: Option<Option<HTMLElementOrLong>>) {}
|
||||||
fn PassOptionalNullableUnion2(&self, _: Option<Option<EventOrString>>) {}
|
fn PassOptionalNullableUnion2(&self, _: Option<Option<EventOrString>>) {}
|
||||||
fn PassOptionalNullableUnion3(&self, _: Option<Option<StringOrLongSequence>>) {}
|
fn PassOptionalNullableUnion3(&self, _: Option<Option<StringOrLongSequence>>) {}
|
||||||
|
@ -560,12 +570,14 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassOptionalNullableByteStringWithDefault(&self, _: Option<ByteString>) {}
|
fn PassOptionalNullableByteStringWithDefault(&self, _: Option<ByteString>) {}
|
||||||
// fn PassOptionalNullableEnumWithDefault(self, _: Option<TestEnum>) {}
|
// fn PassOptionalNullableEnumWithDefault(self, _: Option<TestEnum>) {}
|
||||||
fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<&Blob>) {}
|
fn PassOptionalNullableInterfaceWithDefault(&self, _: Option<&Blob>) {}
|
||||||
fn PassOptionalNullableObjectWithDefault(&self, _: *mut JSContext, _: *mut JSObject) {}
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassOptionalNullableObjectWithDefault(&self, _: *mut JSContext, _: *mut JSObject) {}
|
||||||
fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
|
fn PassOptionalNullableUnionWithDefault(&self, _: Option<HTMLElementOrLong>) {}
|
||||||
fn PassOptionalNullableUnion2WithDefault(&self, _: Option<EventOrString>) {}
|
fn PassOptionalNullableUnion2WithDefault(&self, _: Option<EventOrString>) {}
|
||||||
// fn PassOptionalNullableCallbackFunctionWithDefault(self, _: Option<Function>) {}
|
// fn PassOptionalNullableCallbackFunctionWithDefault(self, _: Option<Function>) {}
|
||||||
fn PassOptionalNullableCallbackInterfaceWithDefault(&self, _: Option<Rc<EventListener>>) {}
|
fn PassOptionalNullableCallbackInterfaceWithDefault(&self, _: Option<Rc<EventListener>>) {}
|
||||||
fn PassOptionalAnyWithDefault(&self, _: *mut JSContext, _: HandleValue) {}
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassOptionalAnyWithDefault(&self, _: *mut JSContext, _: HandleValue) {}
|
||||||
|
|
||||||
fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
fn PassOptionalNullableBooleanWithNonNullDefault(&self, _: Option<bool>) {}
|
||||||
fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
fn PassOptionalNullableByteWithNonNullDefault(&self, _: Option<i8>) {}
|
||||||
|
@ -610,8 +622,10 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn PassVariadicUnion5(&self, _: Vec<StringOrUnsignedLong>) {}
|
fn PassVariadicUnion5(&self, _: Vec<StringOrUnsignedLong>) {}
|
||||||
fn PassVariadicUnion6(&self, _: Vec<UnsignedLongOrBoolean>) {}
|
fn PassVariadicUnion6(&self, _: Vec<UnsignedLongOrBoolean>) {}
|
||||||
fn PassVariadicUnion7(&self, _: Vec<ByteStringOrLong>) {}
|
fn PassVariadicUnion7(&self, _: Vec<ByteStringOrLong>) {}
|
||||||
fn PassVariadicAny(&self, _: *mut JSContext, _: Vec<HandleValue>) {}
|
#[allow(unsafe_code)]
|
||||||
fn PassVariadicObject(&self, _: *mut JSContext, _: Vec<*mut JSObject>) {}
|
unsafe fn PassVariadicAny(&self, _: *mut JSContext, _: Vec<HandleValue>) {}
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PassVariadicObject(&self, _: *mut JSContext, _: Vec<*mut JSObject>) {}
|
||||||
fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
|
fn BooleanMozPreference(&self, pref_name: DOMString) -> bool {
|
||||||
PREFS.get(pref_name.as_ref()).as_boolean().unwrap_or(false)
|
PREFS.get(pref_name.as_ref()).as_boolean().unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
@ -654,20 +668,24 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveAnyMozMap(&self) -> MozMap<JSVal> { MozMap::new() }
|
fn ReceiveAnyMozMap(&self) -> MozMap<JSVal> { MozMap::new() }
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
fn ReturnResolvedPromise(&self, cx: *mut JSContext, v: HandleValue) -> Fallible<Rc<Promise>> {
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn ReturnResolvedPromise(&self, cx: *mut JSContext, v: HandleValue) -> Fallible<Rc<Promise>> {
|
||||||
Promise::Resolve(&self.global(), cx, v)
|
Promise::Resolve(&self.global(), cx, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
fn ReturnRejectedPromise(&self, cx: *mut JSContext, v: HandleValue) -> Fallible<Rc<Promise>> {
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn ReturnRejectedPromise(&self, cx: *mut JSContext, v: HandleValue) -> Fallible<Rc<Promise>> {
|
||||||
Promise::Reject(&self.global(), cx, v)
|
Promise::Reject(&self.global(), cx, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn PromiseResolveNative(&self, cx: *mut JSContext, p: &Promise, v: HandleValue) {
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PromiseResolveNative(&self, cx: *mut JSContext, p: &Promise, v: HandleValue) {
|
||||||
p.resolve(cx, v);
|
p.resolve(cx, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn PromiseRejectNative(&self, cx: *mut JSContext, p: &Promise, v: HandleValue) {
|
#[allow(unsafe_code)]
|
||||||
|
unsafe fn PromiseRejectNative(&self, cx: *mut JSContext, p: &Promise, v: HandleValue) {
|
||||||
p.reject(cx, v);
|
p.reject(cx, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,14 +78,14 @@ impl TextDecoderMethods for TextDecoder {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
|
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
|
||||||
fn Decode(&self, _cx: *mut JSContext, input: Option<*mut JSObject>)
|
unsafe fn Decode(&self, _cx: *mut JSContext, input: Option<*mut JSObject>)
|
||||||
-> Fallible<USVString> {
|
-> Fallible<USVString> {
|
||||||
let input = match input {
|
let input = match input {
|
||||||
Some(input) => input,
|
Some(input) => input,
|
||||||
None => return Ok(USVString("".to_owned())),
|
None => return Ok(USVString("".to_owned())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = match unsafe { array_buffer_view_data::<u8>(input) } {
|
let data = match array_buffer_view_data::<u8>(input) {
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::Type("Argument to TextDecoder.decode is not an ArrayBufferView".to_owned()));
|
return Err(Error::Type("Argument to TextDecoder.decode is not an ArrayBufferView".to_owned()));
|
||||||
|
|
|
@ -50,8 +50,7 @@ impl TextEncoderMethods for TextEncoder {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
|
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
|
||||||
fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonZero<*mut JSObject> {
|
unsafe fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonZero<*mut JSObject> {
|
||||||
unsafe {
|
|
||||||
let encoded = UTF_8.encode(&input.0, EncoderTrap::Strict).unwrap();
|
let encoded = UTF_8.encode(&input.0, EncoderTrap::Strict).unwrap();
|
||||||
let length = encoded.len() as u32;
|
let length = encoded.len() as u32;
|
||||||
rooted!(in(cx) let js_object = JS_NewUint8Array(cx, length));
|
rooted!(in(cx) let js_object = JS_NewUint8Array(cx, length));
|
||||||
|
@ -63,4 +62,3 @@ impl TextEncoderMethods for TextEncoder {
|
||||||
NonZero::new(js_object.get())
|
NonZero::new(js_object.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -94,10 +94,8 @@ macro_rules! object_binding_to_js_or_null {
|
||||||
{
|
{
|
||||||
rooted!(in($cx) let mut rval = NullValue());
|
rooted!(in($cx) let mut rval = NullValue());
|
||||||
if let Some(bound_object) = $binding.get() {
|
if let Some(bound_object) = $binding.get() {
|
||||||
unsafe {
|
|
||||||
bound_object.to_jsval($cx, rval.handle_mut());
|
bound_object.to_jsval($cx, rval.handle_mut());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
rval.get()
|
rval.get()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -624,8 +622,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
receiver.recv().unwrap()
|
receiver.recv().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
|
||||||
fn GetBufferParameter(&self, _cx: *mut JSContext, target: u32, parameter: u32) -> JSVal {
|
unsafe fn GetBufferParameter(&self, _cx: *mut JSContext, target: u32, parameter: u32) -> JSVal {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
.send(CanvasMsg::WebGL(WebGLCommand::GetBufferParameter(target, parameter, sender)))
|
.send(CanvasMsg::WebGL(WebGLCommand::GetBufferParameter(target, parameter, sender)))
|
||||||
|
@ -642,7 +641,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
||||||
fn GetParameter(&self, cx: *mut JSContext, parameter: u32) -> JSVal {
|
unsafe fn GetParameter(&self, cx: *mut JSContext, parameter: u32) -> JSVal {
|
||||||
// Handle the GL_*_BINDING without going all the way
|
// Handle the GL_*_BINDING without going all the way
|
||||||
// to the GL, since we would just need to map back from GL's
|
// to the GL, since we would just need to map back from GL's
|
||||||
// returned ID to the WebGL* object we're tracking.
|
// returned ID to the WebGL* object we're tracking.
|
||||||
|
@ -693,9 +692,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
WebGLParameter::FloatArray(_) => panic!("Parameter should not be float array"),
|
WebGLParameter::FloatArray(_) => panic!("Parameter should not be float array"),
|
||||||
WebGLParameter::String(val) => {
|
WebGLParameter::String(val) => {
|
||||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||||
unsafe {
|
|
||||||
val.to_jsval(cx, rval.handle_mut());
|
val.to_jsval(cx, rval.handle_mut());
|
||||||
}
|
|
||||||
rval.get()
|
rval.get()
|
||||||
}
|
}
|
||||||
WebGLParameter::Invalid => NullValue(),
|
WebGLParameter::Invalid => NullValue(),
|
||||||
|
@ -748,8 +745,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
Some(vec![])
|
Some(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
|
||||||
fn GetExtension(&self, _cx: *mut JSContext, _name: DOMString)
|
unsafe fn GetExtension(&self, _cx: *mut JSContext, _name: DOMString)
|
||||||
-> Option<NonZero<*mut JSObject>> {
|
-> Option<NonZero<*mut JSObject>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -927,17 +925,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
|
||||||
fn BufferData(&self, _cx: *mut JSContext, target: u32, data: *mut JSObject, usage: u32) -> Fallible<()> {
|
unsafe fn BufferData(&self, _cx: *mut JSContext, target: u32, data: *mut JSObject, usage: u32) -> Fallible<()> {
|
||||||
if data.is_null() {
|
if data.is_null() {
|
||||||
return Ok(self.webgl_error(InvalidValue));
|
return Ok(self.webgl_error(InvalidValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
let data_vec = unsafe {
|
let data_vec = match array_buffer_to_vec::<u8>(data) {
|
||||||
match array_buffer_to_vec::<u8>(data) {
|
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
// Not an ArrayBuffer object, maybe an ArrayBufferView?
|
// Not an ArrayBuffer object, maybe an ArrayBufferView?
|
||||||
None => try!(fallible_array_buffer_view_to_vec::<u8>(data)),
|
None => try!(fallible_array_buffer_view_to_vec::<u8>(data)),
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let bound_buffer = match target {
|
let bound_buffer = match target {
|
||||||
|
@ -965,17 +961,15 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.5
|
||||||
fn BufferSubData(&self, _cx: *mut JSContext, target: u32, offset: i64, data: *mut JSObject) -> Fallible<()> {
|
unsafe fn BufferSubData(&self, _cx: *mut JSContext, target: u32, offset: i64, data: *mut JSObject) -> Fallible<()> {
|
||||||
if data.is_null() {
|
if data.is_null() {
|
||||||
return Ok(self.webgl_error(InvalidValue));
|
return Ok(self.webgl_error(InvalidValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
let data_vec = unsafe {
|
let data_vec = match array_buffer_to_vec::<u8>(data) {
|
||||||
match array_buffer_to_vec::<u8>(data) {
|
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
// Not an ArrayBuffer object, maybe an ArrayBufferView?
|
// Not an ArrayBuffer object, maybe an ArrayBufferView?
|
||||||
None => try!(fallible_array_buffer_view_to_vec::<u8>(data)),
|
None => try!(fallible_array_buffer_view_to_vec::<u8>(data)),
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let bound_buffer = match target {
|
let bound_buffer = match target {
|
||||||
|
@ -1005,9 +999,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
||||||
fn CompressedTexImage2D(&self, _cx: *mut JSContext, _target: u32, _level: i32, _internal_format: u32,
|
unsafe fn CompressedTexImage2D(&self, _cx: *mut JSContext, _target: u32, _level: i32, _internal_format: u32,
|
||||||
_width: i32, _height: i32, _border: i32, pixels: *mut JSObject) -> Fallible<()> {
|
_width: i32, _height: i32, _border: i32, pixels: *mut JSObject) -> Fallible<()> {
|
||||||
let _data = try!(unsafe { fallible_array_buffer_view_to_vec::<u8>(pixels) });
|
let _data = try!(fallible_array_buffer_view_to_vec::<u8>(pixels) );
|
||||||
// FIXME: No compressed texture format is currently supported, so error out as per
|
// FIXME: No compressed texture format is currently supported, so error out as per
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT
|
||||||
self.webgl_error(InvalidEnum);
|
self.webgl_error(InvalidEnum);
|
||||||
|
@ -1016,10 +1010,10 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
||||||
fn CompressedTexSubImage2D(&self, _cx: *mut JSContext, _target: u32, _level: i32,
|
unsafe fn CompressedTexSubImage2D(&self, _cx: *mut JSContext, _target: u32, _level: i32,
|
||||||
_xoffset: i32, _yoffset: i32, _width: i32, _height: i32,
|
_xoffset: i32, _yoffset: i32, _width: i32, _height: i32,
|
||||||
_format: u32, pixels: *mut JSObject) -> Fallible<()> {
|
_format: u32, pixels: *mut JSObject) -> Fallible<()> {
|
||||||
let _data = try!(unsafe { fallible_array_buffer_view_to_vec::<u8>(pixels) });
|
let _data = try!(fallible_array_buffer_view_to_vec::<u8>(pixels));
|
||||||
// FIXME: No compressed texture format is currently supported, so error out as per
|
// FIXME: No compressed texture format is currently supported, so error out as per
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#COMPRESSED_TEXTURE_SUPPORT
|
||||||
self.webgl_error(InvalidEnum);
|
self.webgl_error(InvalidEnum);
|
||||||
|
@ -1568,8 +1562,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
||||||
fn GetProgramParameter(&self, _: *mut JSContext, program: Option<&WebGLProgram>, param_id: u32) -> JSVal {
|
unsafe fn GetProgramParameter(&self, _: *mut JSContext, program: Option<&WebGLProgram>, param_id: u32) -> JSVal {
|
||||||
if let Some(program) = program {
|
if let Some(program) = program {
|
||||||
match handle_potential_webgl_error!(self, program.parameter(param_id), WebGLParameter::Invalid) {
|
match handle_potential_webgl_error!(self, program.parameter(param_id), WebGLParameter::Invalid) {
|
||||||
WebGLParameter::Int(val) => Int32Value(val),
|
WebGLParameter::Int(val) => Int32Value(val),
|
||||||
|
@ -1591,8 +1586,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
shader.and_then(|s| s.info_log()).map(DOMString::from)
|
shader.and_then(|s| s.info_log()).map(DOMString::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
||||||
fn GetShaderParameter(&self, _: *mut JSContext, shader: Option<&WebGLShader>, param_id: u32) -> JSVal {
|
unsafe fn GetShaderParameter(&self, _: *mut JSContext, shader: Option<&WebGLShader>, param_id: u32) -> JSVal {
|
||||||
if let Some(shader) = shader {
|
if let Some(shader) = shader {
|
||||||
match handle_potential_webgl_error!(self, shader.parameter(param_id), WebGLParameter::Invalid) {
|
match handle_potential_webgl_error!(self, shader.parameter(param_id), WebGLParameter::Invalid) {
|
||||||
WebGLParameter::Int(val) => Int32Value(val),
|
WebGLParameter::Int(val) => Int32Value(val),
|
||||||
|
@ -1621,14 +1617,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
|
||||||
fn GetVertexAttrib(&self, cx: *mut JSContext, index: u32, pname: u32) -> JSVal {
|
unsafe fn GetVertexAttrib(&self, cx: *mut JSContext, index: u32, pname: u32) -> JSVal {
|
||||||
if index == 0 && pname == constants::CURRENT_VERTEX_ATTRIB {
|
if index == 0 && pname == constants::CURRENT_VERTEX_ATTRIB {
|
||||||
rooted!(in(cx) let mut result = UndefinedValue());
|
rooted!(in(cx) let mut result = UndefinedValue());
|
||||||
let (x, y, z, w) = self.current_vertex_attrib_0.get();
|
let (x, y, z, w) = self.current_vertex_attrib_0.get();
|
||||||
let attrib = vec![x, y, z, w];
|
let attrib = vec![x, y, z, w];
|
||||||
unsafe {
|
|
||||||
attrib.to_jsval(cx, result.handle_mut());
|
attrib.to_jsval(cx, result.handle_mut());
|
||||||
}
|
|
||||||
return result.get()
|
return result.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1642,9 +1636,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
WebGLParameter::Float(_) => panic!("Vertex attrib should not be float"),
|
WebGLParameter::Float(_) => panic!("Vertex attrib should not be float"),
|
||||||
WebGLParameter::FloatArray(val) => {
|
WebGLParameter::FloatArray(val) => {
|
||||||
rooted!(in(cx) let mut result = UndefinedValue());
|
rooted!(in(cx) let mut result = UndefinedValue());
|
||||||
unsafe {
|
|
||||||
val.to_jsval(cx, result.handle_mut());
|
val.to_jsval(cx, result.handle_mut());
|
||||||
}
|
|
||||||
result.get()
|
result.get()
|
||||||
}
|
}
|
||||||
WebGLParameter::Invalid => NullValue(),
|
WebGLParameter::Invalid => NullValue(),
|
||||||
|
@ -1787,13 +1779,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.12
|
||||||
fn ReadPixels(&self, _cx: *mut JSContext, x: i32, y: i32, width: i32, height: i32,
|
unsafe fn ReadPixels(&self, _cx: *mut JSContext, x: i32, y: i32, width: i32, height: i32,
|
||||||
format: u32, pixel_type: u32, pixels: *mut JSObject) -> Fallible<()> {
|
format: u32, pixel_type: u32, pixels: *mut JSObject) -> Fallible<()> {
|
||||||
if pixels.is_null() {
|
if pixels.is_null() {
|
||||||
return Ok(self.webgl_error(InvalidValue));
|
return Ok(self.webgl_error(InvalidValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut data = match unsafe { array_buffer_view_data::<u8>(pixels) } {
|
let mut data = match { array_buffer_view_data::<u8>(pixels) } {
|
||||||
Some(data) => data,
|
Some(data) => data,
|
||||||
None => return Err(Error::Type("Not an ArrayBufferView".to_owned())),
|
None => return Err(Error::Type("Not an ArrayBufferView".to_owned())),
|
||||||
};
|
};
|
||||||
|
@ -1802,7 +1794,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
match unsafe { JS_GetArrayBufferViewType(pixels) } {
|
match { JS_GetArrayBufferViewType(pixels) } {
|
||||||
Type::Uint8 => (),
|
Type::Uint8 => (),
|
||||||
_ => return Ok(self.webgl_error(InvalidOperation)),
|
_ => return Ok(self.webgl_error(InvalidOperation)),
|
||||||
}
|
}
|
||||||
|
@ -2035,12 +2027,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform1iv(&self,
|
unsafe fn Uniform1iv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform, UniformSetterType::Int, &data_vec) {
|
if self.validate_uniform_parameters(uniform, UniformSetterType::Int, &data_vec) {
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
|
@ -2053,12 +2045,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform1fv(&self,
|
unsafe fn Uniform1fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform, UniformSetterType::Float, &data_vec) {
|
if self.validate_uniform_parameters(uniform, UniformSetterType::Float, &data_vec) {
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
|
@ -2082,12 +2074,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform2fv(&self,
|
unsafe fn Uniform2fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::FloatVec2,
|
UniformSetterType::FloatVec2,
|
||||||
|
@ -2115,12 +2107,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform2iv(&self,
|
unsafe fn Uniform2iv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::IntVec2,
|
UniformSetterType::IntVec2,
|
||||||
|
@ -2148,12 +2140,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform3fv(&self,
|
unsafe fn Uniform3fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::FloatVec3,
|
UniformSetterType::FloatVec3,
|
||||||
|
@ -2181,12 +2173,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform3iv(&self,
|
unsafe fn Uniform3iv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::IntVec3,
|
UniformSetterType::IntVec3,
|
||||||
|
@ -2215,12 +2207,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform4iv(&self,
|
unsafe fn Uniform4iv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<i32>(cx, data, ConversionBehavior::Default));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::IntVec4,
|
UniformSetterType::IntVec4,
|
||||||
|
@ -2248,12 +2240,12 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn Uniform4fv(&self,
|
unsafe fn Uniform4fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
|
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::FloatVec4,
|
UniformSetterType::FloatVec4,
|
||||||
|
@ -2268,13 +2260,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn UniformMatrix2fv(&self,
|
unsafe fn UniformMatrix2fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
transpose: bool,
|
transpose: bool,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::FloatMat2,
|
UniformSetterType::FloatMat2,
|
||||||
&data_vec) {
|
&data_vec) {
|
||||||
|
@ -2288,13 +2280,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn UniformMatrix3fv(&self,
|
unsafe fn UniformMatrix3fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
transpose: bool,
|
transpose: bool,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::FloatMat3,
|
UniformSetterType::FloatMat3,
|
||||||
&data_vec) {
|
&data_vec) {
|
||||||
|
@ -2308,13 +2300,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn UniformMatrix4fv(&self,
|
unsafe fn UniformMatrix4fv(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
uniform: Option<&WebGLUniformLocation>,
|
uniform: Option<&WebGLUniformLocation>,
|
||||||
transpose: bool,
|
transpose: bool,
|
||||||
data: *mut JSObject) -> Fallible<()> {
|
data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if self.validate_uniform_parameters(uniform,
|
if self.validate_uniform_parameters(uniform,
|
||||||
UniformSetterType::FloatMat4,
|
UniformSetterType::FloatMat4,
|
||||||
&data_vec) {
|
&data_vec) {
|
||||||
|
@ -2352,9 +2344,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn VertexAttrib1fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
unsafe fn VertexAttrib1fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if data_vec.len() < 1 {
|
if data_vec.len() < 1 {
|
||||||
return Ok(self.webgl_error(InvalidOperation));
|
return Ok(self.webgl_error(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
@ -2369,9 +2361,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn VertexAttrib2fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
unsafe fn VertexAttrib2fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if data_vec.len() < 2 {
|
if data_vec.len() < 2 {
|
||||||
return Ok(self.webgl_error(InvalidOperation));
|
return Ok(self.webgl_error(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
@ -2386,9 +2378,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn VertexAttrib3fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
unsafe fn VertexAttrib3fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if data_vec.len() < 3 {
|
if data_vec.len() < 3 {
|
||||||
return Ok(self.webgl_error(InvalidOperation));
|
return Ok(self.webgl_error(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
@ -2403,9 +2395,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.10
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn VertexAttrib4fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
unsafe fn VertexAttrib4fv(&self, cx: *mut JSContext, indx: u32, data: *mut JSObject) -> Fallible<()> {
|
||||||
assert!(!data.is_null());
|
assert!(!data.is_null());
|
||||||
let data_vec = try!(unsafe { typed_array_or_sequence_to_vec::<f32>(cx, data, ()) });
|
let data_vec = try!(typed_array_or_sequence_to_vec::<f32>(cx, data, ()));
|
||||||
if data_vec.len() < 4 {
|
if data_vec.len() < 4 {
|
||||||
return Ok(self.webgl_error(InvalidOperation));
|
return Ok(self.webgl_error(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
@ -2468,7 +2460,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn TexImage2D(&self,
|
unsafe fn TexImage2D(&self,
|
||||||
_cx: *mut JSContext,
|
_cx: *mut JSContext,
|
||||||
target: u32,
|
target: u32,
|
||||||
level: i32,
|
level: i32,
|
||||||
|
@ -2482,7 +2474,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
let data = if data_ptr.is_null() {
|
let data = if data_ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(try!(unsafe { fallible_array_buffer_view_to_vec::<u8>(data_ptr) }))
|
Some(try!(fallible_array_buffer_view_to_vec::<u8>(data_ptr)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let validator = TexImage2DValidator::new(self, target, level,
|
let validator = TexImage2DValidator::new(self, target, level,
|
||||||
|
@ -2504,7 +2496,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_byte_length =
|
let expected_byte_length =
|
||||||
match unsafe { self.validate_tex_image_2d_data(width, height,
|
match { self.validate_tex_image_2d_data(width, height,
|
||||||
format, data_type,
|
format, data_type,
|
||||||
data_ptr) } {
|
data_ptr) } {
|
||||||
Ok(byte_length) => byte_length,
|
Ok(byte_length) => byte_length,
|
||||||
|
@ -2574,7 +2566,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn TexSubImage2D(&self,
|
unsafe fn TexSubImage2D(&self,
|
||||||
_cx: *mut JSContext,
|
_cx: *mut JSContext,
|
||||||
target: u32,
|
target: u32,
|
||||||
level: i32,
|
level: i32,
|
||||||
|
@ -2588,7 +2580,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
let data = if data_ptr.is_null() {
|
let data = if data_ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(try!(unsafe { fallible_array_buffer_view_to_vec::<u8>(data_ptr) }))
|
Some(try!(fallible_array_buffer_view_to_vec::<u8>(data_ptr)))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2610,7 +2602,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_byte_length =
|
let expected_byte_length =
|
||||||
match unsafe { self.validate_tex_image_2d_data(width, height,
|
match { self.validate_tex_image_2d_data(width, height,
|
||||||
format, data_type,
|
format, data_type,
|
||||||
data_ptr) } {
|
data_ptr) } {
|
||||||
Ok(byte_length) => byte_length,
|
Ok(byte_length) => byte_length,
|
||||||
|
|
|
@ -483,8 +483,10 @@ impl WindowMethods for Window {
|
||||||
self.navigator.or_init(|| Navigator::new(self))
|
self.navigator.or_init(|| Navigator::new(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
||||||
fn SetTimeout(&self, _cx: *mut JSContext, callback: Rc<Function>, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetTimeout(&self, _cx: *mut JSContext, callback: Rc<Function>, timeout: i32,
|
||||||
|
args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::FunctionTimerCallback(callback),
|
TimerCallback::FunctionTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -492,8 +494,10 @@ impl WindowMethods for Window {
|
||||||
IsInterval::NonInterval)
|
IsInterval::NonInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
||||||
fn SetTimeout_(&self, _cx: *mut JSContext, callback: DOMString, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetTimeout_(&self, _cx: *mut JSContext, callback: DOMString,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::StringTimerCallback(callback),
|
TimerCallback::StringTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -506,8 +510,10 @@ impl WindowMethods for Window {
|
||||||
self.upcast::<GlobalScope>().clear_timeout_or_interval(handle);
|
self.upcast::<GlobalScope>().clear_timeout_or_interval(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
||||||
fn SetInterval(&self, _cx: *mut JSContext, callback: Rc<Function>, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetInterval(&self, _cx: *mut JSContext, callback: Rc<Function>,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::FunctionTimerCallback(callback),
|
TimerCallback::FunctionTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -515,8 +521,10 @@ impl WindowMethods for Window {
|
||||||
IsInterval::Interval)
|
IsInterval::Interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
||||||
fn SetInterval_(&self, _cx: *mut JSContext, callback: DOMString, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetInterval_(&self, _cx: *mut JSContext, callback: DOMString,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::StringTimerCallback(callback),
|
TimerCallback::StringTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -610,8 +618,9 @@ impl WindowMethods for Window {
|
||||||
doc.cancel_animation_frame(ident);
|
doc.cancel_animation_frame(ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-window-postmessage
|
// https://html.spec.whatwg.org/multipage/#dom-window-postmessage
|
||||||
fn PostMessage(&self,
|
unsafe fn PostMessage(&self,
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
message: HandleValue,
|
message: HandleValue,
|
||||||
origin: DOMString)
|
origin: DOMString)
|
||||||
|
@ -670,8 +679,8 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn WebdriverCallback(&self, cx: *mut JSContext, val: HandleValue) {
|
unsafe fn WebdriverCallback(&self, cx: *mut JSContext, val: HandleValue) {
|
||||||
let rv = unsafe { jsval_to_webdriver(cx, val) };
|
let rv = jsval_to_webdriver(cx, val);
|
||||||
let opt_chan = self.webdriver_script_chan.borrow_mut().take();
|
let opt_chan = self.webdriver_script_chan.borrow_mut().take();
|
||||||
if let Some(chan) = opt_chan {
|
if let Some(chan) = opt_chan {
|
||||||
chan.send(rv).unwrap();
|
chan.send(rv).unwrap();
|
||||||
|
@ -1511,6 +1520,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
pub fn new(runtime: Rc<Runtime>,
|
pub fn new(runtime: Rc<Runtime>,
|
||||||
script_chan: MainThreadScriptChan,
|
script_chan: MainThreadScriptChan,
|
||||||
dom_task_source: DOMManipulationTaskSource,
|
dom_task_source: DOMManipulationTaskSource,
|
||||||
|
@ -1598,9 +1608,11 @@ impl Window {
|
||||||
test_runner: Default::default(),
|
test_runner: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
WindowBinding::Wrap(runtime.cx(), win)
|
WindowBinding::Wrap(runtime.cx(), win)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
|
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
|
||||||
let clip_rect = Rect::new(Point2D::new(clip_rect.origin.x.to_f32_px(),
|
let clip_rect = Rect::new(Point2D::new(clip_rect.origin.x.to_f32_px(),
|
||||||
|
|
|
@ -164,8 +164,9 @@ impl Worker {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkerMethods for Worker {
|
impl WorkerMethods for Worker {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-worker-postmessage
|
// https://html.spec.whatwg.org/multipage/#dom-worker-postmessage
|
||||||
fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
unsafe fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
|
||||||
let data = try!(StructuredCloneData::write(cx, message));
|
let data = try!(StructuredCloneData::write(cx, message));
|
||||||
let address = Trusted::new(self);
|
let address = Trusted::new(self);
|
||||||
|
|
||||||
|
|
|
@ -268,8 +268,10 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||||
base64_atob(atob)
|
base64_atob(atob)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
||||||
fn SetTimeout(&self, _cx: *mut JSContext, callback: Rc<Function>, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetTimeout(&self, _cx: *mut JSContext, callback: Rc<Function>,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::FunctionTimerCallback(callback),
|
TimerCallback::FunctionTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -277,8 +279,10 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||||
IsInterval::NonInterval)
|
IsInterval::NonInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-settimeout
|
||||||
fn SetTimeout_(&self, _cx: *mut JSContext, callback: DOMString, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetTimeout_(&self, _cx: *mut JSContext, callback: DOMString,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::StringTimerCallback(callback),
|
TimerCallback::StringTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -291,8 +295,10 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||||
self.upcast::<GlobalScope>().clear_timeout_or_interval(handle);
|
self.upcast::<GlobalScope>().clear_timeout_or_interval(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
||||||
fn SetInterval(&self, _cx: *mut JSContext, callback: Rc<Function>, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetInterval(&self, _cx: *mut JSContext, callback: Rc<Function>,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::FunctionTimerCallback(callback),
|
TimerCallback::FunctionTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
@ -300,8 +306,10 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||||
IsInterval::Interval)
|
IsInterval::Interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
// https://html.spec.whatwg.org/multipage/#dom-windowtimers-setinterval
|
||||||
fn SetInterval_(&self, _cx: *mut JSContext, callback: DOMString, timeout: i32, args: Vec<HandleValue>) -> i32 {
|
unsafe fn SetInterval_(&self, _cx: *mut JSContext, callback: DOMString,
|
||||||
|
timeout: i32, args: Vec<HandleValue>) -> i32 {
|
||||||
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
self.upcast::<GlobalScope>().set_timeout_or_interval(
|
||||||
TimerCallback::StringTimerCallback(callback),
|
TimerCallback::StringTimerCallback(callback),
|
||||||
args,
|
args,
|
||||||
|
|
|
@ -86,8 +86,9 @@ impl XMLDocumentMethods for XMLDocument {
|
||||||
self.upcast::<Document>().SupportedPropertyNames()
|
self.upcast::<Document>().SupportedPropertyNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
||||||
fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
||||||
self.upcast::<Document>().NamedGetter(_cx, name)
|
self.upcast::<Document>().NamedGetter(_cx, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -761,8 +761,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://xhr.spec.whatwg.org/#the-response-attribute
|
// https://xhr.spec.whatwg.org/#the-response-attribute
|
||||||
fn Response(&self, cx: *mut JSContext) -> JSVal {
|
unsafe fn Response(&self, cx: *mut JSContext) -> JSVal {
|
||||||
unsafe {
|
|
||||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||||
match self.response_type.get() {
|
match self.response_type.get() {
|
||||||
XMLHttpRequestResponseType::_empty | XMLHttpRequestResponseType::Text => {
|
XMLHttpRequestResponseType::_empty | XMLHttpRequestResponseType::Text => {
|
||||||
|
@ -802,7 +801,6 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
}
|
}
|
||||||
rval.get()
|
rval.get()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// https://xhr.spec.whatwg.org/#the-responsetext-attribute
|
// https://xhr.spec.whatwg.org/#the-responsetext-attribute
|
||||||
fn GetResponseText(&self) -> Fallible<USVString> {
|
fn GetResponseText(&self) -> Fallible<USVString> {
|
||||||
|
|
|
@ -173,11 +173,11 @@ pub fn init_service_workers(sw_senders: SWManagerSenders) {
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
unsafe {
|
unsafe {
|
||||||
proxyhandler::init();
|
proxyhandler::init();
|
||||||
}
|
|
||||||
|
|
||||||
// Create the global vtables used by the (generated) DOM
|
// Create the global vtables used by the (generated) DOM
|
||||||
// bindings to implement JS proxies.
|
// bindings to implement JS proxies.
|
||||||
RegisterBindings::RegisterProxyHandlers();
|
RegisterBindings::RegisterProxyHandlers();
|
||||||
|
}
|
||||||
|
|
||||||
perform_platform_specific_initialization();
|
perform_platform_specific_initialization();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue