OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_API_H_ | 5 #ifndef V8_API_H_ |
6 #define V8_API_H_ | 6 #define V8_API_H_ |
7 | 7 |
8 #include "include/v8-testing.h" | 8 #include "include/v8-testing.h" |
9 #include "src/contexts.h" | 9 #include "src/contexts.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
11 #include "src/isolate.h" | 11 #include "src/isolate.h" |
12 #include "src/list.h" | 12 #include "src/list.h" |
13 #include "src/objects-inl.h" | 13 #include "src/objects-inl.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 | 16 |
17 // Constants used in the implementation of the API. The most natural thing | 17 // Constants used in the implementation of the API. The most natural thing |
18 // would usually be to place these with the classes that use them, but | 18 // would usually be to place these with the classes that use them, but |
19 // we want to keep them out of v8.h because it is an externally | 19 // we want to keep them out of v8.h because it is an externally |
20 // visible file. | 20 // visible file. |
21 class Consts { | 21 class Consts { |
22 public: | 22 public: |
23 enum TemplateType { | 23 enum TemplateType { |
24 FUNCTION_TEMPLATE = 0, | 24 FUNCTION_TEMPLATE = 0, |
25 OBJECT_TEMPLATE = 1 | 25 OBJECT_TEMPLATE = 1 |
26 }; | 26 }; |
27 }; | 27 }; |
28 | 28 |
29 | |
30 // Utilities for working with neander-objects, primitive | |
31 // env-independent JSObjects used by the api. | |
32 class NeanderObject { | |
33 public: | |
34 explicit NeanderObject(v8::internal::Isolate* isolate, int size); | |
35 explicit inline NeanderObject(v8::internal::Handle<v8::internal::Object> obj); | |
36 explicit inline NeanderObject(v8::internal::Object* obj); | |
37 inline v8::internal::Object* get(int index); | |
38 inline void set(int index, v8::internal::Object* value); | |
39 inline v8::internal::Handle<v8::internal::JSObject> value() { return value_; } | |
40 int size(); | |
41 private: | |
42 v8::internal::Handle<v8::internal::JSObject> value_; | |
43 }; | |
44 | |
45 | |
46 NeanderObject::NeanderObject(v8::internal::Handle<v8::internal::Object> obj) | |
47 : value_(v8::internal::Handle<v8::internal::JSObject>::cast(obj)) { } | |
48 | |
49 | |
50 NeanderObject::NeanderObject(v8::internal::Object* obj) | |
51 : value_(v8::internal::Handle<v8::internal::JSObject>( | |
52 v8::internal::JSObject::cast(obj))) { } | |
53 | |
54 | |
55 v8::internal::Object* NeanderObject::get(int offset) { | |
56 DCHECK(value()->HasFastObjectElements()); | |
57 return v8::internal::FixedArray::cast(value()->elements())->get(offset); | |
58 } | |
59 | |
60 | |
61 void NeanderObject::set(int offset, v8::internal::Object* value) { | |
62 DCHECK(value_->HasFastObjectElements()); | |
63 v8::internal::FixedArray::cast(value_->elements())->set(offset, value); | |
64 } | |
65 | |
66 | |
67 template <typename T> inline T ToCData(v8::internal::Object* obj) { | 29 template <typename T> inline T ToCData(v8::internal::Object* obj) { |
68 STATIC_ASSERT(sizeof(T) == sizeof(v8::internal::Address)); | 30 STATIC_ASSERT(sizeof(T) == sizeof(v8::internal::Address)); |
69 if (obj == v8::internal::Smi::FromInt(0)) return nullptr; | 31 if (obj == v8::internal::Smi::FromInt(0)) return nullptr; |
70 return reinterpret_cast<T>( | 32 return reinterpret_cast<T>( |
71 reinterpret_cast<intptr_t>( | 33 reinterpret_cast<intptr_t>( |
72 v8::internal::Foreign::cast(obj)->foreign_address())); | 34 v8::internal::Foreign::cast(obj)->foreign_address())); |
73 } | 35 } |
74 | 36 |
75 | 37 |
76 template <typename T> | 38 template <typename T> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 class Utils { | 113 class Utils { |
152 public: | 114 public: |
153 static inline bool ApiCheck(bool condition, | 115 static inline bool ApiCheck(bool condition, |
154 const char* location, | 116 const char* location, |
155 const char* message) { | 117 const char* message) { |
156 if (!condition) Utils::ReportApiFailure(location, message); | 118 if (!condition) Utils::ReportApiFailure(location, message); |
157 return condition; | 119 return condition; |
158 } | 120 } |
159 static void ReportOOMFailure(const char* location, bool is_heap_oom); | 121 static void ReportOOMFailure(const char* location, bool is_heap_oom); |
160 | 122 |
161 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); | |
162 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); | |
163 | |
164 static inline Local<Context> ToLocal( | 123 static inline Local<Context> ToLocal( |
165 v8::internal::Handle<v8::internal::Context> obj); | 124 v8::internal::Handle<v8::internal::Context> obj); |
166 static inline Local<Value> ToLocal( | 125 static inline Local<Value> ToLocal( |
167 v8::internal::Handle<v8::internal::Object> obj); | 126 v8::internal::Handle<v8::internal::Object> obj); |
168 static inline Local<Name> ToLocal( | 127 static inline Local<Name> ToLocal( |
169 v8::internal::Handle<v8::internal::Name> obj); | 128 v8::internal::Handle<v8::internal::Name> obj); |
170 static inline Local<String> ToLocal( | 129 static inline Local<String> ToLocal( |
171 v8::internal::Handle<v8::internal::String> obj); | 130 v8::internal::Handle<v8::internal::String> obj); |
172 static inline Local<Symbol> ToLocal( | 131 static inline Local<Symbol> ToLocal( |
173 v8::internal::Handle<v8::internal::Symbol> obj); | 132 v8::internal::Handle<v8::internal::Symbol> obj); |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 } | 646 } |
688 | 647 |
689 private: | 648 private: |
690 static v8::Testing::StressType stress_type_; | 649 static v8::Testing::StressType stress_type_; |
691 }; | 650 }; |
692 | 651 |
693 } // namespace internal | 652 } // namespace internal |
694 } // namespace v8 | 653 } // namespace v8 |
695 | 654 |
696 #endif // V8_API_H_ | 655 #endif // V8_API_H_ |
OLD | NEW |