Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Update SpiderMonkey to 97 #556

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ lazy_static = "1"
libc = "0.2"
log = "0.4"
num-traits = "0.2"
mozjs_sys = { git = "https://github.com/servo/mozjs", rev="4cd3f5b81f4c363c039631bf870e61a00c983f63" }
mozjs_sys = { git = "https://github.com/CYBAI/mozjs", branch = "smup-97" }
2 changes: 1 addition & 1 deletion src/glue_wrappers.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ wrap!(glue: pub fn RUST_SYMBOL_TO_JSID(sym: *mut Symbol, id: MutableHandleId));
wrap!(glue: pub fn RUST_JSID_IS_VOID(id: HandleId) -> bool);
wrap!(glue: pub fn RUST_INTERNED_STRING_TO_JSID(cx: *mut JSContext, str: *mut JSString, id: MutableHandleId));
wrap!(glue: pub fn AppendToIdVector(v: MutableHandleIdVector, id: HandleId) -> bool);
wrap!(glue: pub fn JS_GetPromiseResult (promise: HandleObject, dest: MutableHandleValue));
wrap!(glue: pub fn JS_GetPromiseResult(promise: HandleObject, dest: MutableHandleValue));
wrap!(glue: pub fn JS_GetScriptPrivate(script: *mut JSScript, dest: MutableHandleValue));
wrap!(glue: pub fn JS_GetModulePrivate(module: *mut JSObject, dest: MutableHandleValue));
wrap!(glue: pub fn EncodeStringToUTF8(cx: *mut JSContext, str: HandleString, cb: fn(*const c_char)));
262 changes: 133 additions & 129 deletions src/jsapi_wrappers.in

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions src/jsglue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,23 @@ class WrapperProxyHandler : public js::Wrapper

virtual bool getOwnPropertyDescriptor(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc) const override
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) const override
{
return mTraps.getOwnPropertyDescriptor
? mTraps.getOwnPropertyDescriptor(cx, proxy, id, desc)
: js::Wrapper::getOwnPropertyDescriptor(cx, proxy, id, desc);
if (mTraps.getOwnPropertyDescriptor)
{
JS::Rooted<JS::PropertyDescriptor> mpd(cx);
if (desc.isSome())
{
mpd.set(*desc);
}
bool result = mTraps.getOwnPropertyDescriptor(cx, proxy, id, &mpd);
desc.set(mozilla::ToMaybeRef(&mpd));
return result;
}
else
{
return js::Wrapper::getOwnPropertyDescriptor(cx, proxy, id, desc);
}
}

virtual bool defineProperty(JSContext *cx,
Expand Down Expand Up @@ -467,9 +479,16 @@ class ForwardingProxyHandler : public js::BaseProxyHandler

virtual bool getOwnPropertyDescriptor(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc) const override
JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) const override
{
return mTraps.getOwnPropertyDescriptor(cx, proxy, id, desc);
JS::Rooted<JS::PropertyDescriptor> mpd(cx);
if (desc.isSome())
{
mpd.set(*desc);
}
bool result = mTraps.getOwnPropertyDescriptor(cx, proxy, id, &mpd);
desc.set(mozilla::ToMaybeRef(&mpd));
return result;
}

