OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" | |
33 | |
34 #include "bindings/core/v8/V8Binding.h" | |
35 #include "wtf/ArrayBuffer.h" | |
36 #include "wtf/StdLibExtras.h" | |
37 | |
38 namespace blink { | |
39 | |
40 using namespace WTF; | |
41 | |
42 V8ArrayBufferDeallocationObserver* V8ArrayBufferDeallocationObserver::instanceTe
mplate() | |
43 { | |
44 DEFINE_STATIC_LOCAL(V8ArrayBufferDeallocationObserver, deallocationObserver,
()); | |
45 return &deallocationObserver; | |
46 } | |
47 | |
48 const WrapperTypeInfo V8ArrayBuffer::wrapperTypeInfo = { | |
49 gin::kEmbedderBlink, | |
50 0, | |
51 V8ArrayBuffer::refObject, | |
52 V8ArrayBuffer::derefObject, | |
53 V8ArrayBuffer::trace, | |
54 0, 0, 0, 0, 0, 0, | |
55 WrapperTypeInfo::WrapperTypeObjectPrototype, | |
56 WrapperTypeInfo::ObjectClassId, | |
57 WrapperTypeInfo::Independent, | |
58 WrapperTypeInfo::RefCountedObject | |
59 }; | |
60 | |
61 bool V8ArrayBuffer::hasInstance(v8::Handle<v8::Value> value, v8::Isolate*) | |
62 { | |
63 return value->IsArrayBuffer(); | |
64 } | |
65 | |
66 void V8ArrayBuffer::refObject(ScriptWrappableBase* internalPointer) | |
67 { | |
68 toImpl(internalPointer)->ref(); | |
69 } | |
70 | |
71 void V8ArrayBuffer::derefObject(ScriptWrappableBase* internalPointer) | |
72 { | |
73 toImpl(internalPointer)->deref(); | |
74 } | |
75 | |
76 v8::Handle<v8::Object> V8ArrayBuffer::createWrapper(PassRefPtr<ArrayBuffer> impl
, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
77 { | |
78 ASSERT(impl.get()); | |
79 ASSERT(!DOMDataStore::containsWrapper<V8ArrayBuffer>(impl.get(), isolate)); | |
80 | |
81 v8::Handle<v8::Object> wrapper = v8::ArrayBuffer::New(isolate, impl->data(),
impl->byteLength()); | |
82 impl->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instanceTem
plate()); | |
83 | |
84 V8DOMWrapper::associateObjectWithWrapper<V8ArrayBuffer>(impl, &wrapperTypeIn
fo, wrapper, isolate); | |
85 return wrapper; | |
86 } | |
87 | |
88 ArrayBuffer* V8ArrayBuffer::toImpl(v8::Handle<v8::Object> object) | |
89 { | |
90 ASSERT(object->IsArrayBuffer()); | |
91 v8::Local<v8::ArrayBuffer> v8buffer = object.As<v8::ArrayBuffer>(); | |
92 if (v8buffer->IsExternal()) { | |
93 RELEASE_ASSERT(toWrapperTypeInfo(object)->ginEmbedder == gin::kEmbedderB
link); | |
94 return reinterpret_cast<ArrayBuffer*>(blink::toScriptWrappableBase(objec
t)); | |
95 } | |
96 | |
97 v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize(); | |
98 ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength(), | |
99 V8ArrayBufferDeallocationObserver::instanceTemplate()); | |
100 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(contents); | |
101 V8DOMWrapper::associateObjectWithWrapper<V8ArrayBuffer>(buffer.release(), &w
rapperTypeInfo, object, v8::Isolate::GetCurrent()); | |
102 | |
103 return reinterpret_cast<ArrayBuffer*>(blink::toScriptWrappableBase(object)); | |
104 } | |
105 | |
106 ArrayBuffer* V8ArrayBuffer::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle
<v8::Value> value) | |
107 { | |
108 return V8ArrayBuffer::hasInstance(value, isolate) ? V8ArrayBuffer::toImpl(v8
::Handle<v8::Object>::Cast(value)) : 0; | |
109 } | |
110 | |
111 template<> | |
112 v8::Handle<v8::Value> toV8NoInline(ArrayBuffer* impl, v8::Handle<v8::Object> cre
ationContext, v8::Isolate* isolate) | |
113 { | |
114 return toV8(impl, creationContext, isolate); | |
115 } | |
116 | |
117 } // namespace blink | |
OLD | NEW |