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

Commit

Permalink
Auto merge of #465 - jdm:smup67, r=asajeffrey
Browse files Browse the repository at this point in the history
Upgrade to SpiderMonkey 67

Depends on servo/mozjs#186.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/465)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Jun 26, 2019
2 parents bea7b5c + 68a83c3 commit 124e524
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 51 deletions.
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-5.0
packages:
- autoconf2.13
- gcc-6
- g++-6
- clang-5.0
- clang
homebrew:
update: true
packages:
- python
- python@2
- autoconf@2.13
- ccache
- llvm
- yasm

env:
- FEATURES=""
- FEATURES="--features debugmozjs"

before_script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CC=gcc-6; export CXX=g++-6; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install autoconf@2.13 ccache llvm yasm; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CC=clang; export CXX=clang++; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PYTHON3="/usr/local/opt/python/bin/python3"; fi

script:
- ccache -z
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mozjs"
description = "Rust bindings to the Mozilla SpiderMonkey JavaScript engine."
repository = "https://github.com/servo/rust-mozjs"
version = "0.11.0"
version = "0.12.0"
authors = ["The Servo Project Developers"]
build = "build.rs"
license = "MPL-2.0"
Expand Down Expand Up @@ -51,4 +51,4 @@ lazy_static = "1"
libc = "0.2"
log = "0.4"
num-traits = "0.2"
mozjs_sys = { git = "https://github.com/servo/mozjs", rev = "05c7d307811f88ca263f1861ccca0a81ffb0b58d" }
mozjs_sys = { git = "https://github.com/servo/mozjs", rev = "b2f83932fe9d361face14efd03f2465b9262e687" }
32 changes: 22 additions & 10 deletions src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ pub enum Action { }
unsafe impl Sync for ProxyTraps { }
/* automatically generated by rust-bindgen */

