Skip to content

Commit

Permalink
Auto merge of #20793 - asajeffrey:bindgenup, r=<try>
Browse files Browse the repository at this point in the history
Get the mozjs crate to work with the mozjs_sys which uses bindgen

<!-- Please describe your changes on the following line: -->

This is the matching PR to servo/mozjs#134 and servo/rust-mozjs#425 which runs bindgen on spidermonkey to produce Rust bindings.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because current tests should catch failures

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20793)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 30, 2018
2 parents 11a89bc + 0ec8d23 commit 0f8bacc
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 32 deletions.
30 changes: 17 additions & 13 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ opt-level = 3
# lto = false

[patch.crates-io]
mozjs_sys = { git = "https://github.com/servo/mozjs" }
mozjs = { git = "https://github.com/servo/rust-mozjs" }
# If you need to temporarily test Servo with a local fork of some upstream
# crate, add that here. Use the form:
#
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ environment:
C:\\Program Files (x86)\\MSBuild\\14.0\\Bin;\
C:\\Program Files\\Amazon\\AWSCLI\\;\
C:\\Program Files\\Microsoft Windows Performance Toolkit\\;\
C:\\Program Files\\LLVM\\bin;\
C:\\Program Files\\Git LFS;\
C:\\Program Files\\Git\\cmd;\
C:\\Program Files\\Git\\usr\\bin;\
Expand Down
2 changes: 1 addition & 1 deletion components/malloc_size_of/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ euclid = "0.17"
hashglobe = { path = "../hashglobe" }
hyper = { version = "0.10", optional = true }
hyper_serde = { version = "0.8", optional = true }
mozjs = { version = "0.6", features = ["promises"], optional = true }
mozjs = { version = "0.7", features = ["promises"], optional = true }
selectors = { path = "../selectors" }
serde = { version = "1.0.27", optional = true }
serde_bytes = { version = "0.10", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ metrics = {path = "../metrics"}
mitochondria = "1.1.2"
mime = "0.2.1"
mime_guess = "1.8.0"
mozjs = { version = "0.6", features = ["promises"]}
mozjs = { version = "0.7", features = ["promises"]}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.1.32"
Expand Down
16 changes: 8 additions & 8 deletions components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def getPerSignatureCall(signature, argConversionStartsAt=0):
for i in range(0, distinguishingIndex)]

# Select the right overload from our set.
distinguishingArg = "args.get(%d)" % distinguishingIndex
distinguishingArg = "HandleValue::from_raw(args.get(%d))" % distinguishingIndex

def pickFirstSignature(condition, filterLambda):
sigs = filter(filterLambda, possibleSignatures)
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def __init__(self, argument, index, args, argc, descriptorProvider,
}

replacementVariables = {
"val": string.Template("${args}.get(${index})").substitute(replacer),
"val": string.Template("HandleValue::from_raw(${args}.get(${index}))").substitute(replacer),
}

info = getJSToNativeConversionInfo(
Expand Down Expand Up @@ -1328,7 +1328,7 @@ def __init__(self, argument, index, args, argc, descriptorProvider,
else:
assert argument.optional
variadicConversion = {
"val": string.Template("${args}.get(variadicArg)").substitute(replacer),
"val": string.Template("HandleValue::from_raw(${args}.get(variadicArg))").substitute(replacer),
}
innerConverter = [instantiateJSToNativeConversionTemplate(
template, variadicConversion, declType, "slot")]
Expand Down Expand Up @@ -3365,7 +3365,7 @@ def isFallible(self):
return 'infallible' not in self.extendedAttributes

def wrap_return_value(self):
return wrapForType('args.rval()')
return wrapForType('MutableHandleValue::from_raw(args.rval())')

def define(self):
return (self.cgRoot.define() + "\n" + self.wrap_return_value())
Expand Down Expand Up @@ -3516,7 +3516,7 @@ def definition_body(self):
self.descriptor, self.method),
pre="let this = &*this;\n"
"let args = &*args;\n"
"let argc = args._base.argc_;\n")
"let argc = args.argc_;\n")

@staticmethod
def makeNativeName(descriptor, method):
Expand Down Expand Up @@ -3675,7 +3675,7 @@ def definition_body(self):
return false;
}
rooted!(in(cx) let target_obj = v.to_object());
JS_SetProperty(cx, target_obj.handle(), %s as *const u8 as *const libc::c_char, args.get(0))
JS_SetProperty(cx, target_obj.handle(), %s as *const u8 as *const libc::c_char, HandleValue::from_raw(args.get(0)))
""" % (str_to_const_array(attrName), attrName, str_to_const_array(forwardToAttrName)))


Expand All @@ -3693,7 +3693,7 @@ def definition_body(self):
assert all(ord(c) < 128 for c in name)
return CGGeneric("""\
JS_DefineProperty(cx, obj, %s as *const u8 as *const libc::c_char,
args.get(0), JSPROP_ENUMERATE, None, None)""" % name)
HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE, None, None)""" % name)


