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

Side by Side Diff: src/arguments.cc

Issue 12494012: new style of property/function callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: make arm look like other architectures Created 7 years, 7 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 | « src/arguments.h ('k') | src/arm/macro-assembler-arm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "v8.h"
29 #include "arguments.h"
30
31 namespace v8 {
32 namespace internal {
33
34
35 static bool Match(void* a, void* b) {
36 return a == b;
37 }
38
39
40 static uint32_t Hash(void* function) {
41 uintptr_t as_int = reinterpret_cast<uintptr_t>(function);
42 if (sizeof(function) == 4) return static_cast<uint32_t>(as_int);
43 uint64_t as_64 = static_cast<uint64_t>(as_int);
44 return
45 static_cast<uint32_t>(as_64 >> 32) ^
46 static_cast<uint32_t>(as_64);
47 }
48
49
50 CallbackTable::CallbackTable(): map_(Match, 64) {}
51
52
53 bool CallbackTable::Contains(void* function) {
54 ASSERT(function != NULL);
55 return map_.Lookup(function, Hash(function), false) != NULL;
56 }
57
58
59 void CallbackTable::InsertCallback(Isolate* isolate,
60 void* function,
61 bool returns_void) {
62 if (function == NULL) return;
63 // Don't store for performance.
64 if (kStoreVoidFunctions != returns_void) return;
65 CallbackTable* table = isolate->callback_table();
66 if (table == NULL) {
67 table = new CallbackTable();
68 isolate->set_callback_table(table);
69 }
70 typedef HashMap::Entry Entry;
71 Entry* entry = table->map_.Lookup(function, Hash(function), true);
72 ASSERT(entry != NULL);
73 ASSERT(entry->value == NULL || entry->value == function);
74 entry->value = function;
75 }
76
77
78 template<typename T>
79 template<typename V>
80 v8::Handle<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) {
81 // Check the ReturnValue.
82 Object** handle = &this->end()[kReturnValueOffset];
83 // Nothing was set, return empty handle as per previous behaviour.
84 if ((*handle)->IsTheHole()) return v8::Handle<V>();
85 return v8::Handle<V>(reinterpret_cast<V*>(handle));
86 }
87
88
89 v8::Handle<v8::Value> FunctionCallbackArguments::Call(InvocationCallback f) {
90 Isolate* isolate = this->isolate();
91 void* f_as_void = CallbackTable::FunctionToVoidPtr(f);
92 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void);
93 if (new_style) {
94 FunctionCallback c = reinterpret_cast<FunctionCallback>(f);
95 FunctionCallbackInfo<v8::Value> info(end(),
96 argv_,
97 argc_,
98 is_construct_call_);
99 c(info);
100 } else {
101 v8::Arguments args(end(),
102 argv_,
103 argc_,
104 is_construct_call_);
105 v8::Handle<v8::Value> return_value = f(args);
106 if (!return_value.IsEmpty()) return return_value;
107 }
108 return GetReturnValue<v8::Value>(isolate);
109 }
110
111
112 #define WRITE_CALL_0(OldFunction, NewFunction, ReturnValue) \
113 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(OldFunction f) { \
114 Isolate* isolate = this->isolate(); \
115 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
116 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
117 if (new_style) { \
118 NewFunction c = reinterpret_cast<NewFunction>(f); \
119 PropertyCallbackInfo<ReturnValue> info(end()); \
120 c(info); \
121 } else { \
122 v8::AccessorInfo info(end()); \
123 v8::Handle<ReturnValue> return_value = f(info); \
124 if (!return_value.IsEmpty()) return return_value; \
125 } \
126 return GetReturnValue<ReturnValue>(isolate); \
127 }
128
129 #define WRITE_CALL_1(OldFunction, NewFunction, ReturnValue, Arg1) \
130 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(OldFunction f, \
131 Arg1 arg1) { \
132 Isolate* isolate = this->isolate(); \
133 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
134 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
135 if (new_style) { \
136 NewFunction c = reinterpret_cast<NewFunction>(f); \
137 PropertyCallbackInfo<ReturnValue> info(end()); \
138 c(arg1, info); \
139 } else { \
140 v8::AccessorInfo info(end()); \
141 v8::Handle<ReturnValue> return_value = f(arg1, info); \
142 if (!return_value.IsEmpty()) return return_value; \
143 } \
144 return GetReturnValue<ReturnValue>(isolate); \
145 }
146
147 #define WRITE_CALL_2(OldFunction, NewFunction, ReturnValue, Arg1, Arg2) \
148 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(OldFunction f, \
149 Arg1 arg1, \
150 Arg2 arg2) { \
151 Isolate* isolate = this->isolate(); \
152 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
153 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
154 if (new_style) { \
155 NewFunction c = reinterpret_cast<NewFunction>(f); \
156 PropertyCallbackInfo<ReturnValue> info(end()); \
157 c(arg1, arg2, info); \
158 } else { \
159 v8::AccessorInfo info(end()); \
160 v8::Handle<ReturnValue> return_value = f(arg1, arg2, info); \
161 if (!return_value.IsEmpty()) return return_value; \
162 } \
163 return GetReturnValue<ReturnValue>(isolate); \
164 }
165
166 #define WRITE_CALL_2_VOID(OldFunction, NewFunction, ReturnValue, Arg1, Arg2) \
167 void PropertyCallbackArguments::Call(OldFunction f, \
168 Arg1 arg1, \
169 Arg2 arg2) { \
170 Isolate* isolate = this->isolate(); \
171 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
172 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
173 if (new_style) { \
174 NewFunction c = reinterpret_cast<NewFunction>(f); \
175 PropertyCallbackInfo<ReturnValue> info(end()); \
176 c(arg1, arg2, info); \
177 } else { \
178 v8::AccessorInfo info(end()); \
179 f(arg1, arg2, info); \
180 } \
181 }
182
183 FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0)
184 FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1)
185 FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2)
186 FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID)
187
188 #undef WRITE_CALL_0
189 #undef WRITE_CALL_1
190 #undef WRITE_CALL_2
191 #undef WRITE_CALL_2_VOID
192
193
194 } } // namespace v8::internal
195
OLDNEW
« no previous file with comments | « src/arguments.h ('k') | src/arm/macro-assembler-arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698