[gjs: 14/25] byteArray: Use new ArrayBuffer API
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 14/25] byteArray: Use new ArrayBuffer API
- Date: Sun, 26 Jan 2020 04:49:54 +0000 (UTC)
commit 75eb6e5f938390d2e5ec2737cb93b6a8cfa5d3c2
Author: Philip Chimento <philip chimento gmail com>
Date: Mon May 20 18:07:04 2019 -0700
byteArray: Use new ArrayBuffer API
The ArrayBuffer APIs were slightly renamed, and
JS::NewExternalArrayBuffer() no longer takes a ref callback since
SpiderMonkey can no longer clone ArrayBuffer objects with external data.
gjs/byteArray.cpp | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index d034a418..0df16999 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -29,6 +29,7 @@
#include <glib.h>
#include "gjs/jsapi-wrapper.h"
+#include "js/ArrayBuffer.h"
#include "gi/boxed.h"
#include "gjs/atoms.h"
@@ -38,18 +39,12 @@
#include "gjs/jsapi-util-args.h"
#include "gjs/jsapi-util.h"
-/* Callbacks to use with JS_NewExternalArrayBuffer() */
+/* Callbacks to use with JS::NewExternalArrayBuffer() */
static void gfree_arraybuffer_contents(void* contents, void*) {
g_free(contents);
}
-static void bytes_ref_arraybuffer(void* contents G_GNUC_UNUSED,
- void* user_data) {
- auto* gbytes = static_cast<GBytes*>(user_data);
- g_bytes_ref(gbytes);
-}
-
static void bytes_unref_arraybuffer(void* contents G_GNUC_UNUSED,
void* user_data) {
auto* gbytes = static_cast<GBytes*>(user_data);
@@ -236,7 +231,7 @@ from_string_func(JSContext *context,
*/
size_t len = strlen(utf8.get());
array_buffer =
- JS_NewArrayBufferWithContents(context, len, utf8.release());
+ JS::NewArrayBufferWithContents(context, len, utf8.release());
} else {
JSString *str = argv[0].toString(); /* Rooted by argv */
GError *error = NULL;
@@ -278,8 +273,8 @@ from_string_func(JSContext *context,
return gjs_throw_gerror_message(context, error); // frees GError
array_buffer =
- JS_NewExternalArrayBuffer(context, bytes_written, encoded, nullptr,
- gfree_arraybuffer_contents, nullptr);
+ JS::NewExternalArrayBuffer(context, bytes_written, encoded,
+ gfree_arraybuffer_contents, nullptr);
}
if (!array_buffer)
@@ -320,12 +315,13 @@ from_gbytes_func(JSContext *context,
const void* data = g_bytes_get_data(gbytes, &len);
JS::RootedObject array_buffer(
context,
- JS_NewExternalArrayBuffer(
+ JS::NewExternalArrayBuffer(
context, len,
const_cast<void*>(data), // the ArrayBuffer won't modify the data
- bytes_ref_arraybuffer, bytes_unref_arraybuffer, gbytes));
+ bytes_unref_arraybuffer, gbytes));
if (!array_buffer)
return false;
+ g_bytes_ref(gbytes); // now owned by both ArrayBuffer and BoxedBase
JS::RootedObject obj(
context, JS_NewUint8ArrayWithBuffer(context, array_buffer, 0, -1));
@@ -345,9 +341,10 @@ JSObject* gjs_byte_array_from_data(JSContext* cx, size_t nbytes, void* data) {
JS::RootedObject array_buffer(cx);
// a null data pointer takes precedence over whatever `nbytes` says
if (data)
- array_buffer = JS_NewArrayBufferWithContents(cx, nbytes, g_memdup(data, nbytes));
+ array_buffer =
+ JS::NewArrayBufferWithContents(cx, nbytes, g_memdup(data, nbytes));
else
- array_buffer = JS_NewArrayBuffer(cx, 0);
+ array_buffer = JS::NewArrayBuffer(cx, 0);
if (!array_buffer)
return nullptr;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]