[gjs/wip/ptomato/mozjs31: 21/21] WIP - stuff
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31: 21/21] WIP - stuff
- Date: Fri, 28 Oct 2016 04:07:18 +0000 (UTC)
commit 0f8bbbb207c4fff69a7d65b490d01191bf671693
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Oct 5 21:44:25 2016 -0700
WIP - stuff
gi/arg.cpp | 28 +++++++-------
gi/boxed.cpp | 9 ++---
gi/enumeration.cpp | 7 +---
gi/function.cpp | 19 +++-------
gjs/byteArray.cpp | 31 +++++++---------
gjs/context.cpp | 9 ++---
gjs/coverage.cpp | 85 +++++++++++++++++--------------------------
gjs/importer.cpp | 48 +++++++++++--------------
gjs/jsapi-dynamic-class.cpp | 14 ++++---
gjs/jsapi-util-args.h | 3 +-
gjs/jsapi-util-error.cpp | 9 +++--
gjs/jsapi-util-string.cpp | 2 +-
gjs/jsapi-util.cpp | 30 +++++++--------
gjs/jsapi-util.h | 2 +-
gjs/stack.cpp | 3 +-
15 files changed, 131 insertions(+), 168 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 6171a4d..a9b8a11 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -287,7 +287,7 @@ gjs_array_to_g_list(JSContext *context,
GArgument elem_arg = { 0 };
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array, i, elem.address())) {
+ if (!JS_GetElement(context, array, i, &elem)) {
gjs_throw(context,
"Missing array element %u",
i);
@@ -372,7 +372,7 @@ gjs_object_to_g_hash(JSContext *context,
while (!JSID_IS_VOID(prop_id)) {
GArgument key_arg = { 0 }, val_arg = { 0 };
- if (!JS_IdToValue(context, prop_id, key_js.address()))
+ if (!JS_IdToValue(context, prop_id, &key_js))
goto free_hash_and_fail;
/* Type check key type. */
@@ -383,7 +383,7 @@ gjs_object_to_g_hash(JSContext *context,
&key_arg))
goto free_hash_and_fail;
- if (!JS_GetPropertyById(context, props, prop_id, val_js.address()))
+ if (!JS_GetPropertyById(context, props, prop_id, &val_js))
goto free_hash_and_fail;
/* Type check and convert value to a c type */
@@ -447,7 +447,7 @@ gjs_array_to_strv(JSContext *context,
for (i = 0; i < length; ++i) {
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array, i, elem.address())) {
+ if (!JS_GetElement(context, array, i, &elem)) {
g_free(result);
gjs_throw(context,
"Missing array element %u",
@@ -529,7 +529,7 @@ gjs_array_to_gboolean_array(JSContext *cx,
gboolean *result = g_new0(gboolean, length);
for (i = 0; i < length; i++) {
- if (!JS_GetElement(cx, array, i, elem.address())) {
+ if (!JS_GetElement(cx, array, i, &elem)) {
g_free(result);
gjs_throw(cx, "Missing array element %u", i);
return false;
@@ -564,7 +564,7 @@ gjs_array_to_intarray(JSContext *context,
bool success;
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array, i, elem.address())) {
+ if (!JS_GetElement(context, array, i, &elem)) {
g_free(result);
gjs_throw(context,
"Missing array element %u",
@@ -621,7 +621,7 @@ gjs_gtypearray_to_array(JSContext *context,
GType gtype;
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array, i, elem.address())) {
+ if (!JS_GetElement(context, array, i, &elem)) {
g_free(result);
gjs_throw(context, "Missing array element %u", i);
return false;
@@ -668,7 +668,7 @@ gjs_array_to_floatarray(JSContext *context,
bool success;
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array, i, elem.address())) {
+ if (!JS_GetElement(context, array, i, &elem)) {
g_free(result);
gjs_throw(context,
"Missing array element %u",
@@ -724,7 +724,7 @@ gjs_array_to_ptrarray(JSContext *context,
bool success;
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array_obj, i, elem.address())) {
+ if (!JS_GetElement(context, array_obj, i, &elem)) {
g_free(array);
gjs_throw(context,
"Missing array element %u",
@@ -770,7 +770,7 @@ gjs_array_to_flat_gvalue_array(JSContext *context,
for (i = 0; i < length; i ++) {
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, array, i, elem.address())) {
+ if (!JS_GetElement(context, array, i, &elem)) {
g_free(values);
gjs_throw(context,
"Missing array element %u",
@@ -811,7 +811,7 @@ gjs_array_from_flat_gvalue_array(JSContext *context,
if (result) {
JSObject *jsarray;
- jsarray = JS_NewArrayObject(context, length, elems.begin());
+ jsarray = JS_NewArrayObject(context, elems);
value.setObjectOrNull(jsarray);
}
@@ -2380,7 +2380,8 @@ gjs_object_from_g_hash (JSContext *context,
return true;
}
- JS::RootedObject obj(context, JS_NewObject(context, NULL, NULL, NULL));
+ JS::RootedObject obj(context,
+ JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
if (obj == NULL)
return false;
@@ -2411,8 +2412,7 @@ gjs_object_from_g_hash (JSContext *context,
true))
goto out;
- if (!JS_DefineProperty(context, obj, keyutf8, valjs,
- NULL, NULL, JSPROP_ENUMERATE))
+ if (!JS_DefineProperty(context, obj, keyutf8, valjs, JSPROP_ENUMERATE))
goto out;
g_free(keyutf8);
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 8b65204..fa11d9a 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -440,7 +440,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(boxed)
"boxed constructor, obj %p priv %p",
object.get(), priv);
- JS_GetPrototype(context, object, proto.address());
+ JS_GetPrototype(context, object, &proto);
gjs_debug_lifecycle(GJS_DEBUG_GBOXED, "boxed instance __proto__ is %p",
proto.get());
/* If we're the prototype, then post-construct we'll fill in priv->info.
@@ -862,8 +862,8 @@ define_boxed_class_fields (JSContext *context,
bool result;
result = JS_DefineProperty(context, proto, field_name, JS::NullHandleValue,
- boxed_field_getter, boxed_field_setter,
- JSPROP_PERMANENT | JSPROP_SHARED);
+ JSPROP_PERMANENT | JSPROP_SHARED,
+ boxed_field_getter, boxed_field_setter);
g_base_info_unref ((GIBaseInfo *)field);
@@ -919,7 +919,6 @@ struct JSClass gjs_boxed_class = {
(JSResolveOp) boxed_new_resolve, /* needs cast since it's the new resolve signature */
JS_ConvertStub,
boxed_finalize,
- NULL, /* checkAccess */
NULL, /* call */
NULL, /* hasInstance */
NULL, /* construct */
@@ -1176,7 +1175,7 @@ gjs_define_boxed_class(JSContext *context,
JS::RootedValue value(context,
JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, priv->gtype)));
JS_DefineProperty(context, constructor, "$gtype", value,
- NULL, NULL, JSPROP_PERMANENT);
+ JSPROP_PERMANENT);
}
JSObject*
diff --git a/gi/enumeration.cpp b/gi/enumeration.cpp
index 1b2361c..051ffa2 100644
--- a/gi/enumeration.cpp
+++ b/gi/enumeration.cpp
@@ -68,7 +68,6 @@ gjs_define_enum_value(JSContext *context,
JS::RootedValue value_js(context, JS::NumberValue(value_val));
if (!JS_DefineProperty(context, in_object,
fixed_name, value_js,
- NULL, NULL,
GJS_MODULE_PROP_FLAGS)) {
gjs_throw(context, "Unable to define enumeration value %s %" G_GINT64_FORMAT " (no memory most
likely)",
fixed_name, value_val);
@@ -108,8 +107,7 @@ gjs_define_enum_values(JSContext *context,
gtype = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*)info);
JS::RootedValue value(context,
JS::ObjectOrNullValue(gjs_gtype_create_gtype_wrapper(context, gtype)));
- JS_DefineProperty(context, in_object, "$gtype", value,
- NULL, NULL, JSPROP_PERMANENT);
+ JS_DefineProperty(context, in_object, "$gtype", value, JSPROP_PERMANENT);
return true;
}
@@ -168,7 +166,7 @@ gjs_define_enumeration(JSContext *context,
enum_name = g_base_info_get_name( (GIBaseInfo*) info);
- JS::RootedObject enum_obj(context, JS_NewObject(context, NULL, NULL,
+ JS::RootedObject enum_obj(context, JS_NewObject(context, NULL, JS::NullPtr(),
global));
if (enum_obj == NULL) {
g_error("Could not create enumeration %s.%s",
@@ -191,7 +189,6 @@ gjs_define_enumeration(JSContext *context,
JS::RootedValue v_enum(context, JS::ObjectValue(*enum_obj));
if (!JS_DefineProperty(context, in_object, enum_name, v_enum,
- NULL, NULL,
GJS_MODULE_PROP_FLAGS)) {
gjs_throw(context, "Unable to define enumeration property (no memory most likely)");
return false;
diff --git a/gi/function.cpp b/gi/function.cpp
index 98d7280..6aca94a 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -87,7 +87,7 @@ gjs_callback_trampoline_unref(GjsCallbackTrampoline *trampoline)
if (!trampoline->is_vfunc) {
JS_BeginRequest(context);
- JS_RemoveValueRoot(context, trampoline->js_function.unsafeGet());
+ JS::RemoveValueRoot(context, &trampoline->js_function);
JS_EndRequest(context);
}
@@ -453,7 +453,7 @@ gjs_callback_trampoline_new(JSContext *context,
g_base_info_ref((GIBaseInfo*)trampoline->info);
trampoline->js_function = function;
if (!is_vfunc)
- JS_AddValueRoot(context, trampoline->js_function.unsafeGet());
+ JS::AddValueRoot(context, &trampoline->js_function);
/* Analyze param types and directions, similarly to init_cached_function_data */
n_args = g_callable_info_get_n_args(trampoline->info);
@@ -1277,9 +1277,7 @@ release:
*js_rval = return_values[0];
} else {
JSObject *array;
- array = JS_NewArrayObject(context,
- function->js_out_argc,
- &return_values[0]);
+ array = JS_NewArrayObject(context, return_values);
if (array == NULL) {
failed = true;
} else {
@@ -1476,9 +1474,7 @@ struct JSClass gjs_function_class = {
JS_ResolveStub,
JS_ConvertStub,
function_finalize,
- NULL,
- function_call,
- NULL, NULL, NULL
+ function_call
};
JSPropertySpec gjs_function_proto_props[] = {
@@ -1694,7 +1690,7 @@ function_new(JSContext *context,
}
JS::RootedObject function(context,
- JS_NewObject(context, &gjs_function_class, NULL, global));
+ JS_NewObject(context, &gjs_function_class, JS::NullPtr(), global));
if (function == NULL) {
gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to construct function");
return NULL;
@@ -1746,10 +1742,7 @@ gjs_define_function(JSContext *context,
g_assert_not_reached ();
}
- /* COMPAT: JS_DefineProperty is overloaded to take JS::HandleObject in 31 */
- JS::RootedValue v_function(context, JS::ObjectValue(*function));
- if (!JS_DefineProperty(context, in_object, name, v_function,
- NULL, NULL,
+ if (!JS_DefineProperty(context, in_object, name, function,
GJS_MODULE_PROP_FLAGS)) {
gjs_debug(GJS_DEBUG_GFUNCTION, "Failed to define function");
function = NULL;
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index a27825b..18a8736 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -64,8 +64,7 @@ struct JSClass gjs_byte_array_class = {
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
- byte_array_finalize,
- JSCLASS_NO_OPTIONAL_MEMBERS
+ byte_array_finalize
};
bool
@@ -201,7 +200,7 @@ byte_array_get_prop(JSContext *context,
return true; /* prototype, not an instance. */
JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address()))
+ if (!JS_IdToValue(context, id, &id_value))
return false;
/* First handle array indexing */
@@ -251,9 +250,7 @@ byte_array_length_setter(JSContext *context,
byte_array_ensure_array(priv);
- // COMPAT: Indexing JS::CallArgs should provide a handle in mozjs31
- JS::RootedValue arg(context, args[0]);
- if (!gjs_value_to_gsize(context, arg, &len)) {
+ if (!gjs_value_to_gsize(context, args[0], &len)) {
gjs_throw(context,
"Can't set ByteArray length to non-integer");
return false;
@@ -310,7 +307,7 @@ byte_array_set_prop(JSContext *context,
return true; /* prototype, not an instance. */
JS::RootedValue id_value(context);
- if (!JS_IdToValue(context, id, id_value.address()))
+ if (!JS_IdToValue(context, id, &id_value))
return false;
/* First handle array indexing */
@@ -534,9 +531,9 @@ byte_array_new(JSContext *context)
{
ByteArrayInstance *priv;
+ JS::RootedObject proto(context, byte_array_get_prototype(context));
JS::RootedObject array(context,
- JS_NewObject(context, &gjs_byte_array_class,
- byte_array_get_prototype(context), NULL));
+ JS_NewObject(context, &gjs_byte_array_class, proto, JS::NullPtr()));
priv = g_slice_new0(ByteArrayInstance);
@@ -664,13 +661,14 @@ from_array_func(JSContext *context,
priv->array = gjs_g_byte_array_new(0);
- if (!JS_IsArrayObject(context, &argv[0].toObject())) {
+ JS::RootedObject array_obj(context, &argv[0].toObject());
+ if (!JS_IsArrayObject(context, array_obj)) {
gjs_throw(context,
"byteArray.fromArray() called with non-array as first arg");
return false;
}
- if (!JS_GetArrayLength(context, &argv[0].toObject(), &len)) {
+ if (!JS_GetArrayLength(context, array_obj, &len)) {
gjs_throw(context,
"byteArray.fromArray() can't get length of first array arg");
return false;
@@ -683,7 +681,7 @@ from_array_func(JSContext *context,
guint8 b;
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, &argv[0].toObject(), i, elem.address())) {
+ if (!JS_GetElement(context, array_obj, i, &elem)) {
/* this means there was an exception, while elem.isUndefined()
* means no element found
*/
@@ -743,9 +741,9 @@ gjs_byte_array_from_byte_array (JSContext *context,
g_return_val_if_fail(context != NULL, NULL);
g_return_val_if_fail(array != NULL, NULL);
+ JS::RootedObject proto(context, byte_array_get_prototype(context));
JS::RootedObject object(context,
- JS_NewObject(context, &gjs_byte_array_class,
- byte_array_get_prototype(context), NULL));
+ JS_NewObject(context, &gjs_byte_array_class, proto, JS::NullPtr()));
if (!object) {
gjs_throw(context, "failed to create byte array");
return NULL;
@@ -832,10 +830,9 @@ gjs_define_byte_array_stuff(JSContext *context,
{
JSObject *prototype;
- module.set(JS_NewObject(context, NULL, NULL, NULL));
+ module.set(JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr()));
- prototype = JS_InitClass(context, module,
- NULL,
+ prototype = JS_InitClass(context, module, JS::NullPtr(),
&gjs_byte_array_class,
gjs_byte_array_constructor,
0,
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 7c730b7..29ef9ad 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -172,8 +172,7 @@ gjs_log_error(JSContext *context,
JS_RestoreExceptionState(context, exc_state);
}
- /* COMPAT: JS::CallArgs::operator[] will yield Handle in mozjs31 */
- gjs_log_exception_full(context, argv.handleOrUndefinedAt(0), jstr);
+ gjs_log_exception_full(context, argv[0], jstr);
JS_EndRequest(context);
argv.rval().setUndefined();
@@ -441,7 +440,6 @@ gjs_context_constructed(GObject *object)
JS::RootedValue v_global(js_context->context, JS::ObjectValue(*global));
if (!JS_DefineProperty(js_context->context, global,
"window", v_global,
- NULL, NULL,
JSPROP_READONLY | JSPROP_PERMANENT))
g_error("No memory to export global object as 'window'");
@@ -721,8 +719,9 @@ gjs_context_define_string_array(GjsContext *js_context,
GError **error)
{
JSAutoCompartment ac(js_context->context, js_context->global);
+ JS::RootedObject global_root(js_context->context, js_context->global);
if (!gjs_define_string_array(js_context->context,
- js_context->global,
+ global_root,
array_name, array_length, array_values,
JSPROP_READONLY | JSPROP_PERMANENT)) {
gjs_log_exception(js_context->context);
@@ -767,7 +766,7 @@ gjs_object_get_property_const(JSContext *cx,
JS::MutableHandleValue value_p)
{
JS::RootedId pname(cx, gjs_context_get_const_string(cx, property_name));
- return JS_GetPropertyById(cx, obj, pname, value_p.address());
+ return JS_GetPropertyById(cx, obj, pname, value_p);
}
/**
diff --git a/gjs/coverage.cpp b/gjs/coverage.cpp
index ec2ad31..47be2da 100644
--- a/gjs/coverage.cpp
+++ b/gjs/coverage.cpp
@@ -406,8 +406,7 @@ get_array_from_js_value(JSContext *context,
g_return_val_if_fail(out_array != NULL, false);
g_return_val_if_fail(*out_array == NULL, false);
- JS::RootedObject js_array(context, &value.toObject());
- if (!JS_IsArrayObject(context, js_array)) {
+ if (!JS_IsArrayObject(context, value)) {
g_critical("Returned object from is not an array");
return false;
}
@@ -417,6 +416,7 @@ get_array_from_js_value(JSContext *context,
* preallocate to. */
GArray *c_side_array = g_array_new(true, true, array_element_size);
u_int32_t js_array_len;
+ JS::RootedObject js_array(context, &value.toObject());
if (element_clear_func)
g_array_set_clear_func(c_side_array, element_clear_func);
@@ -425,7 +425,7 @@ get_array_from_js_value(JSContext *context,
u_int32_t i = 0;
JS::RootedValue element(context);
for (; i < js_array_len; ++i) {
- if (!JS_GetElement(context, js_array, i, element.address())) {
+ if (!JS_GetElement(context, js_array, i, &element)) {
g_array_unref(c_side_array);
gjs_throw(context, "Failed to get function names array element %d", i);
return false;
@@ -472,12 +472,11 @@ get_executed_lines_for(JSContext *context,
{
GArray *array = NULL;
JS::RootedValue rval(context);
+ JS::AutoValueArray<1> args(context);
+ args[0].set(filename_value);
- /* Removing const with cast is OK because the function arguments are not
- * mutated in JS_CallFunction */
if (!JS_CallFunctionName(context, coverage_statistics, "getExecutedLinesFor",
- 1, (JS::Value *) filename_value.address(),
- rval.address())) {
+ args, &rval)) {
gjs_log_exception(context);
return NULL;
}
@@ -585,12 +584,11 @@ get_functions_for(JSContext *context,
{
GArray *array = NULL;
JS::RootedValue rval(context);
+ JS::AutoValueArray<1> args(context);
+ args[0].set(filename_value);
- /* Removing const with cast is OK because the function arguments are not
- * mutated in JS_CallFunction */
if (!JS_CallFunctionName(context, coverage_statistics, "getFunctionsFor",
- 1, (JS::Value *) filename_value.address(),
- rval.address())) {
+ args, &rval)) {
gjs_log_exception(context);
return NULL;
}
@@ -680,7 +678,7 @@ convert_and_insert_branch_info(GArray *array,
JS::RootedValue branch_exits_value(context);
GArray *branch_exits_array = NULL;
- if (!JS_GetProperty(context, object, "exits", branch_exits_value.address()) ||
+ if (!JS_GetProperty(context, object, "exits", &branch_exits_value) ||
!branch_exits_value.isObject()) {
gjs_throw(context, "Failed to get exits property from element");
return false;
@@ -714,13 +712,12 @@ get_branches_for(JSContext *context,
JS::HandleValue filename_value)
{
GArray *array = NULL;
+ JS::AutoValueArray<1> args(context);
+ args[0].set(filename_value);
JS::RootedValue rval(context);
- /* Removing const with cast is OK because the function arguments are not
- * mutated in JS_CallFunction */
if (!JS_CallFunctionName(context, coverage_statistics, "getBranchesFor",
- 1, (JS::Value *) filename_value.address(),
- rval.address())) {
+ args, &rval)) {
gjs_log_exception(context);
return NULL;
}
@@ -855,7 +852,7 @@ get_covered_files(GjsCoverage *coverage)
uint32_t n_files;
if (!JS_CallFunctionName(context, rooted_priv, "getCoveredFiles",
- 0, NULL, rval.address())) {
+ JS::HandleValueArray::empty(), &rval)) {
gjs_log_exception(context);
return NULL;
}
@@ -871,7 +868,7 @@ get_covered_files(GjsCoverage *coverage)
JS::RootedValue element(context);
for (uint32_t i = 0; i < n_files; i++) {
char *file;
- if (!JS_GetElement(context, files_obj, i, element.address()))
+ if (!JS_GetElement(context, files_obj, i, &element))
goto error;
if (!gjs_string_to_utf8(context, element, &file))
@@ -1013,9 +1010,8 @@ gjs_serialize_statistics(GjsCoverage *coverage)
JS::RootedValue string_value_return(js_runtime);
if (!JS_CallFunctionName(js_context, rooted_priv, "stringify",
- 0,
- NULL,
- string_value_return.address())) {
+ JS::HandleValueArray::empty(),
+ &string_value_return)) {
gjs_log_exception(js_context);
return NULL;
}
@@ -1169,9 +1165,8 @@ coverage_statistics_has_stale_cache(GjsCoverage *coverage)
JS::RootedObject rooted_priv(js_context, priv->coverage_statistics);
JS::RootedValue stale_cache_value(js_context);
if (!JS_CallFunctionName(js_context, rooted_priv, "staleCache",
- 0,
- NULL,
- stale_cache_value.address())) {
+ JS::HandleValueArray::empty(),
+ &stale_cache_value)) {
gjs_log_exception(js_context);
g_error("Failed to call into javascript to get stale cache value. This is a bug");
}
@@ -1258,8 +1253,7 @@ gjs_coverage_init(GjsCoverage *self)
static JSClass coverage_global_class = {
"GjsCoverageGlobal", JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
- JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
- JSCLASS_NO_OPTIONAL_MEMBERS
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
};
static bool
@@ -1379,8 +1373,7 @@ coverage_get_file_modification_time(JSContext *context,
goto out;
if (gjs_get_path_mtime(filename, &mtime)) {
- JS::RootedObject mtime_values_array(runtime,
- JS_NewArrayObject(context, 0, NULL));
+ JS::RootedObject mtime_values_array(runtime, JS_NewArrayObject(context, 0));
if (!JS_DefineElement(context, mtime_values_array, 0, JS::Int32Value(mtime.tv_sec), NULL, NULL, 0))
goto out;
if (!JS_DefineElement(context, mtime_values_array, 1, JS::Int32Value(mtime.tv_usec), NULL, NULL, 0))
@@ -1494,10 +1487,8 @@ gjs_run_script_in_coverage_compartment(GjsCoverage *coverage,
JSContext *js_context = (JSContext *) gjs_context_get_native_context(priv->context);
JSAutoCompartment ac(js_context, priv->coverage_statistics);
JS::RootedValue rval(js_context);
- if (!gjs_eval_with_scope(js_context,
- priv->coverage_statistics,
- script,
- strlen(script),
+ JS::RootedObject rooted_priv(js_context, priv->coverage_statistics);
+ if (!gjs_eval_with_scope(js_context, rooted_priv, script, strlen(script),
"<coverage_modifier>",
&rval)) {
gjs_log_exception(js_context);
@@ -1522,10 +1513,7 @@ gjs_inject_value_into_coverage_compartment(GjsCoverage *coverage,
JS::RootedObject coverage_global_scope(JS_GetRuntime(js_context),
JS_GetGlobalForObject(js_context, priv->coverage_statistics));
- /* Removing const with cast is OK because the property value is not
- * mutated in JS_SetProperty */
- if (!JS_SetProperty(js_context, coverage_global_scope, property,
- (JS::Value *) value.address())) {
+ if (!JS_SetProperty(js_context, coverage_global_scope, property, value)) {
g_warning("Failed to set property %s to requested value", property);
return false;
}
@@ -1549,7 +1537,7 @@ gjs_wrap_root_importer_in_compartment(JSContext *context,
JS::RootedObject wrapped_importer(JS_GetRuntime(context),
importer.toObjectOrNull());
- if (!JS_WrapObject(context, wrapped_importer.address())) {
+ if (!JS_WrapObject(context, &wrapped_importer)) {
return NULL;
}
@@ -1571,20 +1559,19 @@ bootstrap_coverage(GjsCoverage *coverage)
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
JS::RootedObject debugger_compartment(JS_GetRuntime(context),
- JS_NewGlobalObject(context, &coverage_global_class, NULL,
options));
+ JS_NewGlobalObject(context, &coverage_global_class, NULL,
+ JS::FireOnNewGlobalHook, options));
{
JSAutoCompartment compartment(context, debugger_compartment);
JS::RootedObject debuggeeWrapper(context, debuggee);
- if (!JS_WrapObject(context, debuggeeWrapper.address())) {
+ if (!JS_WrapObject(context, &debuggeeWrapper)) {
gjs_throw(context, "Failed to wrap debugeee");
return false;
}
JS::RootedValue debuggeeWrapperValue(context, JS::ObjectValue(*debuggeeWrapper));
- /* Removing const with cast is OK because the property value is not
- * mutated in JS_SetProperty */
if (!JS_SetProperty(context, debugger_compartment, "debuggee",
- (JS::Value *) debuggeeWrapperValue.address())) {
+ debuggeeWrapperValue)) {
gjs_throw(context, "Failed to set debuggee property");
return false;
}
@@ -1660,15 +1647,13 @@ bootstrap_coverage(GjsCoverage *coverage)
/* Now create the array to pass the desired prefixes over */
JSObject *prefixes = gjs_build_string_array(context, -1, priv->prefixes);
- JS::Value coverage_statistics_constructor_arguments[] = {
- JS::ObjectValue(*prefixes),
- cache_value.get()
- };
+ JS::AutoValueArray<2> coverage_statistics_constructor_args(context);
+ coverage_statistics_constructor_args[0].setObject(*prefixes);
+ coverage_statistics_constructor_args[1].set(cache_value);
JSObject *coverage_statistics = JS_New(context,
coverage_statistics_constructor,
- 2,
- coverage_statistics_constructor_arguments);
+ coverage_statistics_constructor_args);
if (!coverage_statistics) {
gjs_throw(context, "Failed to create coverage_statitiscs object");
@@ -1746,9 +1731,7 @@ gjs_clear_js_side_statistics_from_coverage_object(GjsCoverage *coverage)
JS::RootedObject rooted_priv(js_context, priv->coverage_statistics);
JS::RootedValue rval(JS_GetRuntime(js_context));
if (!JS_CallFunctionName(js_context, rooted_priv, "deactivate",
- 0,
- NULL,
- rval.address())) {
+ JS::HandleValueArray::empty(), &rval)) {
gjs_log_exception(js_context);
g_error("Failed to deactivate debugger - this is a fatal error");
}
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 09e2b52..eadd80d 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -74,7 +74,6 @@ define_meta_properties(JSContext *context,
JS::RootedValue file_val(context,
JS::StringValue(JS_NewStringCopyZ(context, full_path)));
if (!JS_DefineProperty(context, module_obj, "__file__", file_val,
- NULL, NULL,
/* don't set ENUMERATE since we wouldn't want to copy
* this symbol to any other object for example.
*/
@@ -91,7 +90,6 @@ define_meta_properties(JSContext *context,
if (!JS_DefineProperty(context, module_obj,
"__moduleName__", module_name_val,
- NULL, NULL,
/* don't set ENUMERATE since we wouldn't want to copy
* this symbol to any other object for example.
*/
@@ -100,7 +98,6 @@ define_meta_properties(JSContext *context,
if (!JS_DefineProperty(context, module_obj,
"__parentModule__", parent_module_val,
- NULL, NULL,
/* don't set ENUMERATE since we wouldn't want to copy
* this symbol to any other object for example.
*/
@@ -138,7 +135,6 @@ define_import(JSContext *context,
{
JS::RootedValue module_val(context, JS::ObjectValue(*module_obj));
if (!JS_DefineProperty(context, obj, name, module_val,
- NULL, NULL,
GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"Failed to define '%s' in importer",
@@ -242,13 +238,13 @@ import_native_file(JSContext *context,
JS::RootedValue v_module(context, JS::ObjectValue(*module_obj));
return JS_DefineProperty(context, obj, name, v_module,
- NULL, NULL, GJS_MODULE_PROP_FLAGS);
+ GJS_MODULE_PROP_FLAGS);
}
static JSObject *
create_module_object(JSContext *context)
{
- return JS_NewObject(context, NULL, NULL, NULL);
+ return JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr());
}
static bool
@@ -264,6 +260,7 @@ import_file(JSContext *context,
GError *error = NULL;
JS::CompileOptions options(context);
+ JS::RootedValue ignored(context);
if (!(g_file_load_contents(file, NULL, &script, &script_len, NULL, &error))) {
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY) &&
@@ -281,7 +278,7 @@ import_file(JSContext *context,
full_path = g_file_get_parse_name (file);
if (!gjs_eval_with_scope(context, module_obj, script, script_len,
- full_path, NULL))
+ full_path, &ignored))
goto out;
ret = true;
@@ -305,10 +302,8 @@ load_module_init(JSContext *context,
gjs_context_get_const_string(context, GJS_STRING_MODULE_INIT));
if (JS_HasPropertyById(context, in_object, module_init_name, &found) && found) {
JS::RootedValue module_obj_val(context);
- if (JS_GetPropertyById(context,
- in_object,
- module_init_name,
- module_obj_val.address())) {
+ if (JS_GetPropertyById(context, in_object,
+ module_init_name, &module_obj_val)) {
return &module_obj_val.toObject();
}
}
@@ -458,7 +453,7 @@ do_import(JSContext *context,
for (i = 0; i < search_path_len; ++i) {
elem.setUndefined();
- if (!JS_GetElement(context, search_path, i, elem.address())) {
+ if (!JS_GetElement(context, search_path, i, &elem)) {
/* this means there was an exception, while elem.isUndefined()
* means no element found
*/
@@ -492,14 +487,9 @@ do_import(JSContext *context,
module_obj.set(load_module_init(context, obj, full_path));
if (module_obj != NULL) {
JS::RootedValue obj_val(context);
- if (JS_GetProperty(context,
- module_obj,
- name,
- obj_val.address())) {
+ if (JS_GetProperty(context, module_obj, name, &obj_val)) {
if (!obj_val.isUndefined() &&
- JS_DefineProperty(context, obj,
- name, obj_val,
- NULL, NULL,
+ JS_DefineProperty(context, obj, name, obj_val,
GJS_MODULE_PROP_FLAGS & ~JSPROP_PERMANENT)) {
result = true;
goto out;
@@ -697,7 +687,7 @@ importer_new_enumerate(JSContext *context,
GDir *dir = NULL;
elem = JS::UndefinedValue();
- if (!JS_GetElement(context, search_path, i, elem.address())) {
+ if (!JS_GetElement(context, search_path, i, &elem)) {
/* this means there was an exception, while elem.isUndefined()
* means no element found
*/
@@ -763,7 +753,13 @@ importer_new_enumerate(JSContext *context,
g_free(dirname);
}
- statep.get().setPrivate(iter);
+ /* FIXME: setPrivate() is not in js::MutableValueOperations (see
+ * Value.h) and now SpiderMonkey is stricter with const for
+ * Handle::get(); how to do this correctly? This code might allow
+ * statep_private to get GC'd before going into statep. */
+ JS::Value statep_private;
+ statep_private.setPrivate(iter);
+ statep.set(statep_private);
idp.set(INT_TO_JSID(iter->elements->len));
@@ -785,7 +781,7 @@ importer_new_enumerate(JSContext *context,
&element_val))
return false;
- if (!JS_ValueToId(context, element_val, idp.address()))
+ if (!JS_ValueToId(context, element_val, idp))
return false;
break;
@@ -901,8 +897,7 @@ struct JSClass gjs_importer_class = {
(JSEnumerateOp) importer_new_enumerate, /* needs cast since it's the new enumerate signature */
(JSResolveOp) importer_new_resolve, /* needs cast since it's the new resolve signature */
JS_ConvertStub,
- importer_finalize,
- JSCLASS_NO_OPTIONAL_MEMBERS
+ importer_finalize
};
JSPropertySpec gjs_importer_proto_props[] = {
@@ -932,7 +927,7 @@ importer_new(JSContext *context,
* prototype; NULL for
* Object.prototype
*/
- NULL,
+ JS::NullPtr(),
&gjs_importer_class,
/* constructor for instances (NULL for
* none - just name the prototype like
@@ -957,7 +952,7 @@ importer_new(JSContext *context,
}
JS::RootedObject importer(context,
- JS_NewObject(context, &gjs_importer_class, NULL, global));
+ JS_NewObject(context, &gjs_importer_class, JS::NullPtr(), global));
if (importer == NULL)
g_error("No memory to create importer importer");
@@ -1080,7 +1075,6 @@ gjs_define_importer(JSContext *context,
JS::RootedValue v_importer(context, JS::ObjectValue(*importer));
if (!JS_DefineProperty(context, in_object, importer_name, v_importer,
- NULL, NULL,
GJS_MODULE_PROP_FLAGS))
g_error("no memory to define importer property");
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 559cfec..9db3833 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -106,17 +106,19 @@ gjs_init_class_dynamic(JSContext *context,
if (static_fs && !JS_DefineFunctions(context, constructor, static_fs))
goto out;
- if (!JS_DefineProperty(context, constructor, "prototype", JS::ObjectValue(*prototype),
- JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT | JSPROP_READONLY))
+ if (!JS_DefineProperty(context, constructor, "prototype", prototype,
+ JSPROP_PERMANENT | JSPROP_READONLY,
+ JS_PropertyStub, JS_StrictPropertyStub))
goto out;
- if (!JS_DefineProperty(context, prototype, "constructor", JS::ObjectValue(*constructor),
- JS_PropertyStub, JS_StrictPropertyStub, 0))
+ if (!JS_DefineProperty(context, prototype, "constructor", constructor,
+ 0, JS_PropertyStub, JS_StrictPropertyStub))
goto out;
/* The constructor defined by JS_InitClass has no property attributes, but this
is a more useful default for gjs */
- if (!JS_DefineProperty(context, in_object, class_name, JS::ObjectValue(*constructor),
- JS_PropertyStub, JS_StrictPropertyStub, GJS_MODULE_PROP_FLAGS))
+ if (!JS_DefineProperty(context, in_object, class_name, constructor,
+ GJS_MODULE_PROP_FLAGS,
+ JS_PropertyStub, JS_StrictPropertyStub))
goto out;
res = true;
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 87f7901..3229350 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -246,8 +246,7 @@ parse_call_args_helper(JSContext *cx,
}
try {
- /* COMPAT: JS::CallArgs::operator[] will yield Handle in mozjs31 */
- assign(cx, *fchar, nullable, args.handleOrUndefinedAt(param_ix), param_ref);
+ assign(cx, *fchar, nullable, args[param_ix], param_ref);
} catch (char *message) {
/* Our error messages are going to be more useful than whatever was
* thrown by the various conversion functions */
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index 005f81c..bea2694 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -76,15 +76,16 @@ gjs_throw_valist(JSContext *context,
JS::RootedObject constructor(context);
JS::RootedObject global(context, JS::CurrentGlobalOrNull(context));
- JS::RootedValue v_constructor(context), v_message(context), new_exc(context);
+ JS::RootedValue v_constructor(context), new_exc(context);
+ JS::AutoValueArray<1> error_args(context);
result = false;
- if (!gjs_string_from_utf8(context, s, -1, &v_message)) {
+ if (!gjs_string_from_utf8(context, s, -1, error_args[0])) {
JS_ReportError(context, "Failed to copy exception string");
goto out;
}
- if (!JS_GetProperty(context, global, error_class, v_constructor.address()) ||
+ if (!JS_GetProperty(context, global, error_class, &v_constructor) ||
!v_constructor.isObject()) {
JS_ReportError(context, "??? Missing Error constructor in global object?");
goto out;
@@ -92,7 +93,7 @@ gjs_throw_valist(JSContext *context,
/* throw new Error(message) */
constructor = &v_constructor.toObject();
- new_exc.setObjectOrNull(JS_New(context, constructor, 1, v_message.address()));
+ new_exc.setObjectOrNull(JS_New(context, constructor, error_args));
JS_SetPendingException(context, new_exc);
result = true;
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 1707256..6143b47 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -313,7 +313,7 @@ gjs_get_string_id (JSContext *context,
{
JS::RootedValue id_val(context);
- if (!JS_IdToValue(context, id, id_val.address()))
+ if (!JS_IdToValue(context, id, &id_val))
return false;
if (id_val.isString()) {
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 1095f86..db643ff 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -47,8 +47,7 @@ gjs_util_error_quark (void)
static JSClass global_class = {
"GjsGlobal", JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(GJS_GLOBAL_SLOT_LAST),
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
- JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
- JSCLASS_NO_OPTIONAL_MEMBERS
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL
};
/**
@@ -92,7 +91,7 @@ gjs_init_context_standard (JSContext *context,
compartment_options.setVersion(JSVERSION_LATEST);
global.set(JS_NewGlobalObject(context, &global_class, NULL,
- compartment_options));
+ JS::FireOnNewGlobalHook, compartment_options));
if (global == NULL)
return false;
@@ -169,7 +168,7 @@ gjs_object_require_property(JSContext *context,
{
value.setUndefined();
- if (G_UNLIKELY(!JS_GetPropertyById(context, obj, property_name, value.address())))
+ if (G_UNLIKELY(!JS_GetPropertyById(context, obj, property_name, value)))
return false;
if (G_LIKELY(!value.isUndefined()))
@@ -188,7 +187,7 @@ gjs_object_require_property_value(JSContext *cx,
bool *value)
{
JS::RootedValue prop_value(cx);
- if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+ if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
prop_value.isBoolean()) {
*value = prop_value.toBoolean();
return true;
@@ -207,7 +206,7 @@ gjs_object_require_property_value(JSContext *cx,
int32_t *value)
{
JS::RootedValue prop_value(cx);
- if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+ if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
prop_value.isInt32()) {
*value = prop_value.toInt32();
return true;
@@ -227,7 +226,7 @@ gjs_object_require_property_value(JSContext *cx,
char **value)
{
JS::RootedValue prop_value(cx);
- if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+ if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
gjs_string_to_utf8(cx, prop_value, value)) {
return true;
}
@@ -245,7 +244,7 @@ gjs_object_require_property_value(JSContext *cx,
JS::MutableHandleObject value)
{
JS::RootedValue prop_value(cx);
- if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+ if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
prop_value.isObject()) {
value.set(&prop_value.toObject());
return true;
@@ -264,7 +263,7 @@ gjs_object_require_converted_property_value(JSContext *cx,
uint32_t *value)
{
JS::RootedValue prop_value(cx);
- if (JS_GetPropertyById(cx, obj, property_name, prop_value.address()) &&
+ if (JS_GetPropertyById(cx, obj, property_name, &prop_value) &&
JS::ToUint32(cx, prop_value, value)) {
return true;
}
@@ -318,7 +317,7 @@ gjs_build_string_array(JSContext *context,
elems.append(element);
}
- return JS_NewArrayObject(context, elems.length(), &elems[0]);
+ return JS_NewArrayObject(context, elems);
}
JSObject*
@@ -336,8 +335,7 @@ gjs_define_string_array(JSContext *context,
if (array != NULL) {
JS::RootedValue v_array(context, JS::ObjectValue(*array));
- if (!JS_DefineProperty(context, in_object, array_name, v_array,
- NULL, NULL, attrs))
+ if (!JS_DefineProperty(context, in_object, array_name, v_array, attrs))
array = NULL;
}
@@ -619,7 +617,7 @@ gjs_log_exception(JSContext *context)
JS_BeginRequest(context);
JS::RootedValue exc(context);
- if (!JS_GetPendingException(context, exc.address()))
+ if (!JS_GetPendingException(context, &exc))
goto out;
JS_ClearPendingException(context);
@@ -860,14 +858,14 @@ gjs_eval_with_scope(JSContext *context,
JS::RootedObject eval_obj(context, object);
if (!eval_obj)
- eval_obj = JS_NewObject(context, NULL, NULL, NULL);
+ eval_obj = JS_NewObject(context, NULL, JS::NullPtr(), JS::NullPtr());
JS::CompileOptions options(context);
options.setUTF8(true)
.setFileAndLine(filename, start_line_number)
- .setSourcePolicy(JS::CompileOptions::LAZY_SOURCE);
+ .setSourceIsLazy(true);
- if (!JS::Evaluate(context, eval_obj, options, script, script_len, retval.address()))
+ if (!JS::Evaluate(context, eval_obj, options, script, script_len, retval))
return false;
gjs_schedule_gc_if_needed(context);
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 0ed6b3f..5475e8d 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -267,7 +267,7 @@ gjs_##name##_constructor(JSContext *context, \
gjs_throw_constructor_error(context); \
return false; \
} \
- object = JS_NewObjectForConstructor(context, &gjs_##name##_class, vp); \
+ object = JS_NewObjectForConstructor(context, &gjs_##name##_class, argv); \
if (object == NULL) \
return false; \
}
diff --git a/gjs/stack.cpp b/gjs/stack.cpp
index c99201f..7dba9b1 100644
--- a/gjs/stack.cpp
+++ b/gjs/stack.cpp
@@ -63,7 +63,8 @@ gjs_context_get_frame_info(JSContext *context,
error_id, &constructor))
return false;
- JS::RootedObject err_obj(context, JS_New(context, constructor, 0, NULL));
+ JS::RootedObject err_obj(context, JS_New(context, constructor,
+ JS::HandleValueArray::empty()));
if (!stack.empty() &&
!gjs_object_get_property_const(context, err_obj, GJS_STRING_STACK,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]