OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 RegisteredExtension* next_auto() { return next_auto_; } | 152 RegisteredExtension* next_auto() { return next_auto_; } |
153 static RegisteredExtension* first_extension() { return first_extension_; } | 153 static RegisteredExtension* first_extension() { return first_extension_; } |
154 private: | 154 private: |
155 Extension* extension_; | 155 Extension* extension_; |
156 RegisteredExtension* next_; | 156 RegisteredExtension* next_; |
157 RegisteredExtension* next_auto_; | 157 RegisteredExtension* next_auto_; |
158 static RegisteredExtension* first_extension_; | 158 static RegisteredExtension* first_extension_; |
159 }; | 159 }; |
160 | 160 |
161 | 161 |
| 162 #define OPEN_HANDLE_LIST(V) \ |
| 163 V(Template, TemplateInfo) \ |
| 164 V(FunctionTemplate, FunctionTemplateInfo) \ |
| 165 V(ObjectTemplate, ObjectTemplateInfo) \ |
| 166 V(Signature, SignatureInfo) \ |
| 167 V(AccessorSignature, FunctionTemplateInfo) \ |
| 168 V(TypeSwitch, TypeSwitchInfo) \ |
| 169 V(Data, Object) \ |
| 170 V(RegExp, JSRegExp) \ |
| 171 V(Object, JSObject) \ |
| 172 V(Array, JSArray) \ |
| 173 V(String, String) \ |
| 174 V(Script, Object) \ |
| 175 V(Function, JSFunction) \ |
| 176 V(Message, JSObject) \ |
| 177 V(Context, Context) \ |
| 178 V(External, Foreign) \ |
| 179 V(StackTrace, JSArray) \ |
| 180 V(StackFrame, JSObject) |
| 181 |
| 182 |
162 class Utils { | 183 class Utils { |
163 public: | 184 public: |
164 static bool ReportApiFailure(const char* location, const char* message); | 185 static bool ReportApiFailure(const char* location, const char* message); |
165 | 186 |
166 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); | 187 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); |
167 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); | 188 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); |
168 | 189 |
169 static inline Local<Context> ToLocal( | 190 static inline Local<Context> ToLocal( |
170 v8::internal::Handle<v8::internal::Context> obj); | 191 v8::internal::Handle<v8::internal::Context> obj); |
171 static inline Local<Value> ToLocal( | 192 static inline Local<Value> ToLocal( |
(...skipping 26 matching lines...) Expand all Loading... |
198 v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj); | 219 v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj); |
199 static inline Local<ObjectTemplate> ToLocal( | 220 static inline Local<ObjectTemplate> ToLocal( |
200 v8::internal::Handle<v8::internal::ObjectTemplateInfo> obj); | 221 v8::internal::Handle<v8::internal::ObjectTemplateInfo> obj); |
201 static inline Local<Signature> ToLocal( | 222 static inline Local<Signature> ToLocal( |
202 v8::internal::Handle<v8::internal::SignatureInfo> obj); | 223 v8::internal::Handle<v8::internal::SignatureInfo> obj); |
203 static inline Local<AccessorSignature> AccessorSignatureToLocal( | 224 static inline Local<AccessorSignature> AccessorSignatureToLocal( |
204 v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj); | 225 v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj); |
205 static inline Local<TypeSwitch> ToLocal( | 226 static inline Local<TypeSwitch> ToLocal( |
206 v8::internal::Handle<v8::internal::TypeSwitchInfo> obj); | 227 v8::internal::Handle<v8::internal::TypeSwitchInfo> obj); |
207 | 228 |
208 static inline v8::internal::Handle<v8::internal::TemplateInfo> | 229 #define DECLARE_OPEN_HANDLE(From, To) \ |
209 OpenHandle(const Template* that); | 230 static inline v8::internal::Handle<v8::internal::To> \ |
210 static inline v8::internal::Handle<v8::internal::FunctionTemplateInfo> | 231 OpenHandle(const From* that, bool allow_empty_handle = false); |
211 OpenHandle(const FunctionTemplate* that); | 232 |
212 static inline v8::internal::Handle<v8::internal::ObjectTemplateInfo> | 233 OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE) |
213 OpenHandle(const ObjectTemplate* that); | 234 |
214 static inline v8::internal::Handle<v8::internal::Object> | 235 #undef DECLARE_OPEN_HANDLE |
215 OpenHandle(const Data* data); | |
216 static inline v8::internal::Handle<v8::internal::JSRegExp> | |
217 OpenHandle(const RegExp* data); | |
218 static inline v8::internal::Handle<v8::internal::JSObject> | |
219 OpenHandle(const v8::Object* data); | |
220 static inline v8::internal::Handle<v8::internal::JSArray> | |
221 OpenHandle(const v8::Array* data); | |
222 static inline v8::internal::Handle<v8::internal::String> | |
223 OpenHandle(const String* data); | |
224 static inline v8::internal::Handle<v8::internal::Object> | |
225 OpenHandle(const Script* data); | |
226 static inline v8::internal::Handle<v8::internal::JSFunction> | |
227 OpenHandle(const Function* data); | |
228 static inline v8::internal::Handle<v8::internal::JSObject> | |
229 OpenHandle(const Message* message); | |
230 static inline v8::internal::Handle<v8::internal::JSArray> | |
231 OpenHandle(const StackTrace* stack_trace); | |
232 static inline v8::internal::Handle<v8::internal::JSObject> | |
233 OpenHandle(const StackFrame* stack_frame); | |
234 static inline v8::internal::Handle<v8::internal::Context> | |
235 OpenHandle(const v8::Context* context); | |
236 static inline v8::internal::Handle<v8::internal::SignatureInfo> | |
237 OpenHandle(const v8::Signature* sig); | |
238 static inline v8::internal::Handle<v8::internal::FunctionTemplateInfo> | |
239 OpenHandle(const v8::AccessorSignature* sig); | |
240 static inline v8::internal::Handle<v8::internal::TypeSwitchInfo> | |
241 OpenHandle(const v8::TypeSwitch* that); | |
242 static inline v8::internal::Handle<v8::internal::Foreign> | |
243 OpenHandle(const v8::External* that); | |
244 }; | 236 }; |
245 | 237 |
246 | 238 |
247 template <class T> | 239 template <class T> |
248 inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { | 240 inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) { |
249 return reinterpret_cast<T*>(obj.location()); | 241 return reinterpret_cast<T*>(obj.location()); |
250 } | 242 } |
251 | 243 |
252 | 244 |
253 template <class T> | 245 template <class T> |
254 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( | 246 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( |
255 v8::HandleScope* scope) { | 247 v8::HandleScope* scope) { |
256 v8::internal::Handle<T> handle; | 248 v8::internal::Handle<T> handle; |
257 if (!is_null()) { | 249 if (!is_null()) { |
258 handle = *this; | 250 handle = *this; |
259 } | 251 } |
260 return Utils::OpenHandle(*scope->Close(Utils::ToLocal(handle))); | 252 return Utils::OpenHandle(*scope->Close(Utils::ToLocal(handle)), true); |
261 } | 253 } |
262 | 254 |
263 | 255 |
264 // Implementations of ToLocal | 256 // Implementations of ToLocal |
265 | 257 |
266 #define MAKE_TO_LOCAL(Name, From, To) \ | 258 #define MAKE_TO_LOCAL(Name, From, To) \ |
267 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ | 259 Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \ |
268 ASSERT(obj.is_null() || !obj->IsTheHole()); \ | 260 ASSERT(obj.is_null() || !obj->IsTheHole()); \ |
269 return Local<To>(reinterpret_cast<To*>(obj.location())); \ | 261 return Local<To>(reinterpret_cast<To*>(obj.location())); \ |
270 } | 262 } |
(...skipping 16 matching lines...) Expand all Loading... |
287 MAKE_TO_LOCAL(StackFrameToLocal, JSObject, StackFrame) | 279 MAKE_TO_LOCAL(StackFrameToLocal, JSObject, StackFrame) |
288 MAKE_TO_LOCAL(NumberToLocal, Object, Number) | 280 MAKE_TO_LOCAL(NumberToLocal, Object, Number) |
289 MAKE_TO_LOCAL(IntegerToLocal, Object, Integer) | 281 MAKE_TO_LOCAL(IntegerToLocal, Object, Integer) |
290 MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32) | 282 MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32) |
291 | 283 |
292 #undef MAKE_TO_LOCAL | 284 #undef MAKE_TO_LOCAL |
293 | 285 |
294 | 286 |
295 // Implementations of OpenHandle | 287 // Implementations of OpenHandle |
296 | 288 |
297 #define MAKE_OPEN_HANDLE(From, To) \ | 289 #define MAKE_OPEN_HANDLE(From, To) \ |
298 v8::internal::Handle<v8::internal::To> Utils::OpenHandle(\ | 290 v8::internal::Handle<v8::internal::To> Utils::OpenHandle( \ |
299 const v8::From* that) { \ | 291 const v8::From* that, bool allow_empty_handle) { \ |
300 return v8::internal::Handle<v8::internal::To>( \ | 292 EXTRA_CHECK(allow_empty_handle || that != NULL); \ |
| 293 return v8::internal::Handle<v8::internal::To>( \ |
301 reinterpret_cast<v8::internal::To**>(const_cast<v8::From*>(that))); \ | 294 reinterpret_cast<v8::internal::To**>(const_cast<v8::From*>(that))); \ |
302 } | 295 } |
303 | 296 |
304 MAKE_OPEN_HANDLE(Template, TemplateInfo) | 297 OPEN_HANDLE_LIST(MAKE_OPEN_HANDLE) |
305 MAKE_OPEN_HANDLE(FunctionTemplate, FunctionTemplateInfo) | |
306 MAKE_OPEN_HANDLE(ObjectTemplate, ObjectTemplateInfo) | |
307 MAKE_OPEN_HANDLE(Signature, SignatureInfo) | |
308 MAKE_OPEN_HANDLE(AccessorSignature, FunctionTemplateInfo) | |
309 MAKE_OPEN_HANDLE(TypeSwitch, TypeSwitchInfo) | |
310 MAKE_OPEN_HANDLE(Data, Object) | |
311 MAKE_OPEN_HANDLE(RegExp, JSRegExp) | |
312 MAKE_OPEN_HANDLE(Object, JSObject) | |
313 MAKE_OPEN_HANDLE(Array, JSArray) | |
314 MAKE_OPEN_HANDLE(String, String) | |
315 MAKE_OPEN_HANDLE(Script, Object) | |
316 MAKE_OPEN_HANDLE(Function, JSFunction) | |
317 MAKE_OPEN_HANDLE(Message, JSObject) | |
318 MAKE_OPEN_HANDLE(Context, Context) | |
319 MAKE_OPEN_HANDLE(External, Foreign) | |
320 MAKE_OPEN_HANDLE(StackTrace, JSArray) | |
321 MAKE_OPEN_HANDLE(StackFrame, JSObject) | |
322 | 298 |
323 #undef MAKE_OPEN_HANDLE | 299 #undef MAKE_OPEN_HANDLE |
| 300 #undef OPEN_HANDLE_LIST |
324 | 301 |
325 | 302 |
326 namespace internal { | 303 namespace internal { |
327 | 304 |
328 // Tracks string usage to help make better decisions when | 305 // Tracks string usage to help make better decisions when |
329 // externalizing strings. | 306 // externalizing strings. |
330 // | 307 // |
331 // Implementation note: internally this class only tracks fresh | 308 // Implementation note: internally this class only tracks fresh |
332 // strings and keeps a single use counter for them. | 309 // strings and keeps a single use counter for them. |
333 class StringTracker { | 310 class StringTracker { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 stress_type_ = stress_type; | 585 stress_type_ = stress_type; |
609 } | 586 } |
610 | 587 |
611 private: | 588 private: |
612 static v8::Testing::StressType stress_type_; | 589 static v8::Testing::StressType stress_type_; |
613 }; | 590 }; |
614 | 591 |
615 } } // namespace v8::internal | 592 } } // namespace v8::internal |
616 | 593 |
617 #endif // V8_API_H_ | 594 #endif // V8_API_H_ |
OLD | NEW |