#[repr(C)]
#[derive(Copy, Clone)]
pub struct JobQueueTraps {
pub getIncumbentGlobal: ::std::option::Option<
unsafe extern "C" fn(queue: *const c_void, cx: *mut JSContext) -> *mut JSObject>,
pub enqueuePromiseJob: ::std::option::Option<
unsafe extern "C" fn(queue: *const c_void, cx: *mut JSContext, promise: HandleObject,
job: HandleObject, allocationSite: HandleObject,
incumbentGlobal: HandleObject) -> bool>,
pub empty: ::std::option::Option<unsafe extern "C" fn(queue: *const c_void) -> bool>,
}
impl ::std::default::Default for JobQueueTraps {
fn default() -> JobQueueTraps { unsafe { ::std::mem::zeroed() } }
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct ProxyTraps {
Expand Down Expand Up @@ -42,8 +57,9 @@ pub struct ProxyTraps {
-> bool>,
pub enumerate: ::std::option::Option<unsafe extern "C" fn
(cx: *mut JSContext,
proxy: HandleObject)
-> *mut JSObject>,
proxy: HandleObject,
props: *mut AutoIdVector)
-> bool>,
pub getPrototypeIfOrdinary: ::std::option::Option<unsafe extern "C" fn
(cx: *mut JSContext,
proxy: HandleObject,
Expand Down Expand Up @@ -83,13 +99,6 @@ pub struct ProxyTraps {
(cx: *mut JSContext,
proxy: HandleObject,
args: *const CallArgs) -> bool>,
pub getPropertyDescriptor: ::std::option::Option<unsafe extern "C" fn
(cx: *mut JSContext,
proxy: HandleObject,
id: HandleId,
desc:
MutableHandle<PropertyDescriptor>)
-> bool>,
pub hasOwn: ::std::option::Option<unsafe extern "C" fn
(cx: *mut JSContext,
proxy: HandleObject, id: HandleId,
Expand Down Expand Up @@ -255,7 +264,8 @@ extern "C" {
pub fn GetProxyHandler(obj: *mut JSObject) -> *const ::libc::c_void;
pub fn ReportError(aCx: *mut JSContext, aError: *const i8);
pub fn IsWrapper(obj: *mut JSObject) -> bool;
pub fn UnwrapObject(obj: *mut JSObject, stopAtOuter: u8) -> *mut JSObject;
pub fn UnwrapObjectStatic(obj: *mut JSObject) -> *mut JSObject;
pub fn UnwrapObjectDynamic(obj: *mut JSObject, cx: *mut JSContext, stopAtOuter: u8) -> *mut JSObject;
pub fn UncheckedUnwrapObject(obj: *mut JSObject, stopAtOuter: u8) -> *mut JSObject;
pub fn CreateAutoIdVector(cx: *mut JSContext) -> *mut AutoIdVector;
pub fn AppendToAutoIdVector(v: *mut AutoIdVector, id: jsid) -> bool;
Expand Down Expand Up @@ -348,4 +358,6 @@ extern "C" {
pub fn JS_GetEmptyStringValue (cx: *mut JSContext, dest: *mut JS::Value);
pub fn JS_GetReservedSlot (obj: *mut JSObject , index: u32, dest: *mut JS::Value);
pub fn EncodeStringToUTF8(cx: *mut JSContext, str: JS::HandleString, cb: fn(*const c_char));
pub fn CreateJobQueue(traps: *const JobQueueTraps, queue: *const c_void) -> *mut JS::JobQueue;
pub fn DeleteJobQueue(queue: *mut JS::JobQueue);
}
7 changes: 4 additions & 3 deletions src/jsapi_wrappers.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ wrap!(jsapi: pub fn GetWasmModule(obj: HandleObject) -> RefPtr<WasmModule>);
wrap!(jsapi: pub fn CaptureCurrentStack(cx: *mut JSContext, stackp: MutableHandleObject, capture: *mut StackCapture) -> bool);
wrap!(jsapi: pub fn BuildStackString(cx: *mut JSContext, principals: *mut JSPrincipals, stack: HandleObject, stringp: MutableHandleString, indent: usize, stackFormat: StackFormat) -> bool);
wrap!(jsapi: pub fn ForceLexicalInitialization(cx: *mut JSContext, obj: HandleObject) -> bool);
wrap!(jsapi: pub fn DetachArrayBuffer(cx: *mut JSContext, obj: HandleObject) -> bool);
wrap!(jsapi: pub fn StealArrayBufferContents(cx: *mut JSContext, obj: HandleObject) -> *mut ::std::os::raw::c_void);
wrap!(jsapi: pub fn CloneAndExecuteScript(cx: *mut JSContext, script: Handle<*mut JSScript>, rval: MutableHandle<Value>) -> bool);
wrap!(jsapi: pub fn CloneAndExecuteScript1(cx: *mut JSContext, envChain: *mut u8, script: Handle<*mut JSScript>, rval: MutableHandle<Value>) -> bool);
wrap!(jsapi: pub fn Evaluate(cx: *mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText<u16>, rval: MutableHandle<Value>) -> bool);
Expand Down Expand Up @@ -105,6 +107,7 @@ wrap!(jsapi: pub fn AddPromiseReactions(cx: *mut JSContext, promise: HandleObjec
wrap!(jsapi: pub fn GetPromiseUserInputEventHandlingState(promise: HandleObject) -> PromiseUserInputEventHandlingState);
wrap!(jsapi: pub fn SetPromiseUserInputEventHandlingState(promise: HandleObject, state: PromiseUserInputEventHandlingState) -> bool);
wrap!(jsapi: pub fn GetSavedFrameSource(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, sourcep: MutableHandle<*mut JSString>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult);
wrap!(jsapi: pub fn GetSavedFrameSourceId(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, sourceIdp: *mut u32, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult);
wrap!(jsapi: pub fn GetSavedFrameLine(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, linep: *mut u32, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult);
wrap!(jsapi: pub fn GetSavedFrameColumn(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, columnp: *mut u32, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult);
wrap!(jsapi: pub fn GetSavedFrameFunctionDisplayName(cx: *mut JSContext, principals: *mut JSPrincipals, savedFrame: HandleObject, namep: MutableHandle<*mut JSString>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult);
Expand Down Expand Up @@ -276,6 +279,7 @@ wrap!(jsapi: pub fn JS_DeleteElement(cx: *mut JSContext, obj: HandleObject, inde
wrap!(jsapi: pub fn JS_DeletePropertyById1(cx: *mut JSContext, obj: HandleObject, id: jsid) -> bool);
wrap!(jsapi: pub fn JS_DeleteProperty1(cx: *mut JSContext, obj: HandleObject, name: *const ::std::os::raw::c_char) -> bool);
wrap!(jsapi: pub fn JS_DeleteElement1(cx: *mut JSContext, obj: HandleObject, index: u32) -> bool);
wrap!(jsapi: pub fn JS_AssignObject(cx: *mut JSContext, target: HandleObject, src: HandleObject) -> bool);
wrap!(jsapi: pub fn JS_CallFunctionValue(cx: *mut JSContext, obj: HandleObject, fval: HandleValue, args: *const HandleValueArray, rval: MutableHandleValue) -> bool);
wrap!(jsapi: pub fn JS_CallFunction(cx: *mut JSContext, obj: HandleObject, fun: HandleFunction, args: *const HandleValueArray, rval: MutableHandleValue) -> bool);
wrap!(jsapi: pub fn JS_CallFunctionName(cx: *mut JSContext, obj: HandleObject, name: *const ::std::os::raw::c_char, args: *const HandleValueArray, rval: MutableHandleValue) -> bool);
Expand All @@ -293,8 +297,6 @@ wrap!(jsapi: pub fn JS_IsArrayObject(cx: *mut JSContext, value: HandleValue, isA
wrap!(jsapi: pub fn JS_IsArrayObject1(cx: *mut JSContext, obj: HandleObject, isArray: *mut bool) -> bool);
wrap!(jsapi: pub fn JS_GetArrayLength(cx: *mut JSContext, obj: HandleObject, lengthp: *mut u32) -> bool);
wrap!(jsapi: pub fn JS_SetArrayLength(cx: *mut JSContext, obj: HandleObject, length: u32) -> bool);
wrap!(jsapi: pub fn JS_StealArrayBufferContents(cx: *mut JSContext, obj: HandleObject) -> *mut ::std::os::raw::c_void);
wrap!(jsapi: pub fn JS_ExternalizeArrayBufferContents(cx: *mut JSContext, obj: HandleObject) -> *mut ::std::os::raw::c_void);
wrap!(jsapi: pub fn JS_GetFunctionLength(cx: *mut JSContext, fun: HandleFunction, length: *mut u16) -> bool);
wrap!(jsapi: pub fn JS_DefineFunctions(cx: *mut JSContext, obj: HandleObject, fs: *const JSFunctionSpec) -> bool);
wrap!(jsapi: pub fn JS_DefineFunction(cx: *mut JSContext, obj: HandleObject, name: *const ::std::os::raw::c_char, call: JSNative, nargs: ::std::os::raw::c_uint, attrs: ::std::os::raw::c_uint) -> *mut JSFunction);
Expand Down Expand Up @@ -350,7 +352,6 @@ wrap!(jsapi: pub fn JS_NewUint32ArrayWithBuffer(cx: *mut JSContext, arrayBuffer:
wrap!(jsapi: pub fn JS_NewFloat32ArrayWithBuffer(cx: *mut JSContext, arrayBuffer: HandleObject, byteOffset: u32, length: i32) -> *mut JSObject);
wrap!(jsapi: pub fn JS_NewFloat64ArrayWithBuffer(cx: *mut JSContext, arrayBuffer: HandleObject, byteOffset: u32, length: i32) -> *mut JSObject);
wrap!(jsapi: pub fn JS_GetArrayBufferViewBuffer(cx: *mut JSContext, obj: HandleObject, isSharedMemory: *mut bool) -> *mut JSObject);
wrap!(jsapi: pub fn JS_DetachArrayBuffer(cx: *mut JSContext, obj: HandleObject) -> bool);
wrap!(jsapi: pub fn JS_NewDataView(cx: *mut JSContext, buffer: HandleObject, byteOffset: u32, byteLength: i32) -> *mut JSObject);
wrap!(jsapi: pub fn JS_Utf8BufferIsCompilableUnit(cx: *mut JSContext, obj: HandleObject, utf8: *const ::std::os::raw::c_char, length: usize) -> bool);
wrap!(jsapi: pub fn JS_ExecuteScript(cx: *mut JSContext, script: Handle<*mut JSScript>, rval: MutableHandle<Value>) -> bool);
Expand Down
96 changes: 70 additions & 26 deletions src/jsglue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,50 @@ typedef size_t(*GetSize)(JSObject *obj);

WantToMeasure gWantToMeasure = nullptr;

struct JobQueueTraps {
JSObject* (*getIncumbentGlobal)(void* queue, JSContext* cx);
bool (*enqueuePromiseJob)(void* queue, JSContext* cx, JS::HandleObject promise,
JS::HandleObject job, JS::HandleObject allocationSite,
JS::HandleObject incumbentGlobal) = 0;
bool (*empty)(void* queue);
};

class RustJobQueue : public JS::JobQueue{
JobQueueTraps mTraps;
void* mQueue;
public:
RustJobQueue(const JobQueueTraps& aTraps, void* aQueue)
: mTraps(aTraps)
, mQueue(aQueue)
{
}

virtual JSObject* getIncumbentGlobal(JSContext* cx) {
return mTraps.getIncumbentGlobal(mQueue, cx);
}

bool enqueuePromiseJob(JSContext* cx, JS::HandleObject promise,
JS::HandleObject job, JS::HandleObject allocationSite,
JS::HandleObject incumbentGlobal)
{
return mTraps.enqueuePromiseJob(mQueue, cx, promise, job, allocationSite, incumbentGlobal);
}

virtual bool empty() const {
return mTraps.empty(mQueue);
}

virtual void runJobs(JSContext* cx) {
MOZ_ASSERT(false, "runJobs should not be invoked");
}

private:
virtual js::UniquePtr<SavedJobQueue> saveJobQueue(JSContext* cx) {
MOZ_ASSERT(false, "saveJobQueue should not be invoked");
return nullptr;
}
};

struct ProxyTraps {
bool (*enter)(JSContext *cx, JS::HandleObject proxy, JS::HandleId id,
js::BaseProxyHandler::Action action, bool *bp);
Expand All @@ -47,7 +91,7 @@ struct ProxyTraps {
bool (*delete_)(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id, JS::ObjectOpResult &result);

JSObject* (*enumerate)(JSContext *cx, JS::HandleObject proxy);
bool (*enumerate)(JSContext *cx, JS::HandleObject proxy, js::AutoIdVector& props);

bool (*getPrototypeIfOrdinary)(JSContext *cx, JS::HandleObject proxy,
bool *isOrdinary, JS::MutableHandleObject protop);
Expand All @@ -73,9 +117,6 @@ struct ProxyTraps {
bool (*construct)(JSContext *cx, JS::HandleObject proxy,
const JS::CallArgs &args);

bool (*getPropertyDescriptor)(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc);
bool (*hasOwn)(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id, bool *bp);
bool (*getOwnEnumerablePropertyKeys)(JSContext *cx, JS::HandleObject proxy,
Expand Down Expand Up @@ -111,12 +152,13 @@ static int HandlerFamily;
#define DEFER_TO_TRAP_OR_BASE_CLASS(_base) \
\
/* Standard internal methods. */ \
virtual JSObject* enumerate(JSContext *cx, \
JS::HandleObject proxy) const override \
virtual bool enumerate(JSContext *cx, \
JS::HandleObject proxy, \
js::AutoIdVector& props) const override \
{ \
return mTraps.enumerate \
? mTraps.enumerate(cx, proxy) \
: _base::enumerate(cx, proxy); \
? mTraps.enumerate(cx, proxy, props) \
: _base::enumerate(cx, proxy, props); \
} \
\
virtual bool has(JSContext* cx, JS::HandleObject proxy, \
Expand Down Expand Up @@ -319,15 +361,6 @@ class WrapperProxyHandler : public js::Wrapper
? mTraps.isExtensible(cx, proxy, succeeded)
: js::Wrapper::isExtensible(cx, proxy, succeeded);
}

virtual bool getPropertyDescriptor(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc) const override
{
return mTraps.getPropertyDescriptor
? mTraps.getPropertyDescriptor(cx, proxy, id, desc)
: js::Wrapper::getPropertyDescriptor(cx, proxy, id, desc);
}
};

class RustJSPrincipal : public JSPrincipals
Expand Down Expand Up @@ -426,13 +459,6 @@ class ForwardingProxyHandler : public js::BaseProxyHandler
{
return mTraps.isExtensible(cx, proxy, succeeded);
}

virtual bool getPropertyDescriptor(JSContext *cx, JS::HandleObject proxy,
JS::HandleId id,
JS::MutableHandle<JS::PropertyDescriptor> desc) const override
{
return mTraps.getPropertyDescriptor(cx, proxy, id, desc);
}
};

class ServoDOMVisitor : public JS::ObjectPrivateVisitor {
Expand Down Expand Up @@ -768,9 +794,15 @@ IsWrapper(JSObject* obj)
}

JSObject*
UnwrapObject(JSObject* obj, bool stopAtOuter)
UnwrapObjectStatic(JSObject* obj)
{
return js::CheckedUnwrapStatic(obj);
}

JSObject*
UnwrapObjectDynamic(JSObject* obj, JSContext* cx, bool stopAtOuter)
{
return js::CheckedUnwrap(obj, stopAtOuter);
return js::CheckedUnwrapDynamic(obj, cx, stopAtOuter);
}

JSObject*
Expand Down Expand Up @@ -1037,4 +1069,16 @@ EncodeStringToUTF8(JSContext* cx, JS::HandleString str, EncodedStringCallback cb
cb(chars.get());
}

JS::JobQueue*
CreateJobQueue(const JobQueueTraps* aTraps, void* aQueue)
{
return new RustJobQueue(*aTraps, aQueue);
}

void
DeleteJobQueue(JS::JobQueue* queue)
{
delete queue;
}

} // extern "C"
8 changes: 4 additions & 4 deletions src/typedarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use glue::GetUint16ArrayLengthAndData;
use glue::GetUint32ArrayLengthAndData;
use glue::GetUint8ArrayLengthAndData;
use glue::GetUint8ClampedArrayLengthAndData;
use jsapi::GetArrayBufferData;
use jsapi::GetArrayBufferLengthAndData;
use jsapi::GetArrayBufferViewLengthAndData;
use jsapi::Heap;
use jsapi::JSContext;
use jsapi::JSObject;
use jsapi::JSTracer;
use jsapi::JS_GetArrayBufferData;
use jsapi::JS_GetArrayBufferViewType;
use jsapi::JS_GetFloat32ArrayData;
use jsapi::JS_GetFloat64ArrayData;
Expand All @@ -36,7 +36,6 @@ use jsapi::JS_GetUint16ArrayData;
use jsapi::JS_GetUint32ArrayData;
use jsapi::JS_GetUint8ArrayData;
use jsapi::JS_GetUint8ClampedArrayData;
use jsapi::JS_NewArrayBuffer;
use jsapi::JS_NewFloat32Array;
use jsapi::JS_NewFloat64Array;
use jsapi::JS_NewInt16Array;
Expand All @@ -46,6 +45,7 @@ use jsapi::JS_NewUint16Array;
use jsapi::JS_NewUint32Array;
use jsapi::JS_NewUint8Array;
use jsapi::JS_NewUint8ClampedArray;
use jsapi::NewArrayBuffer;
use jsapi::Type;
use jsapi::UnwrapArrayBuffer;
use jsapi::UnwrapArrayBufferView;
Expand Down Expand Up @@ -376,8 +376,8 @@ typed_array_element!(ArrayBufferU8,
u8,
UnwrapArrayBuffer,
GetArrayBufferLengthAndData,
JS_NewArrayBuffer,
JS_GetArrayBufferData);
NewArrayBuffer,
GetArrayBufferData);
typed_array_element!(ArrayBufferViewU8,
u8,
UnwrapArrayBufferView,
Expand Down

0 comments on commit 124e524

Please sign in to comment.