| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 * | |
| 24 */ | |
| 25 | |
| 26 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_CUSTOM_V8ARRAYBUFFERCUSTOM_H_ | |
| 27 #define SKY_ENGINE_BINDINGS_CORE_V8_CUSTOM_V8ARRAYBUFFERCUSTOM_H_ | |
| 28 | |
| 29 #include "sky/engine/bindings/core/v8/V8Binding.h" | |
| 30 #include "sky/engine/bindings/core/v8/V8DOMWrapper.h" | |
| 31 #include "sky/engine/bindings/core/v8/WrapperTypeInfo.h" | |
| 32 #include "sky/engine/wtf/ArrayBuffer.h" | |
| 33 #include "v8/include/v8.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 class V8ArrayBufferDeallocationObserver final: public WTF::ArrayBufferDeallocati
onObserver { | |
| 38 public: | |
| 39 virtual void arrayBufferDeallocated(unsigned sizeInBytes) override | |
| 40 { | |
| 41 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-static
_cast<int>(sizeInBytes)); | |
| 42 } | |
| 43 static V8ArrayBufferDeallocationObserver* instanceTemplate(); | |
| 44 | |
| 45 protected: | |
| 46 virtual void blinkAllocatedMemory(unsigned sizeInBytes) override | |
| 47 { | |
| 48 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(static_
cast<int>(sizeInBytes)); | |
| 49 } | |
| 50 }; | |
| 51 | |
| 52 class V8ArrayBuffer { | |
| 53 public: | |
| 54 static bool hasInstance(v8::Handle<v8::Value>, v8::Isolate*); | |
| 55 static ArrayBuffer* toNative(v8::Handle<v8::Object>); | |
| 56 static ArrayBuffer* toNativeWithTypeCheck(v8::Isolate*, v8::Handle<v8::Value
>); | |
| 57 static void refObject(ScriptWrappableBase* internalPointer); | |
| 58 static void derefObject(ScriptWrappableBase* internalPointer); | |
| 59 static const WrapperTypeInfo wrapperTypeInfo; | |
| 60 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount; | |
| 61 | |
| 62 static inline ScriptWrappableBase* toScriptWrappableBase(ArrayBuffer* impl) | |
| 63 { | |
| 64 return reinterpret_cast<ScriptWrappableBase*>(impl); | |
| 65 } | |
| 66 | |
| 67 static inline ArrayBuffer* fromInternalPointer(ScriptWrappableBase* internal
Pointer) | |
| 68 { | |
| 69 return reinterpret_cast<ArrayBuffer*>(internalPointer); | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 friend v8::Handle<v8::Object> wrap(ArrayBuffer*, v8::Handle<v8::Object> crea
tionContext, v8::Isolate*); | |
| 74 static v8::Handle<v8::Object> createWrapper(PassRefPtr<ArrayBuffer>, v8::Han
dle<v8::Object> creationContext, v8::Isolate*); | |
| 75 }; | |
| 76 | |
| 77 inline v8::Handle<v8::Object> wrap(ArrayBuffer* impl, v8::Handle<v8::Object> cre
ationContext, v8::Isolate* isolate) | |
| 78 { | |
| 79 ASSERT(impl); | |
| 80 ASSERT(!DOMDataStore::containsWrapper<V8ArrayBuffer>(impl, isolate)); | |
| 81 return V8ArrayBuffer::createWrapper(impl, creationContext, isolate); | |
| 82 } | |
| 83 | |
| 84 inline v8::Handle<v8::Value> toV8(ArrayBuffer* impl, v8::Handle<v8::Object> crea
tionContext, v8::Isolate* isolate) | |
| 85 { | |
| 86 if (UNLIKELY(!impl)) | |
| 87 return v8::Null(isolate); | |
| 88 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<V8ArrayBuffer>(impl
, isolate); | |
| 89 if (!wrapper.IsEmpty()) | |
| 90 return wrapper; | |
| 91 return wrap(impl, creationContext, isolate); | |
| 92 } | |
| 93 | |
| 94 template<class CallbackInfo> | |
| 95 inline void v8SetReturnValue(const CallbackInfo& info, ArrayBuffer* impl) | |
| 96 { | |
| 97 if (UNLIKELY(!impl)) { | |
| 98 v8SetReturnValueNull(info); | |
| 99 return; | |
| 100 } | |
| 101 if (DOMDataStore::setReturnValueFromWrapper<V8ArrayBuffer>(info.GetReturnVal
ue(), impl)) | |
| 102 return; | |
| 103 v8::Handle<v8::Object> wrapper = wrap(impl, info.Holder(), info.GetIsolate()
); | |
| 104 v8SetReturnValue(info, wrapper); | |
| 105 } | |
| 106 | |
| 107 template<class CallbackInfo> | |
| 108 inline void v8SetReturnValueForMainWorld(const CallbackInfo& info, ArrayBuffer*
impl) | |
| 109 { | |
| 110 ASSERT(DOMWrapperWorld::current(info.GetIsolate()).isMainWorld()); | |
| 111 if (UNLIKELY(!impl)) { | |
| 112 v8SetReturnValueNull(info); | |
| 113 return; | |
| 114 } | |
| 115 if (DOMDataStore::setReturnValueFromWrapperForMainWorld<V8ArrayBuffer>(info.
GetReturnValue(), impl)) | |
| 116 return; | |
| 117 v8::Handle<v8::Value> wrapper = wrap(impl, info.Holder(), info.GetIsolate())
; | |
| 118 v8SetReturnValue(info, wrapper); | |
| 119 } | |
| 120 | |
| 121 template<class CallbackInfo, class Wrappable> | |
| 122 inline void v8SetReturnValueFast(const CallbackInfo& info, ArrayBuffer* impl, Wr
appable* wrappable) | |
| 123 { | |
| 124 if (UNLIKELY(!impl)) { | |
| 125 v8SetReturnValueNull(info); | |
| 126 return; | |
| 127 } | |
| 128 if (DOMDataStore::setReturnValueFromWrapperFast<V8ArrayBuffer>(info.GetRetur
nValue(), impl, info.Holder(), wrappable)) | |
| 129 return; | |
| 130 v8::Handle<v8::Object> wrapper = wrap(impl, info.Holder(), info.GetIsolate()
); | |
| 131 v8SetReturnValue(info, wrapper); | |
| 132 } | |
| 133 | |
| 134 inline v8::Handle<v8::Value> toV8(PassRefPtr< ArrayBuffer > impl, v8::Handle<v8:
:Object> creationContext, v8::Isolate* isolate) | |
| 135 { | |
| 136 return toV8(impl.get(), creationContext, isolate); | |
| 137 } | |
| 138 | |
| 139 template<class CallbackInfo> | |
| 140 inline void v8SetReturnValue(const CallbackInfo& info, PassRefPtr< ArrayBuffer >
impl) | |
| 141 { | |
| 142 v8SetReturnValue(info, impl.get()); | |
| 143 } | |
| 144 | |
| 145 template<class CallbackInfo> | |
| 146 inline void v8SetReturnValueForMainWorld(const CallbackInfo& info, PassRefPtr< A
rrayBuffer > impl) | |
| 147 { | |
| 148 v8SetReturnValueForMainWorld(info, impl.get()); | |
| 149 } | |
| 150 | |
| 151 template<class CallbackInfo, class Wrappable> | |
| 152 inline void v8SetReturnValueFast(const CallbackInfo& info, PassRefPtr< ArrayBuff
er > impl, Wrappable* wrappable) | |
| 153 { | |
| 154 v8SetReturnValueFast(info, impl.get(), wrappable); | |
| 155 } | |
| 156 | |
| 157 } // namespace blink | |
| 158 | |
| 159 #endif // SKY_ENGINE_BINDINGS_CORE_V8_CUSTOM_V8ARRAYBUFFERCUSTOM_H_ | |
| OLD | NEW |