From c268b7132e69bacd5dcf22b3268527e7d0c535b9 Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Mon, 21 Nov 2016 10:48:13 +0100 Subject: [PATCH] Add methods to create a HandleValueArray. Rust-mozjs currently does not define any methods to create instances of HandleValueArray. Consequently, consumers have to create these instances manually. This is unnecessary boilerplate, and therefore should be abstracted behind a function. --- src/rust.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/rust.rs b/src/rust.rs index 0c7520d82..5b4193fc7 100644 --- a/src/rust.rs +++ b/src/rust.rs @@ -20,8 +20,8 @@ use consts::{JSCLASS_RESERVED_SLOTS_MASK, JSCLASS_GLOBAL_SLOT_COUNT}; use consts::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use jsapi; use jsapi::{AutoIdVector, AutoObjectVector, CallArgs, CompartmentOptions, ContextFriendFields}; -use jsapi::{Evaluate2, Handle, HandleBase, HandleObject, HandleValue, Heap, HeapObjectPostBarrier}; -use jsapi::{HeapValuePostBarrier, InitSelfHostedCode, IsWindowSlow, JS_BeginRequest}; +use jsapi::{Evaluate2, Handle, HandleBase, HandleObject, HandleValue, HandleValueArray, Heap}; +use jsapi::{HeapObjectPostBarrier, HeapValuePostBarrier, InitSelfHostedCode, IsWindowSlow, JS_BeginRequest}; use jsapi::{JS_DefineFunctions, JS_DefineProperties, JS_DestroyRuntime, JS_EndRequest}; use jsapi::{JS_EnterCompartment, JS_EnumerateStandardClasses, JS_GetContext, JS_GlobalObjectTraceHook}; use jsapi::{JS_Init, JS_LeaveCompartment, JS_MayResolveStandardClass, JS_NewRuntime, JS_ResolveStandardClass}; @@ -495,6 +495,22 @@ impl HandleValue { } } +impl HandleValueArray { + pub fn new() -> HandleValueArray { + HandleValueArray { + length_: 0, + elements_: ptr::null(), + } + } + + pub unsafe fn from_rooted_slice(values: &[Value]) -> HandleValueArray { + HandleValueArray { + length_: values.len(), + elements_: values.as_ptr() + } + } +} + const ConstNullValue: *mut JSObject = 0 as *mut JSObject; impl HandleObject {