Skip to content

Commit

Permalink
Auto merge of #28753 - CYBAI:smup-97, r=<try>
Browse files Browse the repository at this point in the history
[WIP] Upgrade to SpiderMonkey 97

This should be merged after servo/mozjs#295 and servo/rust-mozjs#556 merged.

---

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)
- [x] There are tests for these changes (We need to confirm this smup will break or fix which tests)
  • Loading branch information
bors-servo committed Aug 30, 2022
2 parents 08bc2d5 + a082221 commit 3ebf51a
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 156 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ image = "0.24"
indexmap = { version = "1.0.2", features = ["std"] }
ipc-channel = "0.14"
itertools = "0.8"
js = { package = "mozjs", git = "https://github.com/servo/rust-mozjs" }
js = { package = "mozjs", git = "https://github.com/CYBAI/rust-mozjs", branch = "smup-97" }
jstraceable_derive = { path = "../jstraceable_derive" }
keyboard-types = "0.6"
lazy_static = "1"
Expand Down
39 changes: 21 additions & 18 deletions components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ def __init__(self, descriptor, name, static, unforgeable, crossorigin=False):
"name": m.identifier.name,
"attr": m,
"flags": "JSPROP_ENUMERATE",
"is_accessor": "true",
"kind": "JSPropertySpec_Kind::NativeAccessor",
}
for m in descriptor.interface.members if
m.isAttr() and m.isStatic() == static
Expand All @@ -1906,7 +1906,7 @@ def __init__(self, descriptor, name, static, unforgeable, crossorigin=False):
"name": "@@toStringTag",
"attr": None,
"flags": "JSPROP_READONLY",
"is_accessor": "false",
"kind": "JSPropertySpec_Kind::Value",
})

def generateArray(self, array, name):
Expand Down Expand Up @@ -1963,21 +1963,21 @@ def condition(m, d):

