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

Binding stream consumer to support asynchronous WebAssembly compilation #24563

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add StreamConsumer wrapper and ReportStreamErrorCallback fn

  • Loading branch information
ridhimrastogi committed Nov 3, 2019
commit 9fb01e879ba5fa110a171b36189e043a201a14eb
@@ -5,6 +5,8 @@
//! The script runtime contains common traits and structs commonly used by the
//! script thread, the dom, and the worker threads.

#![allow(dead_code)]

use crate::dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback;
use crate::dom::bindings::conversions::get_dom_class;
use crate::dom::bindings::conversions::private_from_object;
@@ -26,7 +28,10 @@ use crate::script_thread::trace_thread;
use crate::task::TaskBox;
use crate::task_source::{TaskSource, TaskSourceName};
use js::glue::{CollectServoSizes, CreateJobQueue, DeleteJobQueue, JobQueueTraps, SetBuildId};
use js::glue::{RUST_js_GetErrorMessage, StreamConsumerConsumeChunk, StreamConsumerStreamEnd};
use js::glue::{StreamConsumerNoteResponseURLs, StreamConsumerStreamError};
use js::jsapi::ContextOptionsRef;
use js::jsapi::StreamConsumer as JSStreamConsumer;
use js::jsapi::{BuildIdCharVector, DisableIncrementalGC, GCDescription, GCProgress};
use js::jsapi::{HandleObject, Heap, JobQueue};
use js::jsapi::{JSContext as RawJSContext, JSTracer, SetDOMCallbacks, SetGCSliceCallback};
@@ -51,6 +56,7 @@ use profile_traits::mem::{Report, ReportKind, ReportsChan};
use servo_config::opts;
use servo_config::pref;
use std::cell::Cell;
use std::ffi::CString;
use std::fmt;
use std::io::{stdout, Write};
use std::ops::Deref;
@@ -776,3 +782,53 @@ impl Deref for JSContext {
&self.0
}
}

pub struct StreamConsumer(*mut JSStreamConsumer);
This conversation was marked as resolved by jdm

This comment has been minimized.

Copy link
@jdm

jdm Nov 3, 2019

Member

Sorry, one last change that will be necessary - add a #![allow(dead_code)] at the top of the file after the license header comment. Otherwise our CI will complain because these new methods and functions are not actually called by any code.

This comment has been minimized.

Copy link
@Akash-Pateria

Akash-Pateria Nov 3, 2019

Author Contributor

Done.


#[allow(unsafe_code)]
impl StreamConsumer {
fn consume_chunk(&self, stream: &[u8]) -> bool {
unsafe {
let stream_ptr = stream.as_ptr();
return StreamConsumerConsumeChunk(self.0, stream_ptr, stream.len());
}
}

fn stream_end(&self) {
unsafe {
StreamConsumerStreamEnd(self.0);
}
}

fn stream_error(&self, error_code: usize) {
unsafe {
StreamConsumerStreamError(self.0, error_code);
}
}

fn note_response_urls(&self, maybe_url: Option<String>, maybe_source_map_url: Option<String>) {
unsafe {
let maybe_url = maybe_url.map(|url| CString::new(url).unwrap());
let maybe_source_map_url = maybe_source_map_url.map(|url| CString::new(url).unwrap());

let maybe_url_param = match maybe_url.as_ref() {
Some(url) => url.as_ptr(),
None => ptr::null(),
};
let maybe_source_map_url_param = match maybe_source_map_url.as_ref() {
Some(url) => url.as_ptr(),
None => ptr::null(),
};

StreamConsumerNoteResponseURLs(self.0, maybe_url_param, maybe_source_map_url_param);
}
}
}

#[allow(unsafe_code)]
unsafe extern "C" fn report_stream_error_callback(_cx: *mut JSContext, error_code: usize) {
error!(
"Error initializing StreamConsumer: {:?}",
RUST_js_GetErrorMessage(ptr::null_mut(), error_code as u32)
);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.