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

Side by Side Diff: src/arguments.cc

Issue 23513004: remove old style callbacks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: inlined a function used once Created 7 years, 3 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 16 matching lines...) Expand all
27 27
28 #include "v8.h" 28 #include "v8.h"
29 #include "arguments.h" 29 #include "arguments.h"
30 30
31 #include "vm-state-inl.h" 31 #include "vm-state-inl.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 36
37 static bool Match(void* a, void* b) {
38 return a == b;
39 }
40
41
42 static uint32_t Hash(void* function) {
43 uintptr_t as_int = reinterpret_cast<uintptr_t>(function);
44 if (sizeof(function) == 4) return static_cast<uint32_t>(as_int);
45 uint64_t as_64 = static_cast<uint64_t>(as_int);
46 return
47 static_cast<uint32_t>(as_64 >> 32) ^
48 static_cast<uint32_t>(as_64);
49 }
50
51
52 CallbackTable::CallbackTable(): map_(Match, 64) {}
53
54
55 bool CallbackTable::Contains(void* function) {
56 ASSERT(function != NULL);
57 return map_.Lookup(function, Hash(function), false) != NULL;
58 }
59
60
61 void CallbackTable::InsertCallback(Isolate* isolate,
62 void* function,
63 bool returns_void) {
64 if (function == NULL) return;
65 // Don't store for performance.
66 if (kStoreVoidFunctions != returns_void) return;
67 CallbackTable* table = isolate->callback_table();
68 if (table == NULL) {
69 table = new CallbackTable();
70 isolate->set_callback_table(table);
71 }
72 typedef HashMap::Entry Entry;
73 Entry* entry = table->map_.Lookup(function, Hash(function), true);
74 ASSERT(entry != NULL);
75 ASSERT(entry->value == NULL || entry->value == function);
76 entry->value = function;
77 }
78
79
80 template<typename T> 37 template<typename T>
81 template<typename V> 38 template<typename V>
82 v8::Handle<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) { 39 v8::Handle<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) {
83 // Check the ReturnValue. 40 // Check the ReturnValue.
84 Object** handle = &this->end()[kReturnValueOffset]; 41 Object** handle = &this->end()[kReturnValueOffset];
85 // Nothing was set, return empty handle as per previous behaviour. 42 // Nothing was set, return empty handle as per previous behaviour.
86 if ((*handle)->IsTheHole()) return v8::Handle<V>(); 43 if ((*handle)->IsTheHole()) return v8::Handle<V>();
87 return Utils::Convert<Object, V>(Handle<Object>(handle)); 44 return Utils::Convert<Object, V>(Handle<Object>(handle));
88 } 45 }
89 46
90 47
91 v8::Handle<v8::Value> FunctionCallbackArguments::Call(InvocationCallback f) { 48 v8::Handle<v8::Value> FunctionCallbackArguments::Call(FunctionCallback f) {
92 Isolate* isolate = this->isolate(); 49 Isolate* isolate = this->isolate();
93 void* f_as_void = CallbackTable::FunctionToVoidPtr(f);
94 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void);
95 VMState<EXTERNAL> state(isolate); 50 VMState<EXTERNAL> state(isolate);
96 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); 51 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
97 if (new_style) { 52 FunctionCallbackInfo<v8::Value> info(end(),
98 FunctionCallback c = reinterpret_cast<FunctionCallback>(f); 53 argv_,
99 FunctionCallbackInfo<v8::Value> info(end(), 54 argc_,
100 argv_, 55 is_construct_call_);
101 argc_, 56 f(info);
102 is_construct_call_);
103 c(info);
104 } else {
105 v8::Arguments args(end(),
106 argv_,
107 argc_,
108 is_construct_call_);
109 v8::Handle<v8::Value> return_value = f(args);
110 if (!return_value.IsEmpty()) return return_value;
111 }
112 return GetReturnValue<v8::Value>(isolate); 57 return GetReturnValue<v8::Value>(isolate);
113 } 58 }
114 59
115 60
116 #define WRITE_CALL_0(OldFunction, NewFunction, ReturnValue) \ 61 #define WRITE_CALL_0(Function, ReturnValue) \
117 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(OldFunction f) { \ 62 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f) { \
118 Isolate* isolate = this->isolate(); \ 63 Isolate* isolate = this->isolate(); \
119 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
120 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
121 VMState<EXTERNAL> state(isolate); \ 64 VMState<EXTERNAL> state(isolate); \
122 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 65 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
123 if (new_style) { \ 66 PropertyCallbackInfo<ReturnValue> info(end()); \
124 NewFunction c = reinterpret_cast<NewFunction>(f); \ 67 f(info); \
125 PropertyCallbackInfo<ReturnValue> info(end()); \
126 c(info); \
127 } else { \
128 v8::AccessorInfo info(end()); \
129 v8::Handle<ReturnValue> return_value = f(info); \
130 if (!return_value.IsEmpty()) return return_value; \
131 } \
132 return GetReturnValue<ReturnValue>(isolate); \ 68 return GetReturnValue<ReturnValue>(isolate); \
133 } 69 }
134 70
135 #define WRITE_CALL_1(OldFunction, NewFunction, ReturnValue, Arg1) \ 71
136 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(OldFunction f, \ 72 #define WRITE_CALL_1(Function, ReturnValue, Arg1) \
73 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \
137 Arg1 arg1) { \ 74 Arg1 arg1) { \
138 Isolate* isolate = this->isolate(); \ 75 Isolate* isolate = this->isolate(); \
139 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
140 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
141 VMState<EXTERNAL> state(isolate); \ 76 VMState<EXTERNAL> state(isolate); \
142 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 77 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
143 if (new_style) { \ 78 PropertyCallbackInfo<ReturnValue> info(end()); \
144 NewFunction c = reinterpret_cast<NewFunction>(f); \ 79 f(arg1, info); \
145 PropertyCallbackInfo<ReturnValue> info(end()); \
146 c(arg1, info); \
147 } else { \
148 v8::AccessorInfo info(end()); \
149 v8::Handle<ReturnValue> return_value = f(arg1, info); \
150 if (!return_value.IsEmpty()) return return_value; \
151 } \
152 return GetReturnValue<ReturnValue>(isolate); \ 80 return GetReturnValue<ReturnValue>(isolate); \
153 } 81 }
154 82
155 #define WRITE_CALL_2(OldFunction, NewFunction, ReturnValue, Arg1, Arg2) \ 83
156 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(OldFunction f, \ 84 #define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2) \
85 v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \
157 Arg1 arg1, \ 86 Arg1 arg1, \
158 Arg2 arg2) { \ 87 Arg2 arg2) { \
159 Isolate* isolate = this->isolate(); \ 88 Isolate* isolate = this->isolate(); \
160 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
161 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
162 VMState<EXTERNAL> state(isolate); \ 89 VMState<EXTERNAL> state(isolate); \
163 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 90 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
164 if (new_style) { \ 91 PropertyCallbackInfo<ReturnValue> info(end()); \
165 NewFunction c = reinterpret_cast<NewFunction>(f); \ 92 f(arg1, arg2, info); \
166 PropertyCallbackInfo<ReturnValue> info(end()); \
167 c(arg1, arg2, info); \
168 } else { \
169 v8::AccessorInfo info(end()); \
170 v8::Handle<ReturnValue> return_value = f(arg1, arg2, info); \
171 if (!return_value.IsEmpty()) return return_value; \
172 } \
173 return GetReturnValue<ReturnValue>(isolate); \ 93 return GetReturnValue<ReturnValue>(isolate); \
174 } 94 }
175 95
176 #define WRITE_CALL_2_VOID(OldFunction, NewFunction, ReturnValue, Arg1, Arg2) \ 96
177 void PropertyCallbackArguments::Call(OldFunction f, \ 97 #define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \
98 void PropertyCallbackArguments::Call(Function f, \
178 Arg1 arg1, \ 99 Arg1 arg1, \
179 Arg2 arg2) { \ 100 Arg2 arg2) { \
180 Isolate* isolate = this->isolate(); \ 101 Isolate* isolate = this->isolate(); \
181 void* f_as_void = CallbackTable::FunctionToVoidPtr(f); \
182 bool new_style = CallbackTable::ReturnsVoid(isolate, f_as_void); \
183 VMState<EXTERNAL> state(isolate); \ 102 VMState<EXTERNAL> state(isolate); \
184 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 103 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
185 if (new_style) { \ 104 PropertyCallbackInfo<ReturnValue> info(end()); \
186 NewFunction c = reinterpret_cast<NewFunction>(f); \ 105 f(arg1, arg2, info); \
187 PropertyCallbackInfo<ReturnValue> info(end()); \
188 c(arg1, arg2, info); \
189 } else { \
190 v8::AccessorInfo info(end()); \
191 f(arg1, arg2, info); \
192 } \
193 } 106 }
194 107
108
195 FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0) 109 FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0)
196 FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1) 110 FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1)
197 FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2) 111 FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2)
198 FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID) 112 FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID)
199 113
200 #undef WRITE_CALL_0 114 #undef WRITE_CALL_0
201 #undef WRITE_CALL_1 115 #undef WRITE_CALL_1
202 #undef WRITE_CALL_2 116 #undef WRITE_CALL_2
203 #undef WRITE_CALL_2_VOID 117 #undef WRITE_CALL_2_VOID
204 118
205 119
206 } } // namespace v8::internal 120 } } // namespace v8::internal
207 121
OLDNEW
« no previous file with comments | « src/arguments.h ('k') | src/arm/stub-cache-arm.cc » ('j') | src/arm/stub-cache-arm.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698