Skip to content

Commit

Permalink
it runs pages without any js
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Sep 6, 2024
1 parent 5cf9d8c commit 4031939
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 164 deletions.
1 change: 1 addition & 0 deletions components/script/dom/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub mod codegen {
include!(concat!(env!("OUT_DIR"), "/RegisterBindings.rs"));
}*/
#[allow(
dead_code,
non_camel_case_types,
unused_imports,
unused_variables,
Expand Down
155 changes: 154 additions & 1 deletion components/script/dom/bindings/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! Various utilities to glue JavaScript and the DOM implementation together.

use std::cell::Ref;
use std::ffi::CString;
use std::os::raw::{c_char, c_void};
use std::ptr::NonNull;
Expand Down Expand Up @@ -35,17 +36,25 @@ use js::rust::{
};
use js::JS_CALLEE;
use malloc_size_of::MallocSizeOfOps;
use servo_media::audio::buffer_source_node::AudioBuffer as ServoMediaAudioBuffer;
pub use script_bindings::utils::*;

use crate::dom::bindings::codegen::PrototypeList::{MAX_PROTO_CHAIN_LENGTH, PROTO_OR_IFACE_LENGTH};
use crate::dom::bindings::codegen::{InterfaceObjectMap, PrototypeList};
use crate::dom::bindings::conversions::{
jsstring_to_str, private_from_proto_check, PrototypeCheck,
};
use crate::dom::bindings::error::throw_invalid_this;
use crate::dom::bindings::error::{throw_invalid_this, throw_dom_exception};
use crate::dom::bindings::inheritance::TopTypeId;
use crate::dom::bindings::proxyhandler::report_cross_origin_denial;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::trace::trace_object;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::dom::readablestream::ReadableStream;
use crate::dom::testbinding::TestBinding;
use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
use crate::dom::window::Window;
use crate::dom::windowproxy::WindowProxyHandler;
use crate::script_runtime::JSContext as SafeJSContext;

Expand Down Expand Up @@ -664,3 +673,147 @@ pub unsafe fn exception_to_promise(cx: *mut JSContext, rval: RawMutableHandleVal
}
}
*/

