mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
This is the final step of #1799, where the majority of the generated code for the JS bindings is now compiled as part of the script_bindings build step. The remaining pieces in script must live there because they refer to concrete DOM types; all code in script_bindings is generic over the [DomTypes](https://doc.servo.org/script/dom/bindings/codegen/DomTypes/trait.DomTypes.html) trait. My testing with incremental builds shows me a 12 second reduction in build times on my 2024 M4 Macbook Pro when modifying code in the script crate after these changes. Before this PR those changes took 20 seconds to rebuild Servo, and now they take 8 seconds. Testing: Existing WPT tests ensure no regressions. Fixes: #1799 --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
/* 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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
use std::ptr;
|
|
|
|
use js::jsapi::{CallArgs, JSObject};
|
|
use js::rust::HandleObject;
|
|
|
|
use crate::codegen::PrototypeList;
|
|
use crate::error::throw_constructor_without_new;
|
|
use crate::interface::get_desired_proto;
|
|
use crate::script_runtime::JSContext;
|
|
use crate::utils::ProtoOrIfaceArray;
|
|
|
|
pub(crate) unsafe fn call_default_constructor<D: crate::DomTypes>(
|
|
cx: JSContext,
|
|
args: &CallArgs,
|
|
global: &D::GlobalScope,
|
|
proto_id: PrototypeList::ID,
|
|
ctor_name: &str,
|
|
creator: unsafe fn(JSContext, HandleObject, *mut ProtoOrIfaceArray),
|
|
constructor: impl FnOnce(JSContext, &CallArgs, &D::GlobalScope, HandleObject) -> bool,
|
|
) -> bool {
|
|
if !args.is_constructing() {
|
|
throw_constructor_without_new(cx, ctor_name);
|
|
return false;
|
|
}
|
|
|
|
rooted!(in(*cx) let mut desired_proto = ptr::null_mut::<JSObject>());
|
|
let proto_result = get_desired_proto(cx, args, proto_id, creator, desired_proto.handle_mut());
|
|
if proto_result.is_err() {
|
|
return false;
|
|
}
|
|
|
|
constructor(cx, args, global, desired_proto.handle())
|
|
}
|