37 using namespace v8::internal;
40 return reinterpret_cast<Isolate*
>((*context)->GetIsolate());
44 static int CountArrayBuffersInWeakList(
Heap* heap) {
59 if (ab == o)
return true;
67 for (
Object* o = array_buffer->weak_first_view();
78 for (
Object* o = array_buffer->weak_first_view();
81 if (ta == o)
return true;
87 TEST(WeakArrayBuffersFromApi) {
90 Isolate* isolate = GetIsolateFrom(&context);
92 int start = CountArrayBuffersInWeakList(isolate->
heap());
104 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->
heap()) - start);
105 CHECK(HasArrayBufferInWeakList(isolate->
heap(), *iab1));
106 CHECK(HasArrayBufferInWeakList(isolate->
heap(), *iab2));
109 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->
heap()) - start);
114 CHECK(HasArrayBufferInWeakList(isolate->
heap(), *iab1));
119 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->
heap()));
123 TEST(WeakArrayBuffersFromScript) {
126 Isolate* isolate = GetIsolateFrom(&context);
127 int start = CountArrayBuffersInWeakList(isolate->
heap());
129 for (
int i = 1; i <= 3; i++) {
132 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->
heap()));
138 CompileRun(
"var ab1 = new ArrayBuffer(256);"
139 "var ab2 = new ArrayBuffer(256);"
140 "var ab3 = new ArrayBuffer(256);");
148 CHECK_EQ(3, CountArrayBuffersInWeakList(isolate->
heap()) - start);
149 CHECK(HasArrayBufferInWeakList(isolate->
heap(),
151 CHECK(HasArrayBufferInWeakList(isolate->
heap(),
153 CHECK(HasArrayBufferInWeakList(isolate->
heap(),
159 CompileRun(source.
start());
162 CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->
heap()) - start);
166 for (
int j = 1; j <= 3; j++) {
167 if (j == i)
continue;
171 CHECK(HasArrayBufferInWeakList(isolate->
heap(),
176 CompileRun(
"ab1 = null; ab2 = null; ab3 = null;");
180 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->
heap()));
184 template <
typename View>
188 Isolate* isolate = GetIsolateFrom(&context);
204 CHECK(HasViewInWeakList(*iab, *ita1));
205 CHECK(HasViewInWeakList(*iab, *ita2));
210 CHECK(HasViewInWeakList(*iab, *ita1));
219 TestViewFromApi<v8::Uint8Array>();
224 TestViewFromApi<v8::Int8Array>();
229 TestViewFromApi<v8::Uint16Array>();
234 TestViewFromApi<v8::Int16Array>();
239 TestViewFromApi<v8::Uint32Array>();
244 TestViewFromApi<v8::Int32Array>();
249 TestViewFromApi<v8::Float32Array>();
254 TestViewFromApi<v8::Float64Array>();
258 TEST(Uint8ClampedArrayFromApi) {
259 TestViewFromApi<v8::Uint8ClampedArray>();
264 TestViewFromApi<v8::DataView>();
267 template <
typename TypedArray>
268 static void TestTypedArrayFromScript(
const char* constructor) {
271 Isolate* isolate = GetIsolateFrom(&context);
273 int start = CountArrayBuffersInWeakList(isolate->
heap());
274 CompileRun(
"var ab = new ArrayBuffer(2048);");
275 for (
int i = 1; i <= 3; i++) {
281 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->
heap()) - start);
286 "var ta1 = new %s(ab);"
287 "var ta2 = new %s(ab);"
288 "var ta3 = new %s(ab)",
289 constructor, constructor, constructor);
291 CompileRun(source.start());
300 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->
heap()) - start);
309 CompileRun(source.start());
312 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->
heap()) - start);
320 for (
int j = 1; j <= 3; j++) {
321 if (j == i)
continue;
329 CompileRun(
"ta1 = null; ta2 = null; ta3 = null;");
332 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->
heap()) - start);
346 TestTypedArrayFromScript<v8::Uint8Array>(
"Uint8Array");
351 TestTypedArrayFromScript<v8::Int8Array>(
"Int8Array");
356 TestTypedArrayFromScript<v8::Uint16Array>(
"Uint16Array");
361 TestTypedArrayFromScript<v8::Int16Array>(
"Int16Array");
366 TestTypedArrayFromScript<v8::Uint32Array>(
"Uint32Array");
371 TestTypedArrayFromScript<v8::Int32Array>(
"Int32Array");
376 TestTypedArrayFromScript<v8::Float32Array>(
"Float32Array");
381 TestTypedArrayFromScript<v8::Float64Array>(
"Float64Array");
385 TEST(Uint8ClampedArrayFromScript) {
386 TestTypedArrayFromScript<v8::Uint8ClampedArray>(
"Uint8ClampedArray");
391 TestTypedArrayFromScript<v8::DataView>(
"DataView");
#define CHECK_EQ(expected, value)
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
v8::Isolate * GetIsolate()
static V8_INLINE Handle< T > Cast(Handle< S > that)
static Local< ArrayBuffer > New(Isolate *isolate, size_t byte_length)
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
static const int kAbortIncrementalMarkingMask
static int SNPrintF(Vector< char > str, const char *format,...)
Object * array_buffers_list()
static JSArrayBuffer * cast(Object *obj)
static JSArrayBufferView * cast(Object *obj)