| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 FUNCTION_TEMPLATE = 0, | 49 FUNCTION_TEMPLATE = 0, |
| 50 OBJECT_TEMPLATE = 1 | 50 OBJECT_TEMPLATE = 1 |
| 51 }; | 51 }; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 | 54 |
| 55 // Utilities for working with neander-objects, primitive | 55 // Utilities for working with neander-objects, primitive |
| 56 // env-independent JSObjects used by the api. | 56 // env-independent JSObjects used by the api. |
| 57 class NeanderObject { | 57 class NeanderObject { |
| 58 public: | 58 public: |
| 59 explicit NeanderObject(int size); | 59 explicit NeanderObject(v8::internal::Isolate* isolate, int size); |
| 60 explicit inline NeanderObject(v8::internal::Handle<v8::internal::Object> obj); | 60 explicit inline NeanderObject(v8::internal::Handle<v8::internal::Object> obj); |
| 61 explicit inline NeanderObject(v8::internal::Object* obj); | 61 explicit inline NeanderObject(v8::internal::Object* obj); |
| 62 inline v8::internal::Object* get(int index); | 62 inline v8::internal::Object* get(int index); |
| 63 inline void set(int index, v8::internal::Object* value); | 63 inline void set(int index, v8::internal::Object* value); |
| 64 inline v8::internal::Handle<v8::internal::JSObject> value() { return value_; } | 64 inline v8::internal::Handle<v8::internal::JSObject> value() { return value_; } |
| 65 int size(); | 65 int size(); |
| 66 private: | 66 private: |
| 67 v8::internal::Handle<v8::internal::JSObject> value_; | 67 v8::internal::Handle<v8::internal::JSObject> value_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 | 70 |
| 71 // Utilities for working with neander-arrays, a simple extensible | 71 // Utilities for working with neander-arrays, a simple extensible |
| 72 // array abstraction built on neander-objects. | 72 // array abstraction built on neander-objects. |
| 73 class NeanderArray { | 73 class NeanderArray { |
| 74 public: | 74 public: |
| 75 NeanderArray(); | 75 explicit NeanderArray(v8::internal::Isolate* isolate); |
| 76 explicit inline NeanderArray(v8::internal::Handle<v8::internal::Object> obj); | 76 explicit inline NeanderArray(v8::internal::Handle<v8::internal::Object> obj); |
| 77 inline v8::internal::Handle<v8::internal::JSObject> value() { | 77 inline v8::internal::Handle<v8::internal::JSObject> value() { |
| 78 return obj_.value(); | 78 return obj_.value(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void add(v8::internal::Handle<v8::internal::Object> value); | 81 void add(v8::internal::Handle<v8::internal::Object> value); |
| 82 | 82 |
| 83 int length(); | 83 int length(); |
| 84 | 84 |
| 85 v8::internal::Object* get(int index); | 85 v8::internal::Object* get(int index); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 V(Message, JSObject) \ | 189 V(Message, JSObject) \ |
| 190 V(Context, Context) \ | 190 V(Context, Context) \ |
| 191 V(External, Foreign) \ | 191 V(External, Foreign) \ |
| 192 V(StackTrace, JSArray) \ | 192 V(StackTrace, JSArray) \ |
| 193 V(StackFrame, JSObject) \ | 193 V(StackFrame, JSObject) \ |
| 194 V(DeclaredAccessorDescriptor, DeclaredAccessorDescriptor) | 194 V(DeclaredAccessorDescriptor, DeclaredAccessorDescriptor) |
| 195 | 195 |
| 196 | 196 |
| 197 class Utils { | 197 class Utils { |
| 198 public: | 198 public: |
| 199 static bool ReportApiFailure(const char* location, const char* message); | 199 static inline bool ApiCheck(bool condition, |
| 200 const char* location, |
| 201 const char* message) { |
| 202 if (!condition) Utils::ReportApiFailure(location, message); |
| 203 return condition; |
| 204 } |
| 200 | 205 |
| 201 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); | 206 static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj); |
| 202 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); | 207 static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj); |
| 203 | 208 |
| 204 static inline Local<Context> ToLocal( | 209 static inline Local<Context> ToLocal( |
| 205 v8::internal::Handle<v8::internal::Context> obj); | 210 v8::internal::Handle<v8::internal::Context> obj); |
| 206 static inline Local<Value> ToLocal( | 211 static inline Local<Value> ToLocal( |
| 207 v8::internal::Handle<v8::internal::Object> obj); | 212 v8::internal::Handle<v8::internal::Object> obj); |
| 208 static inline Local<Function> ToLocal( | 213 static inline Local<Function> ToLocal( |
| 209 v8::internal::Handle<v8::internal::JSFunction> obj); | 214 v8::internal::Handle<v8::internal::JSFunction> obj); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 template <class T> | 301 template <class T> |
| 297 static inline v8::internal::Handle<v8::internal::Object> OpenPersistent( | 302 static inline v8::internal::Handle<v8::internal::Object> OpenPersistent( |
| 298 v8::Persistent<T>* persistent) { | 303 v8::Persistent<T>* persistent) { |
| 299 return OpenPersistent(*persistent); | 304 return OpenPersistent(*persistent); |
| 300 } | 305 } |
| 301 | 306 |
| 302 template <class From, class To> | 307 template <class From, class To> |
| 303 static inline v8::internal::Handle<To> OpenHandle(v8::Local<From> handle) { | 308 static inline v8::internal::Handle<To> OpenHandle(v8::Local<From> handle) { |
| 304 return OpenHandle(*handle); | 309 return OpenHandle(*handle); |
| 305 } | 310 } |
| 311 |
| 312 private: |
| 313 static void ReportApiFailure(const char* location, const char* message); |
| 306 }; | 314 }; |
| 307 | 315 |
| 308 | 316 |
| 309 template <class T> | 317 template <class T> |
| 310 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( | 318 v8::internal::Handle<T> v8::internal::Handle<T>::EscapeFrom( |
| 311 v8::EscapableHandleScope* scope) { | 319 v8::EscapableHandleScope* scope) { |
| 312 v8::internal::Handle<T> handle; | 320 v8::internal::Handle<T> handle; |
| 313 if (!is_null()) { | 321 if (!is_null()) { |
| 314 handle = *this; | 322 handle = *this; |
| 315 } | 323 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 544 |
| 537 | 545 |
| 538 inline internal::Object** GetSpareOrNewBlock(); | 546 inline internal::Object** GetSpareOrNewBlock(); |
| 539 inline void DeleteExtensions(internal::Object** prev_limit); | 547 inline void DeleteExtensions(internal::Object** prev_limit); |
| 540 | 548 |
| 541 inline void IncrementCallDepth() {call_depth_++;} | 549 inline void IncrementCallDepth() {call_depth_++;} |
| 542 inline void DecrementCallDepth() {call_depth_--;} | 550 inline void DecrementCallDepth() {call_depth_--;} |
| 543 inline bool CallDepthIsZero() { return call_depth_ == 0; } | 551 inline bool CallDepthIsZero() { return call_depth_ == 0; } |
| 544 | 552 |
| 545 inline void EnterContext(Handle<Context> context); | 553 inline void EnterContext(Handle<Context> context); |
| 546 inline bool LeaveContext(Handle<Context> context); | 554 inline void LeaveContext(); |
| 555 inline bool LastEnteredContextWas(Handle<Context> context); |
| 547 | 556 |
| 548 // Returns the last entered context or an empty handle if no | 557 // Returns the last entered context or an empty handle if no |
| 549 // contexts have been entered. | 558 // contexts have been entered. |
| 550 inline Handle<Context> LastEnteredContext(); | 559 inline Handle<Context> LastEnteredContext(); |
| 551 | 560 |
| 552 inline void SaveContext(Context* context); | 561 inline void SaveContext(Context* context); |
| 553 inline Context* RestoreContext(); | 562 inline Context* RestoreContext(); |
| 554 inline bool HasSavedContexts(); | 563 inline bool HasSavedContexts(); |
| 555 | 564 |
| 556 inline List<internal::Object**>* blocks() { return &blocks_; } | 565 inline List<internal::Object**>* blocks() { return &blocks_; } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 bool HandleScopeImplementer::HasSavedContexts() { | 637 bool HandleScopeImplementer::HasSavedContexts() { |
| 629 return !saved_contexts_.is_empty(); | 638 return !saved_contexts_.is_empty(); |
| 630 } | 639 } |
| 631 | 640 |
| 632 | 641 |
| 633 void HandleScopeImplementer::EnterContext(Handle<Context> context) { | 642 void HandleScopeImplementer::EnterContext(Handle<Context> context) { |
| 634 entered_contexts_.Add(*context); | 643 entered_contexts_.Add(*context); |
| 635 } | 644 } |
| 636 | 645 |
| 637 | 646 |
| 638 bool HandleScopeImplementer::LeaveContext(Handle<Context> context) { | 647 void HandleScopeImplementer::LeaveContext() { |
| 639 if (entered_contexts_.is_empty()) return false; | |
| 640 // TODO(dcarney): figure out what's wrong here | |
| 641 // if (entered_contexts_.last() != *context) return false; | |
| 642 entered_contexts_.RemoveLast(); | 648 entered_contexts_.RemoveLast(); |
| 643 return true; | |
| 644 } | 649 } |
| 645 | 650 |
| 646 | 651 |
| 652 bool HandleScopeImplementer::LastEnteredContextWas(Handle<Context> context) { |
| 653 return !entered_contexts_.is_empty() && entered_contexts_.last() == *context; |
| 654 } |
| 655 |
| 656 |
| 647 Handle<Context> HandleScopeImplementer::LastEnteredContext() { | 657 Handle<Context> HandleScopeImplementer::LastEnteredContext() { |
| 648 if (entered_contexts_.is_empty()) return Handle<Context>::null(); | 658 if (entered_contexts_.is_empty()) return Handle<Context>::null(); |
| 649 return Handle<Context>(entered_contexts_.last()); | 659 return Handle<Context>(entered_contexts_.last()); |
| 650 } | 660 } |
| 651 | 661 |
| 652 | 662 |
| 653 // If there's a spare block, use it for growing the current scope. | 663 // If there's a spare block, use it for growing the current scope. |
| 654 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() { | 664 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() { |
| 655 internal::Object** block = (spare_ != NULL) ? | 665 internal::Object** block = (spare_ != NULL) ? |
| 656 spare_ : | 666 spare_ : |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 stress_type_ = stress_type; | 717 stress_type_ = stress_type; |
| 708 } | 718 } |
| 709 | 719 |
| 710 private: | 720 private: |
| 711 static v8::Testing::StressType stress_type_; | 721 static v8::Testing::StressType stress_type_; |
| 712 }; | 722 }; |
| 713 | 723 |
| 714 } } // namespace v8::internal | 724 } } // namespace v8::internal |
| 715 | 725 |
| 716 #endif // V8_API_H_ | 726 #endif // V8_API_H_ |
| OLD | NEW |