File tree 5 files changed +73
-4
lines changed
5 files changed +73
-4
lines changed Original file line number Diff line number Diff line change @@ -1006,6 +1006,24 @@ class ScriptOrigin {
1006
1006
Handle <Integer> script_id_;
1007
1007
};
1008
1008
1009
+ class V8_EXPORT SealHandleScope {
1010
+ public:
1011
+ SealHandleScope (Isolate* isolate);
1012
+ ~SealHandleScope ();
1013
+
1014
+ private:
1015
+ // Make it hard to create heap-allocated or illegal handle scopes by
1016
+ // disallowing certain operations.
1017
+ SealHandleScope (const SealHandleScope&);
1018
+ void operator =(const SealHandleScope&);
1019
+ void * operator new (size_t size);
1020
+ void operator delete (void *, size_t );
1021
+
1022
+ internal::Isolate* isolate_;
1023
+ int prev_level_;
1024
+ internal::Object** prev_limit_;
1025
+ };
1026
+
1009
1027
1010
1028
/* *
1011
1029
* A compiled JavaScript script, not yet tied to a Context.
Original file line number Diff line number Diff line change @@ -515,6 +515,27 @@ i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
515
515
}
516
516
517
517
518
+ SealHandleScope::SealHandleScope (Isolate* isolate) {
519
+ i::Isolate* internal_isolate = reinterpret_cast <i::Isolate*>(isolate);
520
+
521
+ isolate_ = internal_isolate;
522
+ i::HandleScopeData* current = internal_isolate->handle_scope_data ();
523
+ prev_limit_ = current->limit ;
524
+ current->limit = current->next ;
525
+ prev_level_ = current->level ;
526
+ current->level = 0 ;
527
+ }
528
+
529
+
530
+ SealHandleScope::~SealHandleScope () {
531
+ i::HandleScopeData* current = isolate_->handle_scope_data ();
532
+ DCHECK_EQ (0 , current->level );
533
+ current->level = prev_level_;
534
+ DCHECK_EQ (current->next , current->limit );
535
+ current->limit = prev_limit_;
536
+ }
537
+
538
+
518
539
void Context::Enter () {
519
540
i::Handle <i::Context> env = Utils::OpenHandle (this );
520
541
i::Isolate* isolate = env->GetIsolate ();
Original file line number Diff line number Diff line change @@ -650,17 +650,14 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) {
650
650
while (!blocks_.is_empty ()) {
651
651
internal::Object** block_start = blocks_.last ();
652
652
internal::Object** block_limit = block_start + kHandleBlockSize ;
653
- # ifdef DEBUG
653
+
654
654
// SealHandleScope may make the prev_limit to point inside the block.
655
655
if (block_start <= prev_limit && prev_limit <= block_limit) {
656
656
#ifdef ENABLE_HANDLE_ZAPPING
657
657
internal::HandleScope::ZapRange (prev_limit, block_limit);
658
658
#endif
659
659
break ;
660
660
}
661
- #else
662
- if (prev_limit == block_limit) break ;
663
- #endif
664
661
665
662
blocks_.RemoveLast ();
666
663
#ifdef ENABLE_HANDLE_ZAPPING
Original file line number Diff line number Diff line change 40
40
# they don't fail then test.py has failed.
41
41
'test-serialize/TestThatAlwaysFails': [FAIL],
42
42
'test-serialize/DependentTestThatAlwaysFails': [FAIL],
43
+ 'test-api/SealHandleScope': [FAIL],
43
44
44
45
# This test always fails. It tests that LiveEdit causes abort when turned off.
45
46
'test-debug/LiveEditDisabled': [FAIL],
Original file line number Diff line number Diff line change @@ -21895,6 +21895,38 @@ void CallCompletedCallbackException() {
21895
21895
}
21896
21896
21897
21897
21898
+ TEST(SealHandleScope) {
21899
+ v8::Isolate* isolate = CcTest::isolate();
21900
+ v8::HandleScope handle_scope(isolate);
21901
+ LocalContext env;
21902
+
21903
+ v8::SealHandleScope seal(isolate);
21904
+
21905
+ // Should fail
21906
+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
21907
+
21908
+ USE(obj);
21909
+ }
21910
+
21911
+
21912
+ TEST(SealHandleScopeNested) {
21913
+ v8::Isolate* isolate = CcTest::isolate();
21914
+ v8::HandleScope handle_scope(isolate);
21915
+ LocalContext env;
21916
+
21917
+ v8::SealHandleScope seal(isolate);
21918
+
21919
+ {
21920
+ v8::HandleScope handle_scope(isolate);
21921
+
21922
+ // Should work
21923
+ v8::Local<v8::Object> obj = v8::Object::New(isolate);
21924
+
21925
+ USE(obj);
21926
+ }
21927
+ }
21928
+
21929
+
21898
21930
TEST(CallCompletedCallbackOneException) {
21899
21931
LocalContext env;
21900
21932
v8::HandleScope scope(env->GetIsolate());
You can’t perform that action at this time.
0 commit comments