[gjs/wip/ptomato/mozjs38: 7/14] 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: 7/14] js: Adapt to new mozilla::Maybe API
- Date: Mon, 23 Jan 2017 23:21:53 +0000 (UTC)
commit 9978df860b121b214747f0d09769174a01c08587
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 0529309..ba5214f 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1018,7 +1018,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 */
@@ -1048,7 +1048,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,
@@ -1064,7 +1064,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,
@@ -1181,7 +1181,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;
@@ -1275,7 +1275,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 {
@@ -1325,8 +1325,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)
@@ -1777,7 +1776,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 f395547..1f6e22e 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -401,10 +401,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 7dba9b1..6b0be38 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_const(context, err_obj, GJS_STRING_STACK,
stack.ref()))
return false;
- if (!fileName.empty() &&
+ if (fileName &&
!gjs_object_get_property_const(context, err_obj, GJS_STRING_FILENAME,
fileName.ref()))
return false;
- if (!lineNumber.empty() &&
+ if (lineNumber &&
!gjs_object_get_property_const(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]