virtual bool defineProperty(JSContext *cx,
Expand Down Expand Up @@ -604,8 +623,14 @@ InvokeGetOwnPropertyDescriptor(
JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc)
{
return static_cast<const ForwardingProxyHandler*>(handler)->
getOwnPropertyDescriptor(cx, proxy, id, desc);
JS::Rooted<mozilla::Maybe<JS::PropertyDescriptor>> mpd(cx);
bool result = static_cast<const ForwardingProxyHandler*>(handler)->
getOwnPropertyDescriptor(cx, proxy, id, &mpd);
if (mpd.isSome())
{
desc.set(*mpd);
}
return result;
}

bool
Expand Down Expand Up @@ -1062,13 +1087,13 @@ CallUnbarrieredObjectTracer(JSTracer* trc, JSObject** objp, const char* name)
void
CallObjectRootTracer(JSTracer* trc, JSObject** objp, const char* name)
{
JS::UnsafeTraceRoot(trc, objp, name);
JS::TraceRoot(trc, objp, name);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

void
CallValueRootTracer(JSTracer* trc, JS::Value* valp, const char* name)
{
JS::UnsafeTraceRoot(trc, valp, name);
JS::TraceRoot(trc, valp, name);
}

bool
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extern crate num_traits;
pub mod jsapi {
pub use mozjs_sys::jsapi::glue::*;
pub use mozjs_sys::jsapi::js::detail::*;
pub use mozjs_sys::jsapi::js::Scalar::Type;
pub use mozjs_sys::jsapi::js::*;
pub use mozjs_sys::jsapi::mozilla::MallocSizeOf;
pub use mozjs_sys::jsapi::JS::detail::*;
pub use mozjs_sys::jsapi::JS::shadow::Object;
pub use mozjs_sys::jsapi::JS::Scalar::Type;
pub use mozjs_sys::jsapi::JS::*;
pub use mozjs_sys::jsapi::*;
}
Expand Down
8 changes: 3 additions & 5 deletions src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl Runtime {
context.set(js_context);
});

InitSelfHostedCode(js_context);
InitSelfHostedCode(js_context, Default::default(), None);

SetWarningReporter(js_context, Some(report_warning));

Expand Down Expand Up @@ -1500,6 +1500,7 @@ pub mod wrappers {
use jsapi::ForOfIterator_NonIterableBehavior;
use jsapi::HandleIdVector;
use jsapi::HandleObjectVector;
use jsapi::InstantiateOptions;
use jsapi::JSClass;
use jsapi::JSErrorReport;
use jsapi::JSExnType;
Expand Down Expand Up @@ -1530,8 +1531,6 @@ pub mod wrappers {
use jsapi::Symbol;
use jsapi::SymbolCode;
use jsapi::TranscodeBuffer;
use jsapi::TranscodeRange;
use jsapi::TranscodeResult;
use jsapi::TwoByteChars;
use jsapi::UniqueChars;
use jsapi::Value;
Expand Down Expand Up @@ -1645,6 +1644,7 @@ pub mod jsapi_wrapped {
use jsapi::ForOfIterator_NonIterableBehavior;
use jsapi::HandleIdVector;
use jsapi::HandleObjectVector;
use jsapi::InstantiateOptions;
use jsapi::JSClass;
use jsapi::JSErrorReport;
use jsapi::JSExnType;
Expand Down Expand Up @@ -1675,8 +1675,6 @@ pub mod jsapi_wrapped {
use jsapi::Symbol;
use jsapi::SymbolCode;
use jsapi::TranscodeBuffer;
use jsapi::TranscodeRange;
use jsapi::TranscodeResult;
use jsapi::TwoByteChars;
use jsapi::UniqueChars;
use jsapi::Value;
Expand Down
68 changes: 55 additions & 13 deletions tests/property_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ extern crate mozjs_sys;

use std::ptr;

use mozjs::jsapi::{JS_NewGlobalObject, JS_NewPlainObject, FromPropertyDescriptor, JS_DefineProperty, JS_GetPropertyDescriptor};
use mozjs::jsapi::{JSPROP_ENUMERATE, JSPROP_READONLY, JSPROP_PERMANENT};
use mozjs::jsapi::{
FromPropertyDescriptor, JS_DefineProperty, JS_GetPropertyDescriptor, JS_NewGlobalObject,
JS_NewPlainObject,
};
use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption, PropertyDescriptor};
use mozjs::jsapi::{JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY};
use mozjs::jsval::{Int32Value, NullValue};
use mozjs::rust::{JSEngine, Runtime, RealmOptions, SIMPLE_GLOBAL_CLASS};
use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS};
use mozjs_sys::jsapi::JSObject;
use mozjs_sys::jsapi::JS_GetProperty;

#[test]
Expand All @@ -37,26 +41,64 @@ fn property_descriptor() {
rooted!(in(context) let property = Int32Value(32));

let attrs = (JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY) as u32;
assert!(JS_DefineProperty(context, object.handle().into(), b"property\0" as *const u8 as *const libc::c_char, property.handle().into(), attrs));
assert!(JS_DefineProperty(
context,
object.handle().into(),
b"property\0" as *const u8 as *const libc::c_char,
property.handle().into(),
attrs
));

rooted!(in(context) let mut descriptor: PropertyDescriptor);
rooted!(in(context) let mut obj: *mut JSObject);

assert!(JS_GetPropertyDescriptor(context, object.handle().into(), b"property\0" as *const u8 as *const libc::c_char, descriptor.handle_mut().into()));
assert_eq!(descriptor.get().attrs, attrs);
assert_eq!(descriptor.get().value.to_int32(), 32);
assert!(JS_GetPropertyDescriptor(
context,
object.handle().into(),
b"property\0" as *const u8 as *const libc::c_char,
descriptor.handle_mut().into(),
obj.handle_mut().into()
));
assert!(descriptor.get().hasValue_());
assert!(descriptor.get().enumerable_());
assert_eq!(descriptor.get().value_.to_int32(), 32);

rooted!(in(context) let mut desc = NullValue());
assert!(FromPropertyDescriptor(context, descriptor.handle().into(), desc.handle_mut().into()));
assert!(FromPropertyDescriptor(
context,
descriptor.handle().into(),
desc.handle_mut().into()
));
rooted!(in(context) let desc_object = desc.to_object());

rooted!(in(context) let mut rval = NullValue());
assert!(JS_GetProperty(context, desc_object.handle().into(), b"value\0" as *const u8 as *const libc::c_char, rval.handle_mut().into()));
assert!(JS_GetProperty(
context,
desc_object.handle().into(),
b"value\0" as *const u8 as *const libc::c_char,
rval.handle_mut().into()
));
assert_eq!(rval.get().to_int32(), 32);
assert!(JS_GetProperty(context, desc_object.handle().into(), b"configurable\0" as *const u8 as *const libc::c_char, rval.handle_mut().into()));
assert!(JS_GetProperty(
context,
desc_object.handle().into(),
b"configurable\0" as *const u8 as *const libc::c_char,
rval.handle_mut().into()
));
assert!(!rval.get().to_boolean());
assert!(JS_GetProperty(context, desc_object.handle().into(), b"enumerable\0" as *const u8 as *const libc::c_char, rval.handle_mut().into()));
assert!(JS_GetProperty(
context,
desc_object.handle().into(),
b"enumerable\0" as *const u8 as *const libc::c_char,
rval.handle_mut().into()
));
assert!(rval.get().to_boolean());
assert!(JS_GetProperty(context, desc_object.handle().into(), b"writable\0" as *const u8 as *const libc::c_char, rval.handle_mut().into()));
assert!(JS_GetProperty(
context,
desc_object.handle().into(),
b"writable\0" as *const u8 as *const libc::c_char,
rval.handle_mut().into()
));
assert!(!rval.get().to_boolean());
}
}
}