def specData(attr):
if attr["name"] == "@@toStringTag":
return (attr["name"][2:], attr["flags"], attr["is_accessor"],
return (attr["name"][2:], attr["flags"], attr["kind"],
str_to_const_array(self.descriptor.interface.getClassName()))

flags = attr["flags"]
if self.unforgeable:
flags += " | JSPROP_PERMANENT"
return (str_to_const_array(attr["attr"].identifier.name), flags, attr["is_accessor"], getter(attr),
return (str_to_const_array(attr["attr"].identifier.name), flags, attr["kind"], getter(attr),
setter(attr))

def template(m):
if m["name"] == "@@toStringTag":
return """ JSPropertySpec {
name: JSPropertySpec_Name { symbol_: SymbolCode::%s as usize + 1 },
attributes_: (%s) as u8,
isAccessor_: (%s),
kind_: %s,
u: JSPropertySpec_AccessorsOrValue {
value: JSPropertySpec_ValueWrapper {
type_: JSPropertySpec_ValueWrapper_Type::String,
Expand All @@ -1991,7 +1991,7 @@ def template(m):
return """ JSPropertySpec {
name: JSPropertySpec_Name { string_: %s as *const u8 as *const libc::c_char },
attributes_: (%s) as u8,
isAccessor_: (%s),
kind_: %s,
u: JSPropertySpec_AccessorsOrValue {
accessors: JSPropertySpec_AccessorsOrValue_Accessors {
getter: JSPropertySpec_Accessor {
Expand Down Expand Up @@ -5368,7 +5368,7 @@ def __init__(self, descriptor, operation):
}
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(
template, templateValues, declType, argument.identifier.name))
self.cgRoot.prepend(CGGeneric("rooted!(in(*cx) let value = desc.value);"))
self.cgRoot.prepend(CGGeneric("rooted!(in(*cx) let value = desc.value_);"))

def getArguments(self):
args = [(a, process_arg(a.identifier.name, a)) for a in self.arguments]
Expand Down Expand Up @@ -5491,7 +5491,7 @@ def getBody(self):
) {
return false;
}
if desc.obj.is_null() {
if !desc.hasValue_() {
return proxyhandler::cross_origin_property_fallback(cx, proxy, id, desc);
}
return true;
Expand All @@ -5507,8 +5507,8 @@ def getBody(self):
attrs = "JSPROP_ENUMERATE"
if self.descriptor.operations['IndexedSetter'] is None:
attrs += " | JSPROP_READONLY"
fillDescriptor = ("desc.value = result_root.get();\n"
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), (%s) as u32);\n"
fillDescriptor = ("let value = result_root.get();\n"
"fill_property_descriptor(MutableHandle::from_raw(desc), value, (%s) as u32);\n"
"return true;" % attrs)
templateValues = {
'jsvalRef': 'result_root.handle_mut()',
Expand All @@ -5532,8 +5532,8 @@ def getBody(self):
attrs = " | ".join(attrs)
else:
attrs = "0"
fillDescriptor = ("desc.value = result_root.get();\n"
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), (%s) as u32);\n"
fillDescriptor = ("let value = result_root.get();\n"
"fill_property_descriptor(MutableHandle::from_raw(desc), value, (%s) as u32);\n"
"return true;" % attrs)
templateValues = {
'jsvalRef': 'result_root.handle_mut()',
Expand Down Expand Up @@ -5569,17 +5569,18 @@ def getBody(self):
let proxy_lt = Handle::from_raw(proxy);
let id_lt = Handle::from_raw(id);
if !expando.is_null() {
if !JS_GetPropertyDescriptorById(*cx, expando.handle().into(), id, desc) {
if !JS_GetOwnPropertyDescriptorById(*cx, expando.handle().into(), id, desc) {
return false;
}
if !desc.obj.is_null() {
// Pretend the property lives on the wrapper.
desc.obj = proxy.get();
if desc.hasValue_() {
let mut slot = UndefinedValue();
GetProxyPrivate(proxy.get(), &mut slot);
desc.value_ = slot;
return true;
}
}
""" + namedGet + """\
desc.obj = ptr::null_mut();
desc.value_ = UndefinedValue();
return true;"""

def definition_body(self):
Expand Down Expand Up @@ -6342,6 +6343,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::jsapi::JSPROP_PERMANENT',
'js::jsapi::JSPROP_READONLY',
'js::jsapi::JSPropertySpec',
'js::jsapi::JSPropertySpec_Kind',
'js::jsapi::JSPropertySpec_Accessor',
'js::jsapi::JSPropertySpec_AccessorsOrValue',
'js::jsapi::JSPropertySpec_AccessorsOrValue_Accessors',
Expand All @@ -6366,8 +6368,9 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::jsapi::GetRealmObjectPrototype',
'js::rust::wrappers::JS_GetProperty',
'js::jsapi::JS_GetPropertyById',
'js::jsapi::JS_GetPropertyDescriptorById',
'js::jsapi::JS_GetOwnPropertyDescriptorById',
'js::glue::JS_GetReservedSlot',
'js::glue::GetProxyPrivate',
'js::jsapi::JS_HasProperty',
'js::jsapi::JS_HasPropertyById',
'js::rust::wrappers::JS_InitializePropertiesFromCompatibleNativeObject',
Expand Down
74 changes: 43 additions & 31 deletions components/script/dom/bindings/proxyhandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ use js::jsapi::{jsid, GetObjectRealmOrNull, GetRealmPrincipals, JSFunctionSpec,
use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, PropertyDescriptor};
use js::jsapi::{GetWellKnownSymbol, SymbolCode};
use js::jsapi::{JSErrNum, SetDOMProxyInformation};
use js::jsapi::{JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING};
use js::jsval::JSVal;
use js::jsval::ObjectValue;
use js::jsval::UndefinedValue;
use js::rust::wrappers::JS_AlreadyHasOwnPropertyById;
Expand Down Expand Up @@ -191,13 +193,30 @@ pub unsafe fn ensure_expando_object(
/// and writable if `readonly` is true.
pub fn fill_property_descriptor(
mut desc: MutableHandle<PropertyDescriptor>,
obj: *mut JSObject,
value: JSVal,
attrs: u32,
) {
desc.obj = obj;
desc.attrs = attrs;
desc.getter = None;
desc.setter = None;
let configurable = (attrs & JSPROP_PERMANENT as u32) == 0;
desc.set_hasConfigurable_(configurable);
desc.set_configurable_(configurable);

let enumerable = (attrs & JSPROP_ENUMERATE as u32) != 0;
desc.set_hasEnumerable_(enumerable);
desc.set_enumerable_(enumerable);

let writable = (attrs & JSPROP_READONLY as u32) == 0;
desc.set_hasWritable_(writable);
desc.set_writable_(writable);

desc.getter_ = ptr::null_mut();
desc.setter_ = ptr::null_mut();
desc.set_hasGetter_(false);
desc.set_hasSetter_(false);

desc.set_resolving_((attrs & JSPROP_RESOLVING as u32) != 0);

desc.value_ = value;
desc.set_hasValue_(!value.is_undefined());
}

/// <https://html.spec.whatwg.org/multipage/#isplatformobjectsameorigin-(-o-)>
Expand Down Expand Up @@ -451,14 +470,14 @@ pub unsafe fn cross_origin_get(

// > 2. Assert: `desc` is not undefined.
assert!(
!descriptor.obj.is_null(),
descriptor.hasValue_(),
"Callees should throw in all cases when they are not finding \
a property decriptor"
);

// > 3. If `! IsDataDescriptor(desc)` is true, then return `desc.[[Value]]`.
if is_data_descriptor(&descriptor) {
vp.set(descriptor.value);
vp.set(descriptor.value_);
return true;
}

Expand Down Expand Up @@ -516,7 +535,7 @@ pub unsafe fn cross_origin_set(

// > 2. Assert: desc is not undefined.
assert!(
!descriptor.obj.is_null(),
descriptor.hasValue_(),
"Callees should throw in all cases when they are not finding \
a property decriptor"
);
Expand Down Expand Up @@ -557,32 +576,27 @@ pub unsafe fn cross_origin_set(
}

unsafe fn get_getter_object(d: &PropertyDescriptor, out: RawMutableHandleObject) {
if (d.attrs & jsapi::JSPROP_GETTER as u32) != 0 {
out.set(std::mem::transmute(d.getter));
if d.hasGetter_() {
out.set(std::mem::transmute(d.getter_));
}
}

unsafe fn get_setter_object(d: &PropertyDescriptor, out: RawMutableHandleObject) {
if (d.attrs & jsapi::JSPROP_SETTER as u32) != 0 {
out.set(std::mem::transmute(d.setter));
if d.hasSetter_() {
out.set(std::mem::transmute(d.setter_));
}
}

/// <https://tc39.es/ecma262/#sec-isaccessordescriptor>
fn is_accessor_descriptor(d: &PropertyDescriptor) -> bool {
d.attrs & (jsapi::JSPROP_GETTER as u32 | jsapi::JSPROP_SETTER as u32) != 0
let is_data = is_data_descriptor(d);
!is_data && (d.hasSetter_() || d.hasGetter_())
}

/// <https://tc39.es/ecma262/#sec-isdatadescriptor>
fn is_data_descriptor(d: &PropertyDescriptor) -> bool {
let is_accessor = is_accessor_descriptor(d);
let is_generic = d.attrs &
(jsapi::JSPROP_GETTER as u32 |
jsapi::JSPROP_SETTER as u32 |
jsapi::JSPROP_IGNORE_READONLY |
jsapi::JSPROP_IGNORE_VALUE) ==
jsapi::JSPROP_IGNORE_READONLY | jsapi::JSPROP_IGNORE_VALUE;
!is_accessor && !is_generic
!is_accessor && (d.hasWritable_() || d.hasValue_())
}

/// Evaluate `CrossOriginGetOwnPropertyHelper(proxy, id) != null`.
Expand Down Expand Up @@ -636,8 +650,10 @@ pub unsafe fn cross_origin_get_own_property_helper(
return false;
}

if !desc.obj.is_null() {
desc.obj = proxy.get();
if desc.hasValue_() {
let mut slot = UndefinedValue();
GetProxyPrivate(proxy.get(), &mut slot);
desc.value_ = slot;
}

true
Expand All @@ -653,22 +669,18 @@ pub unsafe fn cross_origin_property_fallback(
cx: SafeJSContext,
proxy: RawHandleObject,
id: RawHandleId,
mut desc: RawMutableHandle<PropertyDescriptor>,
desc: RawMutableHandle<PropertyDescriptor>,
) -> bool {
assert!(desc.obj.is_null(), "why are we being called?");
assert!(desc.value_.is_undefined(), "why are we being called?");

// > 1. If P is `then`, `@@toStringTag`, `@@hasInstance`, or
// > `@@isConcatSpreadable`, then return `PropertyDescriptor{ [[Value]]:
// > undefined, [[Writable]]: false, [[Enumerable]]: false,
// > [[Configurable]]: true }`.
if is_cross_origin_allowlisted_prop(cx, id) {
*desc = PropertyDescriptor {
getter: None,
setter: None,
value: UndefinedValue(),
attrs: jsapi::JSPROP_READONLY as u32,
obj: proxy.get(),
};
let mut slot = UndefinedValue();
GetProxyPrivate(proxy.get(), &mut slot);
fill_property_descriptor(MutableHandle::from_raw(desc), slot, JSPROP_READONLY as u32);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ where
return Err(());
}

if (JSPROP_ENUMERATE as u32) & desc.attrs == 0 {
if !desc.enumerable_() {
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion components/script/dom/bindings/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ use http::StatusCode;
use indexmap::IndexMap;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use js::glue::{CallObjectTracer, CallScriptTracer, CallStringTracer, CallValueTracer};
use js::jsapi::frontend::CompilationStencil;
use js::jsapi::{
GCTraceKindToAscii, Heap, JSObject, JSScript, JSString, JSTracer, JobQueue, TraceKind,
already_AddRefed, GCTraceKindToAscii, Heap, JSObject, JSScript, JSString, JSTracer, JobQueue,
TraceKind,
};
use js::jsval::JSVal;
use js::rust::{GCMethods, Handle, Runtime};
Expand Down Expand Up @@ -221,6 +223,8 @@ unsafe_no_jsmanaged_fields!(Cow<'static, str>);

unsafe_no_jsmanaged_fields!(CspList);

unsafe_no_jsmanaged_fields!(already_AddRefed<CompilationStencil>);

/// Trace a `JSScript`.
pub fn trace_script(tracer: *mut JSTracer, description: &str, script: &Heap<*mut JSScript>) {
unsafe {
Expand Down

0 comments on commit 3ebf51a

Please sign in to comment.