1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/dom/DOMTypedArray.h"
8 #include "bindings/core/v8/DOMDataStore.h"
9 #include "bindings/core/v8/V8ArrayBuffer.h"
10 #include "bindings/core/v8/V8DOMWrapper.h"
14 template<typename WTFTypedArray, typename V8TypedArray>
15 v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
17 // It's possible that no one except for the new wrapper owns this object at
18 // this moment, so we have to prevent GC to collect this object until the
19 // object gets associated with the wrapper.
20 RefPtr<ThisType> protect(this);
22 ASSERT(!DOMDataStore::containsWrapper(this, isolate));
24 const WrapperTypeInfo* wrapperTypeInfo = this->wrapperTypeInfo();
25 RefPtr<DOMArrayBuffer> buffer = this->buffer();
26 v8::Local<v8::Value> v8Buffer = toV8(buffer.get(), creationContext, isolate);
27 ASSERT(v8Buffer->IsArrayBuffer());
29 v8::Handle<v8::Object> wrapper = V8TypedArray::New(v8Buffer.As<v8::ArrayBuffer>(), byteOffset(), length());
31 return associateWithWrapper(wrapperTypeInfo, wrapper, isolate);
34 template<typename WTFTypedArray, typename V8TypedArray>
35 v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::associateWithWrapper(const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate)
37 return V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperTypeInfo, wrapper);
40 // Instantiation of the non-inline functions of the template classes.
41 #define INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Type) \
42 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS_IMPL(WTF::Type##Array, v8::Type##Array)
43 #define INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS_IMPL(WTFTypedArray, V8TypedArray) \
44 template v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate*); \
45 template v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::associateWithWrapper(const WrapperTypeInfo*, v8::Handle<v8::Object> wrapper, v8::Isolate*)
47 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Int8);
48 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Int16);
49 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Int32);
50 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint8);
51 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint8Clamped);
52 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint16);
53 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint32);
54 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Float32);
55 INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Float64);
57 #undef INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS
58 #undef INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS_IMPL