Commit 46c8e21 1 parent a8bb5c7 commit 46c8e21 Copy full SHA for 46c8e21
File tree 5 files changed +76
-4
lines changed
5 files changed +76
-4
lines changed Original file line number Diff line number Diff line change @@ -944,6 +944,27 @@ class ScriptOrigin {
944
944
};
945
945
946
946
947
+ class V8_EXPORT SealHandleScope {
948
+ public:
949
+ SealHandleScope (Isolate* isolate);
950
+ ~SealHandleScope ();
951
+
952
+ private:
953
+ // Make it hard to create heap-allocated or illegal handle scopes by
954
+ // disallowing certain operations.
955
+ SealHandleScope (const SealHandleScope&);
956
+ void operator =(const SealHandleScope&);
957
+ void * operator new (size_t size);
958
+ void operator delete (void *, size_t );
959
+
960
+ internal::Isolate* isolate_;
961
+ int prev_level_;
962
+ internal::Object** prev_limit_;
963
+ };
964
+
965
+
966
+
967
+
947
968
/* *
948
969
* A compiled JavaScript script, not yet tied to a Context.
949
970
*/
Original file line number Diff line number Diff line change @@ -637,6 +637,27 @@ i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
637
637
}
638
638
639
639
640
+ SealHandleScope::SealHandleScope (Isolate* isolate) {
641
+ i::Isolate* internal_isolate = reinterpret_cast <i::Isolate*>(isolate);
642
+
643
+ isolate_ = internal_isolate;
644
+ i::HandleScopeData* current = internal_isolate->handle_scope_data ();
645
+ prev_limit_ = current->limit ;
646
+ current->limit = current->next ;
647
+ prev_level_ = current->level ;
648
+ current->level = 0 ;
649
+ }
650
+
651
+
652
+ SealHandleScope::~SealHandleScope () {
653
+ i::HandleScopeData* current = isolate_->handle_scope_data ();
654
+ DCHECK_EQ (0 , current->level );
655
+ current->level = prev_level_;
656
+ DCHECK_EQ (current->next , current->limit );
657
+ current->limit = prev_limit_;
658
+ }
659
+
660
+
640
661
void Context::Enter () {
641
662
i::Handle <i::Context> env = Utils::OpenHandle (this );
642
663
i::Isolate* isolate = env->GetIsolate ();
Original file line number Diff line number Diff line change @@ -642,17 +642,14 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
642
642
while (!blocks_.is_empty ()) {
643
643
internal::Object** block_start = blocks_.last ();
644
644
internal::Object** block_limit = block_start + kHandleBlockSize ;
645
- # ifdef DEBUG
645
+
646
646
// SealHandleScope may make the prev_limit to point inside the block.
647
647
if (block_start <= prev_limit && prev_limit <= block_limit) {
648
648
#ifdef ENABLE_HANDLE_ZAPPING
649
649
internal::HandleScope::ZapRange (prev_limit, block_limit);
650
650
#endif
651
651
break ;
652
652
}
653
- #else
654
- if (prev_limit == block_limit) break ;
655
- #endif
656
653
657
654
blocks_.RemoveLast ();
658
655
#ifdef ENABLE_HANDLE_ZAPPING
Original file line number Diff line number Diff line change 43
43
# they don't fail then test.py has failed.
44
44
'test-serialize/TestThatAlwaysFails': [FAIL],
45
45
'test-serialize/DependentTestThatAlwaysFails': [FAIL],
46
+ 'test-api/SealHandleScope': [FAIL],
46
47
47
48
# This test always fails. It tests that LiveEdit causes abort when turned off.
48
49
'test-debug/LiveEditDisabled': [FAIL],
Original file line number Diff line number Diff line change @@ -20625,6 +20625,38 @@ void CallCompletedCallbackException() {
20625
20625
}
20626
20626
20627
20627
20628
+ TEST(SealHandleScope) {
20629
+ v8::Isolate* isolate = CcTest::isolate();
20630
+ v8::HandleScope handle_scope(isolate);
20631
+ LocalContext env;
20632
+
20633
+ v8::SealHandleScope seal(isolate);
20634
+
20635
+ // Should fail
20636
+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
20637
+
20638
+ USE(obj);
20639
+ }
20640
+
20641
+
20642
+ TEST(SealHandleScopeNested) {
20643
+ v8::Isolate* isolate = CcTest::isolate();
20644
+ v8::HandleScope handle_scope(isolate);
20645
+ LocalContext env;
20646
+
20647
+ v8::SealHandleScope seal(isolate);
20648
+
20649
+ {
20650
+ v8::HandleScope handle_scope(isolate);
20651
+
20652
+ // Should work
20653
+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
20654
+
20655
+ USE(obj);
20656
+ }
20657
+ }
20658
+
20659
+
20628
20660
TEST(CallCompletedCallbackOneException) {
20629
20661
LocalContext env;
20630
20662
v8::HandleScope scope(env->GetIsolate());
You can’t perform that action at this time.
0 commit comments