| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 template<typename TypedArray> | 47 template<typename TypedArray> |
| 48 class V8TypedArray { | 48 class V8TypedArray { |
| 49 public: | 49 public: |
| 50 static bool hasInstance(v8::Handle<v8::Value> value, v8::Isolate*) | 50 static bool hasInstance(v8::Handle<v8::Value> value, v8::Isolate*) |
| 51 { | 51 { |
| 52 return TypedArrayTraits<TypedArray>::IsInstance(value); | 52 return TypedArrayTraits<TypedArray>::IsInstance(value); |
| 53 } | 53 } |
| 54 | 54 |
| 55 static TypedArray* toNative(v8::Handle<v8::Object>); | 55 static TypedArray* toNative(v8::Handle<v8::Object>); |
| 56 static TypedArray* toNativeWithTypeCheck(v8::Isolate*, v8::Handle<v8::Value>
); |
| 56 static void derefObject(void*); | 57 static void derefObject(void*); |
| 57 static const WrapperTypeInfo wrapperTypeInfo; | 58 static const WrapperTypeInfo wrapperTypeInfo; |
| 58 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount; | 59 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount; |
| 59 | 60 |
| 60 static v8::Handle<v8::Object> wrap(TypedArray* impl, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) | 61 static v8::Handle<v8::Object> wrap(TypedArray* impl, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) |
| 61 { | 62 { |
| 62 ASSERT(impl); | 63 ASSERT(impl); |
| 63 ASSERT(!DOMDataStore::containsWrapper<Binding>(impl, isolate)); | 64 ASSERT(!DOMDataStore::containsWrapper<Binding>(impl, isolate)); |
| 64 return V8TypedArray<TypedArray>::createWrapper(impl, creationContext, is
olate); | 65 return V8TypedArray<TypedArray>::createWrapper(impl, creationContext, is
olate); |
| 65 } | 66 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toNative(view->Buffer()); | 163 RefPtr<ArrayBuffer> arrayBuffer = V8ArrayBuffer::toNative(view->Buffer()); |
| 163 RefPtr<TypedArray> typedArray = TypedArray::create(arrayBuffer, view->ByteOf
fset(), Traits::length(view)); | 164 RefPtr<TypedArray> typedArray = TypedArray::create(arrayBuffer, view->ByteOf
fset(), Traits::length(view)); |
| 164 ASSERT(typedArray.get()); | 165 ASSERT(typedArray.get()); |
| 165 V8DOMWrapper::associateObjectWithWrapper<Binding>(typedArray.release(), &wra
pperTypeInfo, object, v8::Isolate::GetCurrent(), WrapperConfiguration::Independe
nt); | 166 V8DOMWrapper::associateObjectWithWrapper<Binding>(typedArray.release(), &wra
pperTypeInfo, object, v8::Isolate::GetCurrent(), WrapperConfiguration::Independe
nt); |
| 166 | 167 |
| 167 typedarrayPtr = object->GetAlignedPointerFromInternalField(v8DOMWrapperObjec
tIndex); | 168 typedarrayPtr = object->GetAlignedPointerFromInternalField(v8DOMWrapperObjec
tIndex); |
| 168 ASSERT(typedarrayPtr); | 169 ASSERT(typedarrayPtr); |
| 169 return reinterpret_cast<TypedArray*>(typedarrayPtr); | 170 return reinterpret_cast<TypedArray*>(typedarrayPtr); |
| 170 } | 171 } |
| 171 | 172 |
| 173 template <typename TypedArray> |
| 174 TypedArray* V8TypedArray<TypedArray>::toNativeWithTypeCheck(v8::Isolate* isolate
, v8::Handle<v8::Value> value) |
| 175 { |
| 176 return V8TypedArray<TypedArray>::hasInstance(value, isolate) ? V8TypedArray<
TypedArray>::toNative(v8::Handle<v8::Object>::Cast(value)) : 0; |
| 177 } |
| 172 | 178 |
| 173 template <typename TypedArray> | 179 template <typename TypedArray> |
| 174 const WrapperTypeInfo V8TypedArray<TypedArray>::wrapperTypeInfo = { | 180 const WrapperTypeInfo V8TypedArray<TypedArray>::wrapperTypeInfo = { |
| 175 gin::kEmbedderBlink, | 181 gin::kEmbedderBlink, |
| 176 0, V8TypedArray<TypedArray>::derefObject, | 182 0, V8TypedArray<TypedArray>::derefObject, |
| 177 0, 0, 0, 0, 0, WrapperTypeObjectPrototype, false | 183 0, 0, 0, 0, 0, WrapperTypeObjectPrototype, false |
| 178 }; | 184 }; |
| 179 | 185 |
| 180 template <typename TypedArray> | 186 template <typename TypedArray> |
| 181 void V8TypedArray<TypedArray>::derefObject(void* object) | 187 void V8TypedArray<TypedArray>::derefObject(void* object) |
| 182 { | 188 { |
| 183 static_cast<TypedArray*>(object)->deref(); | 189 static_cast<TypedArray*>(object)->deref(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 | 192 |
| 187 } // namespace WebCode | 193 } // namespace WebCode |
| 188 | 194 |
| 189 #endif // V8TypedArrayCustom_h | 195 #endif // V8TypedArrayCustom_h |
| OLD | NEW |