Chromium Code Reviews| Index: Source/core/dom/DOMTypedArray.cpp |
| diff --git a/Source/core/dom/DOMTypedArray.cpp b/Source/core/dom/DOMTypedArray.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc82ea2beb0cdd689370e47679dbe2f025b0cee2 |
| --- /dev/null |
| +++ b/Source/core/dom/DOMTypedArray.cpp |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/dom/DOMTypedArray.h" |
| + |
| +#include "bindings/core/v8/DOMDataStore.h" |
| +#include "bindings/core/v8/V8ArrayBuffer.h" |
| +#include "bindings/core/v8/V8DOMWrapper.h" |
| + |
| +namespace blink { |
| + |
| +template<typename WTFTypedArray, typename V8TypedArray> |
| +v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| +{ |
| + // It's possible that no one except for the new wrapper owns this object at |
| + // this moment, so we have to prevent GC to collect this object until the |
| + // object gets associated with the wrapper. |
| + RefPtr<ThisType> protect(this); |
| + |
| + ASSERT(!DOMDataStore::containsWrapperNonTemplate(this, isolate)); |
| + |
| + const WrapperTypeInfo* wrapperTypeInfo = this->wrapperTypeInfo(); |
| + RefPtr<DOMArrayBuffer> buffer = this->buffer(); |
| + v8::Local<v8::Value> v8Buffer = toV8(buffer.get(), creationContext, isolate); |
| + ASSERT(v8Buffer->IsArrayBuffer()); |
| + |
| + v8::Handle<v8::Object> wrapper = V8TypedArray::New(v8Buffer.As<v8::ArrayBuffer>(), byteOffset(), length()); |
| + |
| + wrapperTypeInfo->installConditionallyEnabledProperties(wrapper, isolate); |
|
haraken
2014/10/16 05:41:42
Ditto. Remove this.
Yuki
2014/10/16 14:21:51
Done.
|
| + return associateWithWrapper(wrapperTypeInfo, wrapper, isolate); |
| +} |
| + |
| +template<typename WTFTypedArray, typename V8TypedArray> |
| +v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::associateWithWrapper(const WrapperTypeInfo* wrapperTypeInfo, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) |
| +{ |
| + return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperTypeInfo, wrapper, isolate); |
| +} |
| + |
| +// Instantiation of the non-inline functions of the template classes. |
| +#define INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Type) \ |
| + INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS_IMPL(WTF::Type##Array, v8::Type##Array) |
| +#define INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS_IMPL(WTFTypedArray, V8TypedArray) \ |
| +template v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate*); \ |
| +template v8::Handle<v8::Object> DOMTypedArray<WTFTypedArray, V8TypedArray>::associateWithWrapper(const WrapperTypeInfo*, v8::Handle<v8::Object> wrapper, v8::Isolate*) |
| + |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Int8); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Int16); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Int32); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint8); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint8Clamped); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint16); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Uint32); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Float32); |
| +INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS(Float64); |
| + |
| +#undef INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS |
| +#undef INSTANTIATE_DOMTYPEDARRAY_MEMBER_FUNCTIONS_IMPL |
| + |
| +} // namespace blink |