Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Impl ReadableStream support #25827

Closed
wants to merge 9 commits into from
Next

start impl readablestream

  • Loading branch information
gterzian committed Feb 22, 2020
commit 40f9620aad721a52dc2f788c6e18fafb67944863
@@ -2164,9 +2164,6 @@ def isSequence(self):
def isRecord(self):
return False

def isReadableStream(self):
return False

def isArrayBuffer(self):
return False

@@ -2198,8 +2195,7 @@ def isSpiderMonkeyInterface(self):
return self.isInterface() and (self.isArrayBuffer() or
self.isArrayBufferView() or
self.isSharedArrayBuffer() or
self.isTypedArray() or
self.isReadableStream())
self.isTypedArray())

def isDictionary(self):
return False
@@ -2401,9 +2397,6 @@ def isSequence(self):
def isRecord(self):
return self.inner.isRecord()

def isReadableStream(self):
return self.inner.isReadableStream()

def isArrayBuffer(self):
return self.inner.isArrayBuffer()

@@ -2783,9 +2776,6 @@ def isSequence(self):
def isRecord(self):
return self.inner.isRecord()

def isReadableStream(self):
return self.inner.isReadableStream()

def isDictionary(self):
return self.inner.isDictionary()

@@ -3121,7 +3111,6 @@ class IDLBuiltinType(IDLType):
'Uint32Array',
'Float32Array',
'Float64Array',
'ReadableStream',
)

TagLookup = {
@@ -3158,7 +3147,6 @@ class IDLBuiltinType(IDLType):
Types.Uint32Array: IDLType.Tags.interface,
Types.Float32Array: IDLType.Tags.interface,
Types.Float64Array: IDLType.Tags.interface,
Types.ReadableStream: IDLType.Tags.interface,
}

def __init__(self, location, name, type, clamp=False, enforceRange=False, treatNullAsEmpty=False,
@@ -3258,18 +3246,14 @@ def isTypedArray(self):
return (self._typeTag >= IDLBuiltinType.Types.Int8Array and
self._typeTag <= IDLBuiltinType.Types.Float64Array)

def isReadableStream(self):
return self._typeTag == IDLBuiltinType.Types.ReadableStream

def isInterface(self):
# TypedArray things are interface types per the TypedArray spec,
# but we handle them as builtins because SpiderMonkey implements
# all of it internally.
return (self.isArrayBuffer() or
self.isArrayBufferView() or
self.isSharedArrayBuffer() or
self.isTypedArray() or
self.isReadableStream())
self.isTypedArray())

def isNonCallbackInterface(self):
# All the interfaces we can be are non-callback
@@ -3339,7 +3323,6 @@ def isDistinguishableFrom(self, other):
# that's not an ArrayBuffer or a callback interface
(self.isArrayBuffer() and not other.isArrayBuffer()) or
(self.isSharedArrayBuffer() and not other.isSharedArrayBuffer()) or
(self.isReadableStream() and not other.isReadableStream()) or
# ArrayBufferView is distinguishable from everything
# that's not an ArrayBufferView or typed array.
(self.isArrayBufferView() and not other.isArrayBufferView() and
@@ -3492,9 +3475,6 @@ def withExtendedAttributes(self, attrs):
IDLBuiltinType.Types.Float64Array:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Float64Array",
IDLBuiltinType.Types.Float64Array),
IDLBuiltinType.Types.ReadableStream:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "ReadableStream",
IDLBuiltinType.Types.ReadableStream),
}


@@ -5715,7 +5695,6 @@ def t_OTHER(self, t):
"setlike": "SETLIKE",
"iterable": "ITERABLE",
"namespace": "NAMESPACE",
"ReadableStream": "READABLESTREAM",
"constructor": "CONSTRUCTOR",
"symbol": "SYMBOL",
"async": "ASYNC",
@@ -7051,7 +7030,6 @@ def p_DistinguishableType(self, p):
DistinguishableType : PrimitiveType Null
| ARRAYBUFFER Null
| SHAREDARRAYBUFFER Null
| READABLESTREAM Null
| OBJECT Null
"""
if p[1] == "object":
@@ -7060,8 +7038,6 @@ def p_DistinguishableType(self, p):
type = BuiltinTypes[IDLBuiltinType.Types.ArrayBuffer]
elif p[1] == "SharedArrayBuffer":
type = BuiltinTypes[IDLBuiltinType.Types.SharedArrayBuffer]
elif p[1] == "ReadableStream":
type = BuiltinTypes[IDLBuiltinType.Types.ReadableStream]
else:
type = BuiltinTypes[p[1]]

@@ -470,6 +470,7 @@ pub mod promiserejectionevent;
pub mod radionodelist;
pub mod range;
pub mod raredata;
pub mod readablestream;
pub mod request;
pub mod response;
pub mod rtcicecandidate;
@@ -0,0 +1,59 @@
/* 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/. */

use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
use crate::dom::bindings::codegen::Bindings::ReadableStreamBinding::Wrap;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use crate::js::conversions::ToJSValConvertible;
use crate::script_runtime::JSContext as SafeJSContext;
use js::jsapi::{Heap, JSFunction, JSObject};
use js::jsapi::NewReadableDefaultStreamObject;
use js::jsval::UndefinedValue;
use dom_struct::dom_struct;
use std::rc::Rc;
use std::ptr;

#[dom_struct]
pub struct ReadableStream {
reflector_: Reflector,
#[ignore_malloc_size_of = "SM handles JS values"]
stream: Heap<*mut JSObject>,
}

impl ReadableStream {
/// <https://html.spec.whatwg.org/multipage/#dom-messagechannel>
#[allow(non_snake_case, unsafe_code)]
pub fn Constructor(
cx: SafeJSContext,
global: &GlobalScope,
underlying_source: *mut JSObject,
_size: Rc<Function>,
high_watermark: Finite<f64>,
proto: *mut JSObject,
) -> DomRoot<ReadableStream> {
let heap = Heap::default();

unsafe {
let source = Heap::boxed(underlying_source);
let proto = Heap::boxed(proto);
rooted!(in(*cx) let mut size_handler = ptr::null_mut::<JSFunction>());
let size = Heap::boxed(size_handler.get());

rooted!(in(*cx) let stream = NewReadableDefaultStreamObject(*cx, source.handle(), size.handle(), *high_watermark, proto.handle()));
heap.set(stream.get());
}

reflect_dom_object(
Box::new(ReadableStream {
reflector_: Reflector::new(),
stream: heap,
}),
global,
Wrap,
)
}
}
@@ -0,0 +1,13 @@
/* 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: https://streams.spec.whatwg.org/#rs-class
*/

[Exposed=(Window,Worker)]
interface ReadableStream {
constructor(object underlyingSource, Function size, HighWatermark highWaterMark, object proto);
};

typedef double HighWatermark;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.