[gjs/wip/ptomato/mozjs38: 22/28] js: Adapt to new mozilla::Maybe API
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs38: 22/28] js: Adapt to new mozilla::Maybe API
- Date: Wed, 25 Jan 2017 02:36:52 +0000 (UTC)
commit b7f2134ea4b8e6f18727987ffd9a3cdbda9d7ecd
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Jan 11 23:18:42 2017 -0800
js: Adapt to new mozilla::Maybe API
mozilla::Maybe now has a bool operator so we don't have to compare against
.empty(), and we can construct values with mozilla::Some(). The API is
still fairly verbose and will be improved even further in later
SpiderMonkey releases.
gi/function.cpp | 15 +++++++--------
gi/gerror.cpp | 7 +++----
gjs/stack.cpp | 12 ++++++------
3 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 478bf4f..6d1c338 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1028,7 +1028,7 @@ gjs_invoke_c_function(JSContext *context,
did_throw_gerror = false;
}
- if (!js_rval.empty())
+ if (js_rval)
js_rval.ref().setUndefined();
/* Only process return values if the function didn't throw */
@@ -1058,7 +1058,7 @@ gjs_invoke_c_function(JSContext *context,
&arg_type_info,
&out_arg_cvalues[array_length_pos],
true);
- if (!arg_failed && !js_rval.empty()) {
+ if (!arg_failed && js_rval) {
arg_failed = !gjs_value_from_explicit_array(context,
return_values[next_rval],
&return_info,
@@ -1074,7 +1074,7 @@ gjs_invoke_c_function(JSContext *context,
&return_gargument))
failed = true;
} else {
- if (!js_rval.empty())
+ if (js_rval)
arg_failed = !gjs_value_from_g_argument(context,
return_values[next_rval],
&return_info, &return_gargument,
@@ -1191,7 +1191,7 @@ release:
array_length_pos = g_type_info_get_array_length(&arg_type_info);
- if (!js_rval.empty()) {
+ if (js_rval) {
if (array_length_pos >= 0) {
GIArgInfo array_length_arg;
GITypeInfo array_length_type_info;
@@ -1285,7 +1285,7 @@ release:
* on its own, otherwise return a JavaScript array with
* [return value, out arg 1, out arg 2, ...]
*/
- if (!js_rval.empty()) {
+ if (js_rval) {
if (function->js_out_argc == 1) {
js_rval.ref().set(return_values[0]);
} else {
@@ -1335,8 +1335,7 @@ function_call(JSContext *context,
return true; /* we are the prototype, or have the wrong class */
/* COMPAT: mozilla::Maybe gains a much more usable API in future versions */
- mozilla::Maybe<JS::MutableHandleValue> m_retval;
- m_retval.construct(&retval);
+ auto m_retval = mozilla::Some<JS::MutableHandleValue>(&retval);
success = gjs_invoke_c_function(context, priv, object, js_argv, m_retval,
NULL);
if (success)
@@ -1787,7 +1786,7 @@ gjs_invoke_c_function_uncached(JSContext *context,
/* COMPAT: mozilla::Maybe gains a much more usable API in future versions */
mozilla::Maybe<JS::MutableHandleValue> m_rval;
- m_rval.construct(rval);
+ m_rval.emplace(rval);
result = gjs_invoke_c_function(context, &function, obj, args, m_rval, NULL);
uninit_cached_function_data (&function);
return result;
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 2902f0e..cc8875d 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -396,10 +396,9 @@ define_error_properties(JSContext *context,
{
JS::RootedValue stack(context), fileName(context), lineNumber(context);
/* COMPAT: mozilla::Maybe gains a much more usable API in future versions */
- mozilla::Maybe<JS::MutableHandleValue> m_stack, m_file, m_line;
- m_stack.construct(&stack);
- m_file.construct(&fileName);
- m_line.construct(&lineNumber);
+ auto m_stack = mozilla::Some<JS::MutableHandleValue>(&stack);
+ auto m_file = mozilla::Some<JS::MutableHandleValue>(&fileName);
+ auto m_line = mozilla::Some<JS::MutableHandleValue>(&lineNumber);
if (!gjs_context_get_frame_info(context, m_stack, m_file, m_line))
return;
diff --git a/gjs/stack.cpp b/gjs/stack.cpp
index 3dceac2..f1aa8aa 100644
--- a/gjs/stack.cpp
+++ b/gjs/stack.cpp
@@ -66,17 +66,17 @@ gjs_context_get_frame_info(JSContext *context,
JS::RootedObject err_obj(context, JS_New(context, constructor,
JS::HandleValueArray::empty()));
- if (!stack.empty() &&
+ if (stack &&
!gjs_object_get_property(context, err_obj, GJS_STRING_STACK,
stack.ref()))
return false;
- if (!fileName.empty() &&
+ if (fileName &&
!gjs_object_get_property(context, err_obj, GJS_STRING_FILENAME,
fileName.ref()))
return false;
- if (!lineNumber.empty() &&
+ if (lineNumber &&
!gjs_object_get_property(context, err_obj, GJS_STRING_LINE_NUMBER,
lineNumber.ref()))
return false;
@@ -95,9 +95,9 @@ gjs_context_print_stack_stderr(GjsContext *context)
/* Stderr is locale encoding, so we use string_to_filename here */
/* COMPAT: mozilla::Maybe gains a much more usable API in future versions */
- mozilla::Maybe<JS::MutableHandleValue> m_stack, m_file, m_line;
- m_stack.construct(&v_stack);
- if (!gjs_context_get_frame_info(cx, m_stack, m_file, m_line) ||
+ mozilla::Maybe<JS::MutableHandleValue> none,
+ m_stack = mozilla::Some<JS::MutableHandleValue>(&v_stack);
+ if (!gjs_context_get_frame_info(cx, m_stack, none, none) ||
!gjs_string_to_filename(cx, v_stack, &stack)) {
g_printerr("No stack trace available\n");
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]