class CGMemberJITInfo(CGThing):
Expand Down Expand Up @@ -5514,7 +5514,7 @@ def definition_body(self):
JS_SetPrototype(cx, element.handle(), prototype.handle());
(result).to_jsval(cx, args.rval());
(result).to_jsval(cx, MutableHandleValue::from_raw(args.rval()));
return true;
""" % self.descriptor.name)
else:
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/reflector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Reflector {
#[inline]
pub fn get_jsobject(&self) -> HandleObject {
// We're rooted, so it's safe to hand out a handle to object in Heap
unsafe { self.object.handle() }
unsafe { HandleObject::from_raw(self.object.handle()) }
}

/// Initialize the reflector. (May be called only once.)
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ impl<T> RootedTraceableBox<Heap<T>>
T: GCMethods + Copy,
{
pub fn handle(&self) -> Handle<T> {
unsafe { (*self.ptr).handle() }
unsafe { Handle::from_raw((*self.ptr).handle()) }
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/customelementregistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use js::glue::UnwrapObject;
use js::jsapi::{Heap, IsCallable, IsConstructor, HandleValueArray};
use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
use js::jsval::{JSVal, NullValue, ObjectValue, UndefinedValue};
use js::rust::{HandleObject, MutableHandleValue};
use js::rust::{HandleObject, HandleValue, MutableHandleValue};
use js::rust::wrappers::{JS_GetProperty, Construct1, JS_SameValue};
use microtask::Microtask;
use script_thread::ScriptThread;
Expand Down Expand Up @@ -607,7 +607,7 @@ impl CustomElementReaction {
CustomElementReaction::Upgrade(ref definition) => upgrade_element(definition.clone(), element),
CustomElementReaction::Callback(ref callback, ref arguments) => {
// We're rooted, so it's safe to hand out a handle to objects in Heap
let arguments = arguments.iter().map(|arg| unsafe { arg.handle() }).collect();
let arguments = arguments.iter().map(|arg| unsafe { HandleValue::from_raw(arg.handle()) }).collect();
let _ = callback.Call_(&*element, arguments, ExceptionHandling::Report);
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl History {
PopStateEvent::dispatch_jsval(
self.window.upcast::<EventTarget>(),
&*self.window,
unsafe { self.state.handle() }
unsafe { HandleValue::from_raw(self.state.handle()) }
);
}

Expand Down
6 changes: 4 additions & 2 deletions components/script/dom/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ unsafe extern fn native_handler_callback(cx: *mut JSContext, argc: u32, vp: *mut

rooted!(in(cx) let v = *GetFunctionNativeReserved(args.callee(), SLOT_NATIVEHANDLER_TASK));
match v.to_int32() {
v if v == NativeHandlerTask::Resolve as i32 => handler.resolved_callback(cx, args.get(0)),
v if v == NativeHandlerTask::Reject as i32 => handler.rejected_callback(cx, args.get(0)),
v if v == NativeHandlerTask::Resolve as i32 =>
handler.resolved_callback(cx, HandleValue::from_raw(args.get(0))),
v if v == NativeHandlerTask::Reject as i32 =>
handler.rejected_callback(cx, HandleValue::from_raw(args.get(0))),
_ => panic!("unexpected native handler task value"),
};

Expand Down
2 changes: 1 addition & 1 deletion components/script/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,6 @@ impl JsTimerTask {
// always done via rooted JsTimers, which is safe.
#[allow(unsafe_code)]
fn collect_heap_args<'b>(&self, args: &'b [Heap<JSVal>]) -> Vec<HandleValue<'b>> {
args.iter().map(|arg| unsafe { arg.handle() }).collect()
args.iter().map(|arg| unsafe { HandleValue::from_raw(arg.handle()) }).collect()
}
}
3 changes: 3 additions & 0 deletions python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,16 @@ def package_dir(package):
return path.join(msvc_deps_dir, package, msvc_deps[package])

extra_path += [path.join(package_dir("cmake"), "bin")]
extra_path += [path.join(package_dir("llvm"), "bin")]
extra_path += [path.join(package_dir("ninja"), "bin")]
# Link openssl
env["OPENSSL_INCLUDE_DIR"] = path.join(package_dir("openssl"), "include")
env["OPENSSL_LIB_DIR"] = path.join(package_dir("openssl"), "lib" + msvc_x64)
env["OPENSSL_LIBS"] = "libsslMD:libcryptoMD"
# Link moztools
env["MOZTOOLS_PATH"] = path.join(package_dir("moztools"), "bin")
# Link LLVM
env["LIBCLANG_PATH"] = path.join(package_dir("llvm"), "lib")

if is_windows():
if not os.environ.get("NATIVE_WIN32_PYTHON"):
Expand Down
1 change: 1 addition & 0 deletions python/servo/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

WINDOWS_MSVC = {
"cmake": "3.7.2",
"llvm": "4.0.0",
"moztools": "0.0.1-5",
"ninja": "1.7.1",
"openssl": "1.1.0e-vs2015",
Expand Down

0 comments on commit 0f8bacc

Please sign in to comment.