diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-11-03 08:29:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-03 08:29:14 -0500 |
commit | d02496969a892e45314e38fad6ad092b9464b92d (patch) | |
tree | 615db8a1f539d381a2eb7575e94a2f44a04a793c /components/script/script_runtime.rs | |
parent | 7f77cb0bde01065e82cbb50214f3d21811fdd7dc (diff) | |
parent | 9fb01e879ba5fa110a171b36189e043a201a14eb (diff) | |
download | servo-d02496969a892e45314e38fad6ad092b9464b92d.tar.gz servo-d02496969a892e45314e38fad6ad092b9464b92d.zip |
Auto merge of #24563 - Akash-Pateria:async-wasm-compilation-initial, r=jdm
Binding stream consumer to support asynchronous WebAssembly compilation
This PR contains changes related to binding the Stream Consumer wrapper for supporting async WebAssembly compilation in Servo. The changes are listed below:
- Added a StreamConsumer wrapper and implemented its corresponding behaviors such as consumeChunk, streamEnd, streamError, and noteResponseURLs.
- Added ReportStreamErrorCallback for reporting the CompileError/TypeError occurred during the compilation.
---
- [X] `./mach build -d` does not report any errors, however, it has a few warnings of unused functions since we are calling them as yet.
- [X] `./mach test-tidy` does not report any errors
- [X] These changes are part of #21476 fix
Diffstat (limited to 'components/script/script_runtime.rs')
-rw-r--r-- | components/script/script_runtime.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 21cea763c00..10198050ace 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -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); + +#[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) + ); +} |