impl script_bindings::DomHelpers<crate::DomTypeHolder> for crate::DomTypeHolder {
fn throw_dom_exception(
cx: SafeJSContext,
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
result: script_bindings::error::Error,
) {
throw_dom_exception(cx, global, result)
}

unsafe fn global_scope_from_object(
obj: *mut js::jsapi::JSObject,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
GlobalScope::from_object(obj)
}

fn global_scope_origin(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
) -> &servo_url::MutableOrigin {
global.origin()
}

fn Window_create_named_properties_object(
cx: crate::script_runtime::JSContext,
proto: js::rust::HandleObject,
object: js::rust::MutableHandleObject,
) {
Window::create_named_properties_object(cx, proto, object)
}

fn Promise_new_resolved(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
cx: crate::script_runtime::JSContext,
value: js::rust::HandleValue,
) -> crate::dom::bindings::error::Fallible<
std::rc::Rc<<crate::DomTypeHolder as script_bindings::DomTypes>::Promise>,
> {
Promise::new_resolved(global, cx, value)
}

unsafe fn GlobalScope_from_object_maybe_wrapped(
obj: *mut js::jsapi::JSObject,
cx: *mut js::jsapi::JSContext,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
GlobalScope::from_object_maybe_wrapped(obj, cx)
}

fn GlobalScope_incumbent() -> Option<
crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
>,
> {
GlobalScope::incumbent()
}

fn GlobalScope_get_cx() -> crate::script_runtime::JSContext {
GlobalScope::get_cx()
}

unsafe fn GlobalScope_from_context(
cx: *mut js::jsapi::JSContext,
in_realm: crate::realms::InRealm,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
GlobalScope::from_context(cx, in_realm)
}

fn GlobalScope_from_reflector(
reflector: &impl script_bindings::reflector::DomObject,
realm: &script_bindings::realms::AlreadyInRealm,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
GlobalScope::from_reflector(reflector, &realm.into())
}

fn GlobalScope_report_an_error(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
info: crate::dom::bindings::error::ErrorInfo,
value: js::rust::HandleValue,
) {
global.report_an_error(info, value)
}

fn TestBinding_condition_satisfied(
cx: crate::script_runtime::JSContext,
obj: js::rust::HandleObject,
) -> bool {
TestBinding::condition_satisfied(cx, obj)
}
fn TestBinding_condition_unsatisfied(
cx: crate::script_runtime::JSContext,
obj: js::rust::HandleObject,
) -> bool {
TestBinding::condition_unsatisfied(cx, obj)
}
fn WebGL2RenderingContext_is_webgl2_enabled(
cx: crate::script_runtime::JSContext,
obj: js::rust::HandleObject,
) -> bool {
WebGL2RenderingContext::is_webgl2_enabled(cx, obj)
}

fn perform_a_microtask_checkpoint(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
) {
global.perform_a_microtask_checkpoint()
}

unsafe fn ReadableStream_from_js(
cx: crate::script_runtime::JSContext,
obj: *mut js::jsapi::JSObject,
in_realm: crate::realms::InRealm,
) -> Result<
crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::ReadableStream,
>,
(),
> {
ReadableStream::from_js(cx, obj, in_realm)
}

fn DOMException_stringifier(
exception: &<crate::DomTypeHolder as script_bindings::DomTypes>::DOMException,
) -> crate::dom::bindings::str::DOMString {
exception.stringifier()
}

fn get_map() -> &'static phf::Map<
&'static [u8],
fn(crate::script_runtime::JSContext, js::rust::HandleObject),
> {
&InterfaceObjectMap::MAP
}

fn AudioBuffer_get_channels(buffer: &<crate::DomTypeHolder as script_bindings::DomTypes>::AudioBuffer) -> Ref<Option<ServoMediaAudioBuffer>> {
buffer.get_channels()
}
}
146 changes: 0 additions & 146 deletions components/script/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ mod webdriver_handlers;
#[warn(deprecated)]
mod window_named_properties;

use std::cell::Ref;

use servo_media::audio::buffer_source_node::AudioBuffer as ServoMediaAudioBuffer;

pub use init::init;
// export traits to be available for derive macros
pub use script_bindings::inheritance::HasParent;
Expand All @@ -108,145 +104,3 @@ pub use script_bindings::trace::{CustomTraceable, JSTraceable};
pub use script_runtime::JSEngineSetup;

pub use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;

