8 #include "include/v8-testing.h" 9 #include "src/contexts.h" 10 #include "src/debug/debug-interface.h" 11 #include "src/detachable-vector.h" 12 #include "src/heap/factory.h" 13 #include "src/isolate.h" 14 #include "src/objects.h" 15 #include "src/objects/bigint.h" 16 #include "src/objects/js-collection.h" 17 #include "src/objects/js-generator.h" 18 #include "src/objects/js-promise.h" 19 #include "src/objects/js-proxy.h" 20 #include "src/objects/module.h" 21 #include "src/objects/shared-function-info.h" 23 #include "src/objects/templates.h" 34 FUNCTION_TEMPLATE = 0,
67 static void UnregisterAll();
68 Extension* extension() {
return extension_; }
72 Extension* extension_;
77 #define OPEN_HANDLE_LIST(V) \ 78 V(Template, TemplateInfo) \ 79 V(FunctionTemplate, FunctionTemplateInfo) \ 80 V(ObjectTemplate, ObjectTemplateInfo) \ 81 V(Signature, FunctionTemplateInfo) \ 82 V(AccessorSignature, FunctionTemplateInfo) \ 85 V(Object, JSReceiver) \ 89 V(ArrayBuffer, JSArrayBuffer) \ 90 V(ArrayBufferView, JSArrayBufferView) \ 91 V(TypedArray, JSTypedArray) \ 92 V(Uint8Array, JSTypedArray) \ 93 V(Uint8ClampedArray, JSTypedArray) \ 94 V(Int8Array, JSTypedArray) \ 95 V(Uint16Array, JSTypedArray) \ 96 V(Int16Array, JSTypedArray) \ 97 V(Uint32Array, JSTypedArray) \ 98 V(Int32Array, JSTypedArray) \ 99 V(Float32Array, JSTypedArray) \ 100 V(Float64Array, JSTypedArray) \ 101 V(DataView, JSDataView) \ 102 V(SharedArrayBuffer, JSArrayBuffer) \ 106 V(Script, JSFunction) \ 107 V(UnboundModuleScript, SharedFunctionInfo) \ 108 V(UnboundScript, SharedFunctionInfo) \ 110 V(Function, JSReceiver) \ 111 V(Message, JSMessageObject) \ 112 V(Context, Context) \ 113 V(External, Object) \ 114 V(StackTrace, FixedArray) \ 115 V(StackFrame, StackFrameInfo) \ 117 V(debug::GeneratorObject, JSGeneratorObject) \ 118 V(debug::Script, Script) \ 119 V(debug::WeakMap, JSWeakMap) \ 120 V(Promise, JSPromise) \ 121 V(Primitive, Object) \ 122 V(PrimitiveArray, FixedArray) \ 124 V(ScriptOrModule, Script) 128 static inline bool ApiCheck(
bool condition,
129 const char* location,
130 const char* message) {
131 if (!condition) Utils::ReportApiFailure(location, message);
135 const char* location,
bool is_heap_oom);
234 #define DECLARE_OPEN_HANDLE(From, To) \ 235 static inline v8::internal::Handle<v8::internal::To> \ 236 OpenHandle(const From* that, bool allow_empty_handle = false); 238 OPEN_HANDLE_LIST(DECLARE_OPEN_HANDLE)
240 #undef DECLARE_OPEN_HANDLE 242 template <
class From,
class To>
255 return OpenPersistent(*persistent);
258 template <
class From,
class To>
260 return OpenHandle(*handle);
264 static void ReportApiFailure(
const char* location,
const char* message);
270 return reinterpret_cast<T*
>(obj.location());
276 return Utils::Convert<v8::internal::Object, T>(obj);
284 if (maybe.ToHandle(&handle)) {
285 *local = Utils::Convert<v8::internal::Object, T>(handle);
301 first_block_limit_(first_block_limit),
303 isolate->LinkDeferredHandles(
this);
308 std::vector<Address*> blocks_;
334 microtasks_depth_(0),
335 microtasks_suppressions_(0),
336 entered_contexts_count_(0),
337 entered_context_count_during_microtasks_(0),
339 debug_microtasks_depth_(0),
341 microtasks_policy_(v8::MicrotasksPolicy::kAuto),
342 last_handle_before_deferred_block_(
nullptr) {
350 static int ArchiveSpacePerThread();
351 char* RestoreThread(
char* from);
352 char* ArchiveThread(
char* to);
353 void FreeThreadResources();
363 inline void IncrementCallDepth() {call_depth_++;}
364 inline void DecrementCallDepth() {call_depth_--;}
365 inline bool CallDepthIsZero() {
return call_depth_ == 0; }
369 inline void IncrementMicrotasksScopeDepth() {microtasks_depth_++;}
370 inline void DecrementMicrotasksScopeDepth() {microtasks_depth_--;}
371 inline int GetMicrotasksScopeDepth() {
return microtasks_depth_; }
375 inline void IncrementMicrotasksSuppressions() {microtasks_suppressions_++;}
376 inline void DecrementMicrotasksSuppressions() {microtasks_suppressions_--;}
377 inline bool HasMicrotasksSuppressions() {
return !!microtasks_suppressions_; }
382 inline void IncrementDebugMicrotasksScopeDepth() {debug_microtasks_depth_++;}
383 inline void DecrementDebugMicrotasksScopeDepth() {debug_microtasks_depth_--;}
384 inline bool DebugMicrotasksScopeDepthIsZero() {
385 return debug_microtasks_depth_ == 0;
389 inline void set_microtasks_policy(v8::MicrotasksPolicy policy);
390 inline v8::MicrotasksPolicy microtasks_policy()
const;
393 inline void LeaveContext();
402 inline void LeaveMicrotaskContext();
404 inline bool MicrotaskContextIsLastEnteredContext()
const {
405 return !microtask_context_.is_null() &&
406 entered_context_count_during_microtasks_ == entered_contexts_.size();
410 inline Context RestoreContext();
411 inline bool HasSavedContexts();
414 Isolate* isolate()
const {
return isolate_; }
416 void ReturnBlock(
Address* block) {
417 DCHECK_NOT_NULL(block);
418 if (spare_ !=
nullptr) DeleteArray(spare_);
423 void ResetAfterArchive() {
425 entered_contexts_.detach();
426 saved_contexts_.detach();
427 microtask_context_ =
Context();
428 entered_context_count_during_microtasks_ = 0;
430 last_handle_before_deferred_block_ =
nullptr;
435 DCHECK(blocks_.empty());
436 DCHECK(entered_contexts_.empty());
437 DCHECK(saved_contexts_.empty());
438 DCHECK(microtask_context_.is_null());
441 entered_contexts_.free();
442 saved_contexts_.free();
443 if (spare_ !=
nullptr) {
447 DCHECK_EQ(call_depth_, 0);
450 void BeginDeferredScope();
462 int microtasks_depth_;
463 int microtasks_suppressions_;
464 size_t entered_contexts_count_;
465 size_t entered_context_count_during_microtasks_;
467 int debug_microtasks_depth_;
469 v8::MicrotasksPolicy microtasks_policy_;
470 Address* last_handle_before_deferred_block_;
475 char* RestoreThreadHelper(
char* from);
476 char* ArchiveThreadHelper(
char* to);
490 kEnteredContextsCount =
492 kEnteredContextCountDuringMicrotasks = offsetof(
500 const int kHandleBlockSize = v8::internal::KB - 2;
503 void HandleScopeImplementer::set_microtasks_policy(
504 v8::MicrotasksPolicy policy) {
505 microtasks_policy_ = policy;
509 v8::MicrotasksPolicy HandleScopeImplementer::microtasks_policy()
const {
510 return microtasks_policy_;
513 void HandleScopeImplementer::SaveContext(Context context) {
514 saved_contexts_.push_back(context);
517 Context HandleScopeImplementer::RestoreContext() {
518 Context last_context = saved_contexts_.back();
519 saved_contexts_.pop_back();
524 bool HandleScopeImplementer::HasSavedContexts() {
525 return !saved_contexts_.empty();
529 void HandleScopeImplementer::EnterContext(Handle<Context> context) {
530 entered_contexts_.push_back(*context);
531 entered_contexts_count_ = entered_contexts_.size();
534 void HandleScopeImplementer::LeaveContext() {
535 entered_contexts_.pop_back();
536 entered_contexts_count_ = entered_contexts_.size();
539 bool HandleScopeImplementer::LastEnteredContextWas(Handle<Context> context) {
540 return !entered_contexts_.empty() && entered_contexts_.back() == *context;
543 void HandleScopeImplementer::EnterMicrotaskContext(Handle<Context> context) {
544 DCHECK(microtask_context_.is_null());
545 microtask_context_ = *context;
546 entered_context_count_during_microtasks_ = entered_contexts_.size();
549 void HandleScopeImplementer::LeaveMicrotaskContext() {
550 microtask_context_ = Context();
551 entered_context_count_during_microtasks_ = 0;
555 internal::Address* HandleScopeImplementer::GetSpareOrNewBlock() {
556 internal::Address* block =
557 (spare_ !=
nullptr) ? spare_
558 : NewArray<internal::Address>(kHandleBlockSize);
563 void HandleScopeImplementer::DeleteExtensions(internal::Address* prev_limit) {
564 while (!blocks_.empty()) {
565 internal::Address* block_start = blocks_.back();
566 internal::Address* block_limit = block_start + kHandleBlockSize;
571 if (reinterpret_cast<Address>(block_start) <=
572 reinterpret_cast<Address>(prev_limit) &&
573 reinterpret_cast<Address>(prev_limit) <=
574 reinterpret_cast<Address>(block_limit)) {
575 #ifdef ENABLE_HANDLE_ZAPPING 576 internal::HandleScope::ZapRange(prev_limit, block_limit);
582 #ifdef ENABLE_HANDLE_ZAPPING 583 internal::HandleScope::ZapRange(block_start, block_limit);
585 if (spare_ !=
nullptr) {
588 spare_ = block_start;
590 DCHECK((blocks_.empty() && prev_limit ==
nullptr) ||
591 (!blocks_.empty() && prev_limit !=
nullptr));
596 void InvokeAccessorGetterCallback(
599 v8::AccessorNameGetterCallback getter);
602 v8::FunctionCallback callback);
606 static v8::Testing::StressType stress_type() {
return stress_type_; }
607 static void set_stress_type(v8::Testing::StressType stress_type) {
608 stress_type_ = stress_type;
612 static v8::Testing::StressType stress_type_;