[gjs/wip/ptomato/mozjs31: 8/8] WIP - stuff
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/mozjs31: 8/8] WIP - stuff
- Date: Wed, 26 Oct 2016 01:16:50 +0000 (UTC)
commit b78c0b0a19ab266a9c7ae2f398dfe876817006a9
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Oct 5 21:44:25 2016 -0700
WIP - stuff
gjs/byteArray.cpp | 31 +++++++++----------
gjs/context.cpp | 3 +-
gjs/coverage.cpp | 79 ++++++++++++++++++++-----------------------------
gjs/importer.cpp | 45 ++++++++++++----------------
gjs/jsapi-util-args.h | 3 +-
gjs/jsapi-util.h | 2 +-
6 files changed, 68 insertions(+), 95 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index 3fcca16..817e4fc 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 */
@@ -535,9 +532,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);
@@ -665,13 +662,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;
@@ -684,7 +682,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
*/
@@ -744,9 +742,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;
@@ -833,10 +831,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 1386472..cbfb57b 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -440,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'");
@@ -765,7 +764,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 f53538a..a5d4730 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
@@ -1380,8 +1374,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))
@@ -1523,10 +1516,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;
}
@@ -1550,7 +1540,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;
}
@@ -1572,20 +1562,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;
}
@@ -1661,15 +1650,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");
@@ -1747,9 +1734,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 6db3248..8a2e47e 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
@@ -306,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();
}
}
@@ -459,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
*/
@@ -493,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;
@@ -698,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
*/
@@ -764,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));
@@ -786,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;
@@ -902,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[] = {
@@ -933,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
@@ -958,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");
@@ -1081,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-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.h b/gjs/jsapi-util.h
index 4e1b0fd..80c2174 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; \
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]