File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1072,6 +1072,24 @@ class ScriptOrigin {
10721072 Handle<Value> source_map_url_;
10731073};
10741074
1075+ class V8_EXPORT SealHandleScope {
1076+ public:
1077+ SealHandleScope(Isolate* isolate);
1078+ ~SealHandleScope();
1079+
1080+ private:
1081+ // Make it hard to create heap-allocated or illegal handle scopes by
1082+ // disallowing certain operations.
1083+ SealHandleScope(const SealHandleScope&);
1084+ void operator=(const SealHandleScope&);
1085+ void* operator new(size_t size);
1086+ void operator delete(void*, size_t);
1087+
1088+ internal::Isolate* isolate_;
1089+ int prev_level_;
1090+ internal::Object** prev_limit_;
1091+ };
1092+
10751093
10761094/**
10771095 * A compiled JavaScript script, not yet tied to a Context.
Original file line number Diff line number Diff line change @@ -682,6 +682,27 @@ i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
682682}
683683
684684
685+ SealHandleScope::SealHandleScope (Isolate* isolate) {
686+ i::Isolate* internal_isolate = reinterpret_cast <i::Isolate*>(isolate);
687+
688+ isolate_ = internal_isolate;
689+ i::HandleScopeData* current = internal_isolate->handle_scope_data ();
690+ prev_limit_ = current->limit ;
691+ current->limit = current->next ;
692+ prev_level_ = current->level ;
693+ current->level = 0 ;
694+ }
695+
696+
697+ SealHandleScope::~SealHandleScope () {
698+ i::HandleScopeData* current = isolate_->handle_scope_data ();
699+ DCHECK_EQ (0 , current->level );
700+ current->level = prev_level_;
701+ DCHECK_EQ (current->next , current->limit );
702+ current->limit = prev_limit_;
703+ }
704+
705+
685706void Context::Enter () {
686707 i::Handle<i::Context> env = Utils::OpenHandle (this );
687708 i::Isolate* isolate = env->GetIsolate ();
Original file line number Diff line number Diff line change @@ -661,17 +661,14 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
661661 while (!blocks_.is_empty ()) {
662662 internal::Object** block_start = blocks_.last ();
663663 internal::Object** block_limit = block_start + kHandleBlockSize ;
664- # ifdef DEBUG
664+
665665 // SealHandleScope may make the prev_limit to point inside the block.
666666 if (block_start <= prev_limit && prev_limit <= block_limit) {
667667#ifdef ENABLE_HANDLE_ZAPPING
668668 internal::HandleScope::ZapRange (prev_limit, block_limit);
669669#endif
670670 break ;
671671 }
672- #else
673- if (prev_limit == block_limit) break ;
674- #endif
675672
676673 blocks_.RemoveLast ();
677674#ifdef ENABLE_HANDLE_ZAPPING
Original file line number Diff line number Diff line change 4040 # they don't fail then test.py has failed.
4141 'test-serialize/TestThatAlwaysFails': [FAIL],
4242 'test-serialize/DependentTestThatAlwaysFails': [FAIL],
43+ 'test-api/SealHandleScope': [FAIL],
4344
4445 # This test always fails. It tests that LiveEdit causes abort when turned off.
4546 'test-debug/LiveEditDisabled': [FAIL],
Original file line number Diff line number Diff line change @@ -18829,6 +18829,38 @@ void CallCompletedCallbackException() {
1882918829}
1883018830
1883118831
18832+ TEST(SealHandleScope) {
18833+ v8::Isolate* isolate = CcTest::isolate();
18834+ v8::HandleScope handle_scope(isolate);
18835+ LocalContext env;
18836+
18837+ v8::SealHandleScope seal(isolate);
18838+
18839+ // Should fail
18840+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
18841+
18842+ USE(obj);
18843+ }
18844+
18845+
18846+ TEST(SealHandleScopeNested) {
18847+ v8::Isolate* isolate = CcTest::isolate();
18848+ v8::HandleScope handle_scope(isolate);
18849+ LocalContext env;
18850+
18851+ v8::SealHandleScope seal(isolate);
18852+
18853+ {
18854+ v8::HandleScope handle_scope(isolate);
18855+
18856+ // Should work
18857+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
18858+
18859+ USE(obj);
18860+ }
18861+ }
18862+
18863+
1883218864TEST(CallCompletedCallbackOneException) {
1883318865 LocalContext env;
1883418866 v8::HandleScope scope(env->GetIsolate());
You can’t perform that action at this time.
0 commit comments