mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-23 21:17:52 +00:00
Bug 807237. Add 'data' parameter to JS_StealArrayBufferContents. r=sfink
--HG-- extra : rebase_source : 5c9fe8f9b09ac63f3e130e7ff3418301f868cb8d
This commit is contained in:
parent
629f20cb90
commit
0fecd165f2
@ -52,8 +52,9 @@ BEGIN_TEST(testArrayBuffer_bug720949_steal)
|
||||
|
||||
// Steal the contents
|
||||
void *contents;
|
||||
CHECK(JS_StealArrayBufferContents(cx, obj, &contents));
|
||||
CHECK(JS_StealArrayBufferContents(cx, obj, &contents, &data));
|
||||
CHECK(contents != NULL);
|
||||
CHECK(data != NULL);
|
||||
|
||||
// Check that the original ArrayBuffer is neutered
|
||||
CHECK_EQUAL(JS_GetArrayBufferByteLength(obj, cx), 0);
|
||||
@ -111,9 +112,11 @@ BEGIN_TEST(testArrayBuffer_bug720949_viewList)
|
||||
buffer = JS_NewArrayBuffer(cx, 2000);
|
||||
js::RootedObject view(cx, JS_NewUint8ArrayWithBuffer(cx, buffer, 0, -1));
|
||||
void *contents;
|
||||
CHECK(JS_StealArrayBufferContents(cx, buffer, &contents));
|
||||
uint8_t *data;
|
||||
CHECK(JS_StealArrayBufferContents(cx, buffer, &contents, &data));
|
||||
CHECK(contents != NULL);
|
||||
JS_free(cx, contents);
|
||||
CHECK(data != NULL);
|
||||
JS_free(NULL, contents);
|
||||
GC(cx);
|
||||
CHECK(isNeutered(view));
|
||||
CHECK(isNeutered(buffer));
|
||||
@ -137,9 +140,11 @@ BEGIN_TEST(testArrayBuffer_bug720949_viewList)
|
||||
|
||||
// Neuter
|
||||
void *contents;
|
||||
CHECK(JS_StealArrayBufferContents(cx, buffer, &contents));
|
||||
uint8_t *data;
|
||||
CHECK(JS_StealArrayBufferContents(cx, buffer, &contents, &data));
|
||||
CHECK(contents != NULL);
|
||||
JS_free(cx, contents);
|
||||
CHECK(data != NULL);
|
||||
JS_free(NULL, contents);
|
||||
|
||||
CHECK(isNeutered(view1));
|
||||
CHECK(isNeutered(view2));
|
||||
|
@ -3409,6 +3409,7 @@ JS_realloc(JSContext *cx, void *p, size_t nbytes);
|
||||
/*
|
||||
* A wrapper for js_free(p) that may delay js_free(p) invocation as a
|
||||
* performance optimization.
|
||||
* cx may be NULL.
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_free(JSContext *cx, void *p);
|
||||
@ -4617,11 +4618,15 @@ JS_NewArrayBufferWithContents(JSContext *cx, void *contents);
|
||||
/*
|
||||
* Steal the contents of the given array buffer. The array buffer has its
|
||||
* length set to 0 and its contents array cleared. The caller takes ownership
|
||||
* of |contents| and must free it or transfer ownership via
|
||||
* of |*contents| and must free it or transfer ownership via
|
||||
* JS_NewArrayBufferWithContents when done using it.
|
||||
* To free |*contents|, call free().
|
||||
* A pointer to the buffer's data is returned in |*data|. This pointer can
|
||||
* be used until |*contents| is freed or has its ownership transferred.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_StealArrayBufferContents(JSContext *cx, JSObject *obj, void **contents);
|
||||
JS_StealArrayBufferContents(JSContext *cx, JSObject *obj, void **contents,
|
||||
uint8_t **data);
|
||||
|
||||
/*
|
||||
* Allocate memory that may be eventually passed to
|
||||
|
@ -732,7 +732,8 @@ JSStructuredCloneWriter::writeTransferMap()
|
||||
return false;
|
||||
|
||||
void *content;
|
||||
if (!JS_StealArrayBufferContents(context(), obj, &content))
|
||||
uint8_t *data;
|
||||
if (!JS_StealArrayBufferContents(context(), obj, &content, &data))
|
||||
return false;
|
||||
|
||||
if (!out.writePair(SCTAG_TRANSFER_MAP, 0) || !out.writePtr(content))
|
||||
|
@ -461,13 +461,15 @@ ArrayBufferObject::createDataViewForThis(JSContext *cx, unsigned argc, Value *vp
|
||||
}
|
||||
|
||||
bool
|
||||
ArrayBufferObject::stealContents(JSContext *cx, JSObject *obj, void **contents)
|
||||
ArrayBufferObject::stealContents(JSContext *cx, JSObject *obj, void **contents,
|
||||
uint8_t **data)
|
||||
{
|
||||
ArrayBufferObject &buffer = obj->asArrayBuffer();
|
||||
JSObject *views = *GetViewList(&buffer);
|
||||
js::ObjectElements *header = js::ObjectElements::fromElements((js::HeapSlot*)buffer.dataPointer());
|
||||
if (buffer.hasDynamicElements()) {
|
||||
*contents = header;
|
||||
*data = buffer.dataPointer();
|
||||
|
||||
buffer.setFixedElements();
|
||||
header = js::ObjectElements::fromElements((js::HeapSlot*)buffer.dataPointer());
|
||||
@ -482,6 +484,7 @@ ArrayBufferObject::stealContents(JSContext *cx, JSObject *obj, void **contents)
|
||||
|
||||
ArrayBufferObject::setElementsHeader(newheader, length);
|
||||
*contents = newheader;
|
||||
*data = reinterpret_cast<uint8_t *>(newheader + 1);
|
||||
}
|
||||
|
||||
// Neuter the donor ArrayBuffer and all views of it
|
||||
@ -3675,7 +3678,8 @@ JS_AllocateArrayBufferContents(JSContext *cx, uint32_t nbytes, void **contents,
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_StealArrayBufferContents(JSContext *cx, JSObject *obj, void **contents)
|
||||
JS_StealArrayBufferContents(JSContext *cx, JSObject *obj, void **contents,
|
||||
uint8_t **data)
|
||||
{
|
||||
if (!(obj = UnwrapObjectChecked(cx, obj)))
|
||||
return false;
|
||||
@ -3685,7 +3689,7 @@ JS_StealArrayBufferContents(JSContext *cx, JSObject *obj, void **contents)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ArrayBufferObject::stealContents(cx, obj, contents))
|
||||
if (!ArrayBufferObject::stealContents(cx, obj, contents, data))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -132,7 +132,8 @@ class ArrayBufferObject : public JSObject
|
||||
|
||||
static void sweepAll(JSRuntime *rt);
|
||||
|
||||
static bool stealContents(JSContext *cx, JSObject *obj, void **contents);
|
||||
static bool stealContents(JSContext *cx, JSObject *obj, void **contents,
|
||||
uint8_t **data);
|
||||
|
||||
static inline void setElementsHeader(js::ObjectElements *header, uint32_t bytes);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user