Make (dictionary)::empty() safe

It currently works by constructing from null (which will throw a runtime
error if there are non-defaultable members).

This changes it so that we no longer need a JSContext to construct this,
so it can be safely constructed. In the case of non-defaultable members,
this method simply does not exist.
This commit is contained in:
Manish Goregaokar 2018-07-06 11:14:44 -07:00
parent c90737e6c8
commit cceaede96a
2 changed files with 50 additions and 10 deletions

View file

@ -115,7 +115,7 @@ fn dict_return(cx: *mut JSContext,
mut result: MutableHandleObject,
done: bool,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyOrValueResult::empty(cx) };
let mut dict = IterableKeyOrValueResult::empty();
dict.done = done;
dict.value.set(value.get());
rooted!(in(cx) let mut dict_value = UndefinedValue());
@ -130,7 +130,7 @@ fn key_and_value_return(cx: *mut JSContext,
mut result: MutableHandleObject,
key: HandleValue,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };
let mut dict = IterableKeyAndValueResult::empty();
dict.done = false;
dict.value = Some(vec![key, value]
.into_iter()