Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: Source/bindings/v8/custom/V8ArrayBufferCustom.h

Issue 18316003: Revert "Use V8 implementation of ArrayBuffer in Blink." (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/V8Utilities.cpp ('k') | Source/bindings/v8/custom/V8ArrayBufferCustom.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 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 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 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 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 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 * 23 *
24 */ 24 */
25 25
26 #ifndef V8ArrayBufferCustom_h 26 #ifndef V8ArrayBufferCustom_h
27 #define V8ArrayBufferCustom_h 27 #define V8ArrayBufferCustom_h
28 28
29 #include "bindings/v8/V8Binding.h" 29 #include <v8.h>
30 #include "bindings/v8/V8DOMWrapper.h"
31 #include "bindings/v8/WrapperTypeInfo.h"
32
33 #include "wtf/ArrayBuffer.h" 30 #include "wtf/ArrayBuffer.h"
34 31
35 #include <v8.h>
36
37 namespace WebCore { 32 namespace WebCore {
38 33
39 class V8ArrayBufferDeallocationObserver: public WTF::ArrayBufferDeallocationObse rver { 34 class V8ArrayBufferDeallocationObserver: public WTF::ArrayBufferDeallocationObse rver {
40 public: 35 public:
41 virtual void ArrayBufferDeallocated(unsigned sizeInBytes) 36 virtual void ArrayBufferDeallocated(unsigned sizeInBytes)
42 { 37 {
43 v8::V8::AdjustAmountOfExternalAllocatedMemory(-static_cast<int>(sizeInBy tes)); 38 v8::V8::AdjustAmountOfExternalAllocatedMemory(-static_cast<int>(sizeInBy tes));
44 } 39 }
45 static V8ArrayBufferDeallocationObserver* instance(); 40 static V8ArrayBufferDeallocationObserver* instance();
46 }; 41 };
47 42
48 class V8ArrayBuffer {
49 public:
50 static bool HasInstance(v8::Handle<v8::Value>, v8::Isolate*, WrapperWorldTyp e);
51 static bool HasInstanceInAnyWorld(v8::Handle<v8::Value>, v8::Isolate*);
52 static ArrayBuffer* toNative(v8::Handle<v8::Object>);
53 static void derefObject(void*);
54 static WrapperTypeInfo info;
55 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount;
56 static void installPerContextProperties(v8::Handle<v8::Object>, ArrayBuffer* , v8::Isolate*) { }
57 static void installPerContextPrototypeProperties(v8::Handle<v8::Object>, v8: :Isolate*) { }
58 private:
59 friend v8::Handle<v8::Object> wrap(ArrayBuffer*, v8::Handle<v8::Object> crea tionContext, v8::Isolate*);
60 static v8::Handle<v8::Object> createWrapper(PassRefPtr<ArrayBuffer>, v8::Han dle<v8::Object> creationContext, v8::Isolate*);
61 };
62
63 template<>
64 class WrapperTypeTraits<ArrayBuffer > {
65 public:
66 static WrapperTypeInfo* info() { return &V8ArrayBuffer::info; }
67 };
68
69
70 inline v8::Handle<v8::Object> wrap(ArrayBuffer* impl, v8::Handle<v8::Object> cre ationContext, v8::Isolate* isolate)
71 {
72 ASSERT(impl);
73 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty());
74 return V8ArrayBuffer::createWrapper(impl, creationContext, isolate);
75 } 43 }
76 44
77 inline v8::Handle<v8::Value> toV8(ArrayBuffer* impl, v8::Handle<v8::Object> crea tionContext, v8::Isolate* isolate)
78 {
79 if (UNLIKELY(!impl))
80 return v8NullWithCheck(isolate);
81 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate);
82 if (!wrapper.IsEmpty())
83 return wrapper;
84 return wrap(impl, creationContext, isolate);
85 }
86
87 inline v8::Handle<v8::Value> toV8ForMainWorld(ArrayBuffer* impl, v8::Handle<v8:: Object> creationContext, v8::Isolate* isolate)
88 {
89 ASSERT(worldType(isolate) == MainWorld);
90 if (UNLIKELY(!impl))
91 return v8NullWithCheck(isolate);
92 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapperForMainWorld(impl);
93 if (!wrapper.IsEmpty())
94 return wrapper;
95 return wrap(impl, creationContext, isolate);
96 }
97
98 template<class HolderContainer, class Wrappable>
99 inline v8::Handle<v8::Value> toV8Fast(ArrayBuffer* impl, const HolderContainer& container, Wrappable* wrappable)
100 {
101 if (UNLIKELY(!impl))
102 return v8Null(container.GetIsolate());
103 v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapperFast(impl, containe r, wrappable);
104 if (!wrapper.IsEmpty())
105 return wrapper;
106 return wrap(impl, container.Holder(), container.GetIsolate());
107 }
108
109 template<class HolderContainer, class Wrappable>
110 inline v8::Handle<v8::Value> toV8FastForMainWorld(ArrayBuffer* impl, const Holde rContainer& container, Wrappable* wrappable)
111 {
112 ASSERT(worldType(container.GetIsolate()) == MainWorld);
113 if (UNLIKELY(!impl))
114 return v8Null(container.GetIsolate());
115 v8::Handle<v8::Object> wrapper = DOMDataStore::getWrapperForMainWorld(impl);
116 if (!wrapper.IsEmpty())
117 return wrapper;
118 return wrap(impl, container.Holder(), container.GetIsolate());
119 }
120
121 template<class HolderContainer, class Wrappable>
122 inline v8::Handle<v8::Value> toV8FastForMainWorld(PassRefPtr< ArrayBuffer > impl , const HolderContainer& container, Wrappable* wrappable)
123 {
124 return toV8FastForMainWorld(impl.get(), container, wrappable);
125 }
126
127
128 template<class HolderContainer, class Wrappable>
129 inline v8::Handle<v8::Value> toV8Fast(PassRefPtr< ArrayBuffer > impl, const Hold erContainer& container, Wrappable* wrappable)
130 {
131 return toV8Fast(impl.get(), container, wrappable);
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 } // namespace WebCore
140
141 #endif // V8ArrayBufferCustom_h 45 #endif // V8ArrayBufferCustom_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8Utilities.cpp ('k') | Source/bindings/v8/custom/V8ArrayBufferCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698