122927959804bb5d21ffeef0d693c252b00d31b1
[platform/upstream/v8.git] / src / api.h
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
3 // found in the LICENSE file.
4
5 #ifndef V8_API_H_
6 #define V8_API_H_
7
8 #include "include/v8-testing.h"
9 #include "src/contexts.h"
10 #include "src/factory.h"
11 #include "src/isolate.h"
12 #include "src/list.h"
13 #include "src/objects-inl.h"
14
15 namespace v8 {
16
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
19 // we want to keep them out of v8.h because it is an externally
20 // visible file.
21 class Consts {
22  public:
23   enum TemplateType {
24     FUNCTION_TEMPLATE = 0,
25     OBJECT_TEMPLATE = 1
26   };
27 };
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 // Utilities for working with neander-arrays, a simple extensible
47 // array abstraction built on neander-objects.
48 class NeanderArray {
49  public:
50   explicit NeanderArray(v8::internal::Isolate* isolate);
51   explicit inline NeanderArray(v8::internal::Handle<v8::internal::Object> obj);
52   inline v8::internal::Handle<v8::internal::JSObject> value() {
53     return obj_.value();
54   }
55
56   void add(internal::Isolate* isolate,
57            v8::internal::Handle<v8::internal::Object> value);
58
59   int length();
60
61   v8::internal::Object* get(int index);
62   // Change the value at an index to undefined value. If the index is
63   // out of bounds, the request is ignored. Returns the old value.
64   void set(int index, v8::internal::Object* value);
65  private:
66   NeanderObject obj_;
67 };
68
69
70 NeanderObject::NeanderObject(v8::internal::Handle<v8::internal::Object> obj)
71     : value_(v8::internal::Handle<v8::internal::JSObject>::cast(obj)) { }
72
73
74 NeanderObject::NeanderObject(v8::internal::Object* obj)
75     : value_(v8::internal::Handle<v8::internal::JSObject>(
76         v8::internal::JSObject::cast(obj))) { }
77
78
79 NeanderArray::NeanderArray(v8::internal::Handle<v8::internal::Object> obj)
80     : obj_(obj) { }
81
82
83 v8::internal::Object* NeanderObject::get(int offset) {
84   DCHECK(value()->HasFastObjectElements());
85   return v8::internal::FixedArray::cast(value()->elements())->get(offset);
86 }
87
88
89 void NeanderObject::set(int offset, v8::internal::Object* value) {
90   DCHECK(value_->HasFastObjectElements());
91   v8::internal::FixedArray::cast(value_->elements())->set(offset, value);
92 }
93
94
95 template <typename T> inline T ToCData(v8::internal::Object* obj) {
96   STATIC_ASSERT(sizeof(T) == sizeof(v8::internal::Address));
97   if (obj == v8::internal::Smi::FromInt(0)) return nullptr;
98   return reinterpret_cast<T>(
99       reinterpret_cast<intptr_t>(
100           v8::internal::Foreign::cast(obj)->foreign_address()));
101 }
102
103
104 template <typename T>
105 inline v8::internal::Handle<v8::internal::Object> FromCData(
106     v8::internal::Isolate* isolate, T obj) {
107   STATIC_ASSERT(sizeof(T) == sizeof(v8::internal::Address));
108   if (obj == nullptr) return handle(v8::internal::Smi::FromInt(0), isolate);
109   return isolate->factory()->NewForeign(
110       reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(obj)));
111 }
112
113
114 class ApiFunction {
115  public:
116   explicit ApiFunction(v8::internal::Address addr) : addr_(addr) { }
117   v8::internal::Address address() { return addr_; }
118  private:
119   v8::internal::Address addr_;
120 };
121
122
123
124 class RegisteredExtension {
125  public:
126   explicit RegisteredExtension(Extension* extension);
127   static void Register(RegisteredExtension* that);
128   static void UnregisterAll();
129   Extension* extension() { return extension_; }
130   RegisteredExtension* next() { return next_; }
131   static RegisteredExtension* first_extension() { return first_extension_; }
132  private:
133   Extension* extension_;
134   RegisteredExtension* next_;
135   static RegisteredExtension* first_extension_;
136 };
137
138
139 #define OPEN_HANDLE_LIST(V)                  \
140   V(Template, TemplateInfo)                  \
141   V(FunctionTemplate, FunctionTemplateInfo)  \
142   V(ObjectTemplate, ObjectTemplateInfo)      \
143   V(Signature, FunctionTemplateInfo)         \
144   V(AccessorSignature, FunctionTemplateInfo) \
145   V(TypeSwitch, TypeSwitchInfo)              \
146   V(Data, Object)                            \
147   V(RegExp, JSRegExp)                        \
148   V(Object, JSObject)                        \
149   V(Array, JSArray)                          \
150   V(Map, JSMap)                              \
151   V(Set, JSSet)                              \
152   V(ArrayBuffer, JSArrayBuffer)              \
153   V(ArrayBufferView, JSArrayBufferView)      \
154   V(TypedArray, JSTypedArray)                \
155   V(Uint8Array, JSTypedArray)                \
156   V(Uint8ClampedArray, JSTypedArray)         \
157   V(Int8Array, JSTypedArray)                 \
158   V(Uint16Array, JSTypedArray)               \
159   V(Int16Array, JSTypedArray)                \
160   V(Uint32Array, JSTypedArray)               \
161   V(Int32Array, JSTypedArray)                \
162   V(Float32Array, JSTypedArray)              \
163   V(Float64Array, JSTypedArray)              \
164   V(DataView, JSDataView)                    \
165   V(SharedArrayBuffer, JSArrayBuffer)        \
166   V(Name, Name)                              \
167   V(String, String)                          \
168   V(Symbol, Symbol)                          \
169   V(Script, JSFunction)                      \
170   V(UnboundScript, SharedFunctionInfo)       \
171   V(Function, JSFunction)                    \
172   V(Message, JSMessageObject)                \
173   V(Context, Context)                        \
174   V(External, Object)                        \
175   V(StackTrace, JSArray)                     \
176   V(StackFrame, JSObject)                    \
177   V(NativeWeakMap, JSWeakMap)
178
179 class Utils {
180  public:
181   static inline bool ApiCheck(bool condition,
182                               const char* location,
183                               const char* message) {
184     if (!condition) Utils::ReportApiFailure(location, message);
185     return condition;
186   }
187
188   static Local<FunctionTemplate> ToFunctionTemplate(NeanderObject obj);
189   static Local<ObjectTemplate> ToObjectTemplate(NeanderObject obj);
190
191   static inline Local<Context> ToLocal(
192       v8::internal::Handle<v8::internal::Context> obj);
193   static inline Local<Value> ToLocal(
194       v8::internal::Handle<v8::internal::Object> obj);
195   static inline Local<Function> ToLocal(
196       v8::internal::Handle<v8::internal::JSFunction> obj);
197   static inline Local<Name> ToLocal(
198       v8::internal::Handle<v8::internal::Name> obj);
199   static inline Local<String> ToLocal(
200       v8::internal::Handle<v8::internal::String> obj);
201   static inline Local<Symbol> ToLocal(
202       v8::internal::Handle<v8::internal::Symbol> obj);
203   static inline Local<RegExp> ToLocal(
204       v8::internal::Handle<v8::internal::JSRegExp> obj);
205   static inline Local<Object> ToLocal(
206       v8::internal::Handle<v8::internal::JSObject> obj);
207   static inline Local<Array> ToLocal(
208       v8::internal::Handle<v8::internal::JSArray> obj);
209   static inline Local<Map> ToLocal(
210       v8::internal::Handle<v8::internal::JSMap> obj);
211   static inline Local<Set> ToLocal(
212       v8::internal::Handle<v8::internal::JSSet> obj);
213   static inline Local<ArrayBuffer> ToLocal(
214       v8::internal::Handle<v8::internal::JSArrayBuffer> obj);
215   static inline Local<ArrayBufferView> ToLocal(
216       v8::internal::Handle<v8::internal::JSArrayBufferView> obj);
217   static inline Local<DataView> ToLocal(
218       v8::internal::Handle<v8::internal::JSDataView> obj);
219
220   static inline Local<TypedArray> ToLocal(
221       v8::internal::Handle<v8::internal::JSTypedArray> obj);
222   static inline Local<Uint8Array> ToLocalUint8Array(
223       v8::internal::Handle<v8::internal::JSTypedArray> obj);
224   static inline Local<Uint8ClampedArray> ToLocalUint8ClampedArray(
225       v8::internal::Handle<v8::internal::JSTypedArray> obj);
226   static inline Local<Int8Array> ToLocalInt8Array(
227       v8::internal::Handle<v8::internal::JSTypedArray> obj);
228   static inline Local<Uint16Array> ToLocalUint16Array(
229       v8::internal::Handle<v8::internal::JSTypedArray> obj);
230   static inline Local<Int16Array> ToLocalInt16Array(
231       v8::internal::Handle<v8::internal::JSTypedArray> obj);
232   static inline Local<Uint32Array> ToLocalUint32Array(
233       v8::internal::Handle<v8::internal::JSTypedArray> obj);
234   static inline Local<Int32Array> ToLocalInt32Array(
235       v8::internal::Handle<v8::internal::JSTypedArray> obj);
236   static inline Local<Float32Array> ToLocalFloat32Array(
237       v8::internal::Handle<v8::internal::JSTypedArray> obj);
238   static inline Local<Float64Array> ToLocalFloat64Array(
239       v8::internal::Handle<v8::internal::JSTypedArray> obj);
240
241   static inline Local<SharedArrayBuffer> ToLocalShared(
242       v8::internal::Handle<v8::internal::JSArrayBuffer> obj);
243
244   static inline Local<Message> MessageToLocal(
245       v8::internal::Handle<v8::internal::Object> obj);
246   static inline Local<Promise> PromiseToLocal(
247       v8::internal::Handle<v8::internal::JSObject> obj);
248   static inline Local<StackTrace> StackTraceToLocal(
249       v8::internal::Handle<v8::internal::JSArray> obj);
250   static inline Local<StackFrame> StackFrameToLocal(
251       v8::internal::Handle<v8::internal::JSObject> obj);
252   static inline Local<Number> NumberToLocal(
253       v8::internal::Handle<v8::internal::Object> obj);
254   static inline Local<Integer> IntegerToLocal(
255       v8::internal::Handle<v8::internal::Object> obj);
256   static inline Local<Uint32> Uint32ToLocal(
257       v8::internal::Handle<v8::internal::Object> obj);
258   static inline Local<FunctionTemplate> ToLocal(
259       v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj);
260   static inline Local<ObjectTemplate> ToLocal(
261       v8::internal::Handle<v8::internal::ObjectTemplateInfo> obj);
262   static inline Local<Signature> SignatureToLocal(
263       v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj);
264   static inline Local<AccessorSignature> AccessorSignatureToLocal(
265       v8::internal::Handle<v8::internal::FunctionTemplateInfo> obj);
266   static inline Local<TypeSwitch> ToLocal(
267       v8::internal::Handle<v8::internal::TypeSwitchInfo> obj);
268   static inline Local<External> ExternalToLocal(
269       v8::internal::Handle<v8::internal::JSObject> obj);
270   static inline Local<NativeWeakMap> NativeWeakMapToLocal(
271       v8::internal::Handle<v8::internal::JSWeakMap> obj);
272
273 #define DECLARE_OPEN_HANDLE(From, To) \
274   static inline v8::internal::Handle<v8::internal::To> \
275       OpenHandle(const From* that, bool allow_empty_handle = false);
276
277 OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE)
278
279 #undef DECLARE_OPEN_HANDLE
280
281   template<class From, class To>
282   static inline Local<To> Convert(v8::internal::Handle<From> obj) {
283     DCHECK(obj.is_null() || !obj->IsTheHole());
284     return Local<To>(reinterpret_cast<To*>(obj.location()));
285   }
286
287   template <class T>
288   static inline v8::internal::Handle<v8::internal::Object> OpenPersistent(
289       const v8::Persistent<T>& persistent) {
290     return v8::internal::Handle<v8::internal::Object>(
291         reinterpret_cast<v8::internal::Object**>(persistent.val_));
292   }
293
294   template <class T>
295   static inline v8::internal::Handle<v8::internal::Object> OpenPersistent(
296       v8::Persistent<T>* persistent) {
297     return OpenPersistent(*persistent);
298   }
299
300   template <class From, class To>
301   static inline v8::internal::Handle<To> OpenHandle(v8::Local<From> handle) {
302     return OpenHandle(*handle);
303   }
304
305  private:
306   static void ReportApiFailure(const char* location, const char* message);
307 };
308
309
310 template <class T>
311 inline T* ToApi(v8::internal::Handle<v8::internal::Object> obj) {
312   return reinterpret_cast<T*>(obj.location());
313 }
314
315 template <class T>
316 inline v8::Local<T> ToApiHandle(
317     v8::internal::Handle<v8::internal::Object> obj) {
318   return Utils::Convert<v8::internal::Object, T>(obj);
319 }
320
321
322 template <class T>
323 inline bool ToLocal(v8::internal::MaybeHandle<v8::internal::Object> maybe,
324                     Local<T>* local) {
325   v8::internal::Handle<v8::internal::Object> handle;
326   if (maybe.ToHandle(&handle)) {
327     *local = Utils::Convert<v8::internal::Object, T>(handle);
328     return true;
329   }
330   return false;
331 }
332
333
334 // Implementations of ToLocal
335
336 #define MAKE_TO_LOCAL(Name, From, To)                                       \
337   Local<v8::To> Utils::Name(v8::internal::Handle<v8::internal::From> obj) { \
338     return Convert<v8::internal::From, v8::To>(obj);  \
339   }
340
341
342 #define MAKE_TO_LOCAL_TYPED_ARRAY(Type, typeName, TYPE, ctype, size)  \
343   Local<v8::Type##Array> Utils::ToLocal##Type##Array(                 \
344       v8::internal::Handle<v8::internal::JSTypedArray> obj) {         \
345     DCHECK(obj->type() == v8::internal::kExternal##Type##Array);      \
346     return Convert<v8::internal::JSTypedArray, v8::Type##Array>(obj); \
347   }
348
349
350 MAKE_TO_LOCAL(ToLocal, Context, Context)
351 MAKE_TO_LOCAL(ToLocal, Object, Value)
352 MAKE_TO_LOCAL(ToLocal, JSFunction, Function)
353 MAKE_TO_LOCAL(ToLocal, Name, Name)
354 MAKE_TO_LOCAL(ToLocal, String, String)
355 MAKE_TO_LOCAL(ToLocal, Symbol, Symbol)
356 MAKE_TO_LOCAL(ToLocal, JSRegExp, RegExp)
357 MAKE_TO_LOCAL(ToLocal, JSObject, Object)
358 MAKE_TO_LOCAL(ToLocal, JSArray, Array)
359 MAKE_TO_LOCAL(ToLocal, JSMap, Map)
360 MAKE_TO_LOCAL(ToLocal, JSSet, Set)
361 MAKE_TO_LOCAL(ToLocal, JSArrayBuffer, ArrayBuffer)
362 MAKE_TO_LOCAL(ToLocal, JSArrayBufferView, ArrayBufferView)
363 MAKE_TO_LOCAL(ToLocal, JSDataView, DataView)
364 MAKE_TO_LOCAL(ToLocal, JSTypedArray, TypedArray)
365 MAKE_TO_LOCAL(ToLocalShared, JSArrayBuffer, SharedArrayBuffer)
366
367 TYPED_ARRAYS(MAKE_TO_LOCAL_TYPED_ARRAY)
368
369 MAKE_TO_LOCAL(ToLocal, FunctionTemplateInfo, FunctionTemplate)
370 MAKE_TO_LOCAL(ToLocal, ObjectTemplateInfo, ObjectTemplate)
371 MAKE_TO_LOCAL(SignatureToLocal, FunctionTemplateInfo, Signature)
372 MAKE_TO_LOCAL(AccessorSignatureToLocal, FunctionTemplateInfo, AccessorSignature)
373 MAKE_TO_LOCAL(ToLocal, TypeSwitchInfo, TypeSwitch)
374 MAKE_TO_LOCAL(MessageToLocal, Object, Message)
375 MAKE_TO_LOCAL(PromiseToLocal, JSObject, Promise)
376 MAKE_TO_LOCAL(StackTraceToLocal, JSArray, StackTrace)
377 MAKE_TO_LOCAL(StackFrameToLocal, JSObject, StackFrame)
378 MAKE_TO_LOCAL(NumberToLocal, Object, Number)
379 MAKE_TO_LOCAL(IntegerToLocal, Object, Integer)
380 MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)
381 MAKE_TO_LOCAL(ExternalToLocal, JSObject, External)
382 MAKE_TO_LOCAL(NativeWeakMapToLocal, JSWeakMap, NativeWeakMap)
383
384 #undef MAKE_TO_LOCAL_TYPED_ARRAY
385 #undef MAKE_TO_LOCAL
386
387
388 // Implementations of OpenHandle
389
390 #define MAKE_OPEN_HANDLE(From, To)                                             \
391   v8::internal::Handle<v8::internal::To> Utils::OpenHandle(                    \
392       const v8::From* that, bool allow_empty_handle) {                         \
393     DCHECK(allow_empty_handle || that != NULL);                                \
394     DCHECK(that == NULL ||                                                     \
395            (*reinterpret_cast<v8::internal::Object* const*>(that))->Is##To()); \
396     return v8::internal::Handle<v8::internal::To>(                             \
397         reinterpret_cast<v8::internal::To**>(const_cast<v8::From*>(that)));    \
398   }
399
400 OPEN_HANDLE_LIST(MAKE_OPEN_HANDLE)
401
402 #undef MAKE_OPEN_HANDLE
403 #undef OPEN_HANDLE_LIST
404
405
406 namespace internal {
407
408
409 class DeferredHandles {
410  public:
411   ~DeferredHandles();
412
413  private:
414   DeferredHandles(Object** first_block_limit, Isolate* isolate)
415       : next_(NULL),
416         previous_(NULL),
417         first_block_limit_(first_block_limit),
418         isolate_(isolate) {
419     isolate->LinkDeferredHandles(this);
420   }
421
422   void Iterate(ObjectVisitor* v);
423
424   List<Object**> blocks_;
425   DeferredHandles* next_;
426   DeferredHandles* previous_;
427   Object** first_block_limit_;
428   Isolate* isolate_;
429
430   friend class HandleScopeImplementer;
431   friend class Isolate;
432 };
433
434
435 // This class is here in order to be able to declare it a friend of
436 // HandleScope.  Moving these methods to be members of HandleScope would be
437 // neat in some ways, but it would expose internal implementation details in
438 // our public header file, which is undesirable.
439 //
440 // An isolate has a single instance of this class to hold the current thread's
441 // data. In multithreaded V8 programs this data is copied in and out of storage
442 // so that the currently executing thread always has its own copy of this
443 // data.
444 class HandleScopeImplementer {
445  public:
446   explicit HandleScopeImplementer(Isolate* isolate)
447       : isolate_(isolate),
448         blocks_(0),
449         entered_contexts_(0),
450         saved_contexts_(0),
451         spare_(NULL),
452         call_depth_(0),
453         last_handle_before_deferred_block_(NULL) { }
454
455   ~HandleScopeImplementer() {
456     DeleteArray(spare_);
457   }
458
459   // Threading support for handle data.
460   static int ArchiveSpacePerThread();
461   char* RestoreThread(char* from);
462   char* ArchiveThread(char* to);
463   void FreeThreadResources();
464
465   // Garbage collection support.
466   void Iterate(v8::internal::ObjectVisitor* v);
467   static char* Iterate(v8::internal::ObjectVisitor* v, char* data);
468
469
470   inline internal::Object** GetSpareOrNewBlock();
471   inline void DeleteExtensions(internal::Object** prev_limit);
472
473   inline void IncrementCallDepth() {call_depth_++;}
474   inline void DecrementCallDepth() {call_depth_--;}
475   inline bool CallDepthIsZero() { return call_depth_ == 0; }
476
477   inline void EnterContext(Handle<Context> context);
478   inline void LeaveContext();
479   inline bool LastEnteredContextWas(Handle<Context> context);
480
481   // Returns the last entered context or an empty handle if no
482   // contexts have been entered.
483   inline Handle<Context> LastEnteredContext();
484
485   inline void SaveContext(Context* context);
486   inline Context* RestoreContext();
487   inline bool HasSavedContexts();
488
489   inline List<internal::Object**>* blocks() { return &blocks_; }
490   Isolate* isolate() const { return isolate_; }
491
492   void ReturnBlock(Object** block) {
493     DCHECK(block != NULL);
494     if (spare_ != NULL) DeleteArray(spare_);
495     spare_ = block;
496   }
497
498  private:
499   void ResetAfterArchive() {
500     blocks_.Initialize(0);
501     entered_contexts_.Initialize(0);
502     saved_contexts_.Initialize(0);
503     spare_ = NULL;
504     last_handle_before_deferred_block_ = NULL;
505     call_depth_ = 0;
506   }
507
508   void Free() {
509     DCHECK(blocks_.length() == 0);
510     DCHECK(entered_contexts_.length() == 0);
511     DCHECK(saved_contexts_.length() == 0);
512     blocks_.Free();
513     entered_contexts_.Free();
514     saved_contexts_.Free();
515     if (spare_ != NULL) {
516       DeleteArray(spare_);
517       spare_ = NULL;
518     }
519     DCHECK(call_depth_ == 0);
520   }
521
522   void BeginDeferredScope();
523   DeferredHandles* Detach(Object** prev_limit);
524
525   Isolate* isolate_;
526   List<internal::Object**> blocks_;
527   // Used as a stack to keep track of entered contexts.
528   List<Context*> entered_contexts_;
529   // Used as a stack to keep track of saved contexts.
530   List<Context*> saved_contexts_;
531   Object** spare_;
532   int call_depth_;
533   Object** last_handle_before_deferred_block_;
534   // This is only used for threading support.
535   HandleScopeData handle_scope_data_;
536
537   void IterateThis(ObjectVisitor* v);
538   char* RestoreThreadHelper(char* from);
539   char* ArchiveThreadHelper(char* to);
540
541   friend class DeferredHandles;
542   friend class DeferredHandleScope;
543
544   DISALLOW_COPY_AND_ASSIGN(HandleScopeImplementer);
545 };
546
547
548 const int kHandleBlockSize = v8::internal::KB - 2;  // fit in one page
549
550
551 void HandleScopeImplementer::SaveContext(Context* context) {
552   saved_contexts_.Add(context);
553 }
554
555
556 Context* HandleScopeImplementer::RestoreContext() {
557   return saved_contexts_.RemoveLast();
558 }
559
560
561 bool HandleScopeImplementer::HasSavedContexts() {
562   return !saved_contexts_.is_empty();
563 }
564
565
566 void HandleScopeImplementer::EnterContext(Handle<Context> context) {
567   entered_contexts_.Add(*context);
568 }
569
570
571 void HandleScopeImplementer::LeaveContext() {
572   entered_contexts_.RemoveLast();
573 }
574
575
576 bool HandleScopeImplementer::LastEnteredContextWas(Handle<Context> context) {
577   return !entered_contexts_.is_empty() && entered_contexts_.last() == *context;
578 }
579
580
581 Handle<Context> HandleScopeImplementer::LastEnteredContext() {
582   if (entered_contexts_.is_empty()) return Handle<Context>::null();
583   return Handle<Context>(entered_contexts_.last());
584 }
585
586
587 // If there's a spare block, use it for growing the current scope.
588 internal::Object** HandleScopeImplementer::GetSpareOrNewBlock() {
589   internal::Object** block = (spare_ != NULL) ?
590       spare_ :
591       NewArray<internal::Object*>(kHandleBlockSize);
592   spare_ = NULL;
593   return block;
594 }
595
596
597 void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
598   while (!blocks_.is_empty()) {
599     internal::Object** block_start = blocks_.last();
600     internal::Object** block_limit = block_start + kHandleBlockSize;
601
602     // SealHandleScope may make the prev_limit to point inside the block.
603     if (block_start <= prev_limit && prev_limit <= block_limit) {
604 #ifdef ENABLE_HANDLE_ZAPPING
605       internal::HandleScope::ZapRange(prev_limit, block_limit);
606 #endif
607       break;
608     }
609
610     blocks_.RemoveLast();
611 #ifdef ENABLE_HANDLE_ZAPPING
612     internal::HandleScope::ZapRange(block_start, block_limit);
613 #endif
614     if (spare_ != NULL) {
615       DeleteArray(spare_);
616     }
617     spare_ = block_start;
618   }
619   DCHECK((blocks_.is_empty() && prev_limit == NULL) ||
620          (!blocks_.is_empty() && prev_limit != NULL));
621 }
622
623
624 // Interceptor functions called from generated inline caches to notify
625 // CPU profiler that external callbacks are invoked.
626 void InvokeAccessorGetterCallback(
627     v8::Local<v8::Name> property,
628     const v8::PropertyCallbackInfo<v8::Value>& info,
629     v8::AccessorNameGetterCallback getter);
630
631 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
632                             v8::FunctionCallback callback);
633
634 class Testing {
635  public:
636   static v8::Testing::StressType stress_type() { return stress_type_; }
637   static void set_stress_type(v8::Testing::StressType stress_type) {
638     stress_type_ = stress_type;
639   }
640
641  private:
642   static v8::Testing::StressType stress_type_;
643 };
644
645 } }  // namespace v8::internal
646
647 #endif  // V8_API_H_