impl script_bindings::DomHelpers<crate::DomTypeHolder> for crate::DomTypeHolder {
fn throw_dom_exception(
cx: crate::script_runtime::JSContext,
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
result: script_bindings::error::Error,
) {
todo!()
}

unsafe fn global_scope_from_object(
obj: *mut js::jsapi::JSObject,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
todo!()
}

fn global_scope_origin(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
) -> &servo_url::MutableOrigin {
todo!()
}

fn report_cross_origin_denial(
cx: crate::script_runtime::JSContext,
id: js::jsapi::HandleId,
access: &str,
) -> bool {
todo!()
}

fn Window_create_named_properties_object(
cx: crate::script_runtime::JSContext,
proto: js::rust::HandleObject,
object: js::rust::MutableHandleObject,
) {
todo!()
}

fn Promise_new_resolved(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
cx: crate::script_runtime::JSContext,
value: js::rust::HandleValue,
) -> crate::dom::bindings::error::Fallible<
std::rc::Rc<<crate::DomTypeHolder as script_bindings::DomTypes>::Promise>,
> {
todo!()
}

unsafe fn GlobalScope_from_object_maybe_wrapped(
obj: *mut js::jsapi::JSObject,
cx: *mut js::jsapi::JSContext,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
todo!()
}

fn GlobalScope_incumbent() -> Option<
crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
>,
> {
todo!()
}

fn GlobalScope_get_cx() -> crate::script_runtime::JSContext {
todo!()
}

fn GlobalScope_from_context(
cx: *mut js::jsapi::JSContext,
in_realm: crate::realms::InRealm,
) -> crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
> {
todo!()
}

fn GlobalScope_report_an_error(
info: crate::dom::bindings::error::ErrorInfo,
value: js::rust::HandleValue,
) {
todo!()
}

fn TestBinding_condition_satisfied(
cx: crate::script_runtime::JSContext,
obj: js::rust::HandleObject,
) -> bool {
todo!()
}
fn TestBinding_condition_unsatisfied(
cx: crate::script_runtime::JSContext,
obj: js::rust::HandleObject,
) -> bool {
todo!()
}
fn WebGL2RenderingContext_is_webgl2_enabled(
cx: crate::script_runtime::JSContext,
obj: js::rust::HandleObject,
) -> bool {
todo!()
}

fn perform_a_microtask_checkpoint(
global: &<crate::DomTypeHolder as script_bindings::DomTypes>::GlobalScope,
) {
todo!()
}

fn ReadableStream_from_js(
cx: crate::script_runtime::JSContext,
obj: *mut js::jsapi::JSObject,
in_realm: crate::realms::InRealm,
) -> Result<
crate::dom::bindings::root::DomRoot<
<crate::DomTypeHolder as script_bindings::DomTypes>::ReadableStream,
>,
(),
> {
todo!()
}

fn DOMException_stringifier(
exception: &<crate::DomTypeHolder as script_bindings::DomTypes>::DOMException,
) -> crate::dom::bindings::str::DOMString {
todo!()
}

fn get_map() -> &'static phf::Map<
&'static [u8],
fn(crate::script_runtime::JSContext, js::rust::HandleObject),
> {
todo!()
}

fn AudioBuffer_get_channels(buffer: &<crate::DomTypeHolder as script_bindings::DomTypes>::AudioBuffer) -> Ref<Option<ServoMediaAudioBuffer>> {
todo!()
}
}
8 changes: 7 additions & 1 deletion components/script/realms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ use crate::dom::bindings::reflector::DomObject;
use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::JSContext;

pub struct AlreadyInRealm;
pub struct AlreadyInRealm(());

impl<'a> From<&'a script_bindings::realms::AlreadyInRealm> for AlreadyInRealm {
fn from(_realm: &'a script_bindings::realms::AlreadyInRealm) -> Self {
Self(())
}
}

impl AlreadyInRealm {
#![allow(unsafe_code)]
Expand Down
4 changes: 2 additions & 2 deletions components/script_bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -5943,7 +5943,7 @@ def getBody(self):
set += dedent(
"""
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
return <D as DomHelpers<D>>::report_cross_origin_denial(cx, id, "define");
return report_cross_origin_denial::<D>(cx, id, "define");
}
// Safe to enter the Realm of proxy now.
Expand Down Expand Up @@ -6002,7 +6002,7 @@ def getBody(self):
set += dedent(
"""
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
return <D as DomHelpers<D>>::report_cross_origin_denial(cx, id, "delete");
return report_cross_origin_denial::<D>(cx, id, "delete");
}
// Safe to enter the Realm of proxy now.
Expand Down
2 changes: 1 addition & 1 deletion components/script_bindings/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub unsafe fn report_pending_exception<D: crate::DomTypes>(

if dispatch_event {
let global = <D as crate::DomHelpers<D>>::GlobalScope_from_context(cx, realm);
D::GlobalScope_report_an_error(error_info, value.handle());
D::GlobalScope_report_an_error(&global, error_info, value.handle());
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/script_bindings/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ pub mod dom {
};
pub use crate::dom::bindings::proxyhandler;
pub use crate::dom::bindings::proxyhandler::{
ensure_expando_object, get_expando_object, set_property_descriptor,
ensure_expando_object, get_expando_object, set_property_descriptor, report_cross_origin_denial
};
pub use crate::dom::bindings::record::Record;
pub use crate::dom::bindings::reflector::{
Expand Down
Loading

0 comments on commit 4031939

Please sign in to comment.