diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jsapi-tests/testExternalArrayBuffer.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jsapi-tests/testExternalArrayBuffer.cpp')
-rw-r--r-- | js/src/jsapi-tests/testExternalArrayBuffer.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/jsapi-tests/testExternalArrayBuffer.cpp b/js/src/jsapi-tests/testExternalArrayBuffer.cpp new file mode 100644 index 000000000..cb864d37c --- /dev/null +++ b/js/src/jsapi-tests/testExternalArrayBuffer.cpp @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + */ + +#include "jsfriendapi.h" +#include "jsapi-tests/tests.h" +#include "vm/ArrayBufferObject.h" + +char test_data[] = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +static void GC(JSContext* cx) +{ + JS_GC(cx); + // Trigger another to wait for background finalization to end. + JS_GC(cx); +} + +BEGIN_TEST(testExternalArrayBuffer) +{ + size_t length = sizeof(test_data); + JS::RootedObject obj(cx, JS_NewArrayBufferWithExternalContents(cx, length, test_data)); + GC(cx); + CHECK(VerifyObject(obj, length)); + GC(cx); + JS_DetachArrayBuffer(cx, obj); + GC(cx); + CHECK(VerifyObject(obj, 0)); + + return true; +} + +bool VerifyObject(JS::HandleObject obj, uint32_t length) +{ + JS::AutoCheckCannotGC nogc; + + CHECK(obj); + CHECK(JS_IsArrayBufferObject(obj)); + CHECK_EQUAL(JS_GetArrayBufferByteLength(obj), length); + bool sharedDummy; + const char* data = + reinterpret_cast<const char*>(JS_GetArrayBufferData(obj, &sharedDummy, nogc)); + CHECK(data); + CHECK(test_data == data); + + return true; +} + +END_TEST(testExternalArrayBuffer) |