forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-evaluate.cc
More file actions
1364 lines (1311 loc) Β· 53.8 KB
/
debug-evaluate.cc
File metadata and controls
1364 lines (1311 loc) Β· 53.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/debug/debug-evaluate.h"
#include "src/builtins/accessors.h"
#include "src/codegen/assembler-inl.h"
#include "src/codegen/compiler.h"
#include "src/codegen/reloc-info.h"
#include "src/codegen/script-details.h"
#include "src/common/globals.h"
#include "src/debug/debug-frames.h"
#include "src/debug/debug-scopes.h"
#include "src/debug/debug.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/interpreter/bytecode-array-iterator.h"
#include "src/interpreter/bytecodes.h"
#include "src/objects/code-inl.h"
#include "src/objects/contexts.h"
#include "src/objects/string-set-inl.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/debug/debug-wasm-objects.h"
#endif // V8_ENABLE_WEBASSEMBLY
namespace v8 {
namespace internal {
namespace {
static MaybeDirectHandle<SharedFunctionInfo> GetFunctionInfo(
Isolate* isolate, Handle<String> source, REPLMode repl_mode) {
ScriptDetails script_details(isolate->factory()->empty_string(),
ScriptOriginOptions(true, true));
script_details.repl_mode = repl_mode;
ScriptCompiler::CompilationDetails compilation_details;
return Compiler::GetSharedFunctionInfoForScript(
isolate, source, script_details, ScriptCompiler::kNoCompileOptions,
ScriptCompiler::kNoCacheNoReason, NOT_NATIVES_CODE, &compilation_details);
}
} // namespace
MaybeDirectHandle<Object> DebugEvaluate::Global(Isolate* isolate,
Handle<String> source,
debug::EvaluateGlobalMode mode,
REPLMode repl_mode) {
DirectHandle<SharedFunctionInfo> shared_info;
if (!GetFunctionInfo(isolate, source, repl_mode).ToHandle(&shared_info)) {
return MaybeDirectHandle<Object>();
}
DirectHandle<NativeContext> context = isolate->native_context();
DirectHandle<JSFunction> function =
Factory::JSFunctionBuilder{isolate, shared_info, context}.Build();
DisableBreak disable_break_scope(
isolate->debug(),
mode == debug::EvaluateGlobalMode::kDisableBreaks ||
mode ==
debug::EvaluateGlobalMode::kDisableBreaksAndThrowOnSideEffect);
if (mode == debug::EvaluateGlobalMode::kDisableBreaksAndThrowOnSideEffect) {
isolate->debug()->StartSideEffectCheckMode();
}
// TODO(cbruni, 1244145): Use host-defined options from script context.
DirectHandle<FixedArray> host_defined_options(
Cast<Script>(function->shared()->script())->host_defined_options(),
isolate);
MaybeDirectHandle<Object> result = Execution::CallScript(
isolate, function,
DirectHandle<JSObject>(context->global_proxy(), isolate),
host_defined_options);
if (mode == debug::EvaluateGlobalMode::kDisableBreaksAndThrowOnSideEffect) {
isolate->debug()->StopSideEffectCheckMode();
}
return result;
}
MaybeDirectHandle<Object> DebugEvaluate::Local(Isolate* isolate,
StackFrameId frame_id,
int inlined_jsframe_index,
DirectHandle<String> source,
bool throw_on_side_effect) {
// Handle the processing of break.
DisableBreak disable_break_scope(isolate->debug());
// Get the frame where the debugging is performed.
DebuggableStackFrameIterator it(isolate, frame_id);
#if V8_ENABLE_WEBASSEMBLY
if (it.is_wasm()) {
#if V8_ENABLE_DRUMBRAKE
// TODO(paolosev@microsoft.com) - Not supported by Wasm interpreter.
if (it.is_wasm_interpreter_entry()) return {};
#endif // V8_ENABLE_DRUMBRAKE
WasmFrame* frame = WasmFrame::cast(it.frame());
DirectHandle<SharedFunctionInfo> outer_info(
isolate->native_context()->empty_function()->shared(), isolate);
DirectHandle<JSObject> context_extension = GetWasmDebugProxy(frame);
DirectHandle<ScopeInfo> scope_info =
ScopeInfo::CreateForWithScope(isolate, Handle<ScopeInfo>::null());
DirectHandle<Context> context = isolate->factory()->NewWithContext(
isolate->native_context(), scope_info, context_extension);
return Evaluate(isolate, outer_info, context, context_extension, source,
throw_on_side_effect);
}
#endif // V8_ENABLE_WEBASSEMBLY
CHECK(it.is_javascript());
JavaScriptFrame* frame = it.javascript_frame();
// This is not a lot different than DebugEvaluate::Global, except that
// variables accessible by the function we are evaluating from are
// materialized and included on top of the native context. Changes to
// the materialized object are written back afterwards.
// Note that the native context is taken from the original context chain,
// which may not be the current native context of the isolate.
ContextBuilder context_builder(isolate, frame, inlined_jsframe_index);
if (isolate->has_exception()) return {};
DirectHandle<Context> context = context_builder.evaluation_context();
DirectHandle<JSObject> receiver(context->global_proxy(), isolate);
MaybeDirectHandle<Object> maybe_result =
Evaluate(isolate, context_builder.outer_info(), context, receiver, source,
throw_on_side_effect);
if (!maybe_result.is_null()) context_builder.UpdateValues();
return maybe_result;
}
MaybeDirectHandle<Object> DebugEvaluate::WithTopmostArguments(
Isolate* isolate, DirectHandle<String> source) {
// Handle the processing of break.
DisableBreak disable_break_scope(isolate->debug());
Factory* factory = isolate->factory();
JavaScriptStackFrameIterator it(isolate);
// Get context and receiver.
DirectHandle<Context> native_context(
Cast<Context>(it.frame()->context())->native_context(), isolate);
// Materialize arguments as property on an extension object.
DirectHandle<JSObject> materialized = factory->NewSlowJSObjectWithNullProto();
DirectHandle<String> arguments_str = factory->arguments_string();
JSObject::SetOwnPropertyIgnoreAttributes(
materialized, arguments_str,
Accessors::FunctionGetArguments(it.frame(), 0), NONE)
.Check();
// Materialize receiver.
DirectHandle<Object> this_value(it.frame()->receiver(), isolate);
DCHECK_EQ(it.frame()->IsConstructor(), IsTheHole(*this_value, isolate));
if (!IsTheHole(*this_value, isolate)) {
DirectHandle<String> this_str = factory->this_string();
JSObject::SetOwnPropertyIgnoreAttributes(materialized, this_str, this_value,
NONE)
.Check();
}
// Use extension object in a debug-evaluate scope.
DirectHandle<ScopeInfo> scope_info =
ScopeInfo::CreateForWithScope(isolate, Handle<ScopeInfo>::null());
scope_info->SetIsDebugEvaluateScope();
DirectHandle<Context> evaluation_context = factory->NewDebugEvaluateContext(
native_context, scope_info, materialized, DirectHandle<Context>());
DirectHandle<SharedFunctionInfo> outer_info(
native_context->empty_function()->shared(), isolate);
DirectHandle<JSObject> receiver(native_context->global_proxy(), isolate);
const bool throw_on_side_effect = false;
MaybeDirectHandle<Object> maybe_result =
Evaluate(isolate, outer_info, evaluation_context, receiver, source,
throw_on_side_effect);
return maybe_result;
}
// Compile and evaluate source for the given context.
MaybeDirectHandle<Object> DebugEvaluate::Evaluate(
Isolate* isolate, DirectHandle<SharedFunctionInfo> outer_info,
DirectHandle<Context> context, DirectHandle<Object> receiver,
DirectHandle<String> source, bool throw_on_side_effect) {
DirectHandle<JSFunction> eval_fun;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, eval_fun,
Compiler::GetFunctionFromEval(isolate, source, outer_info, context,
LanguageMode::kSloppy, NO_PARSE_RESTRICTION,
kNoSourcePosition, kNoSourcePosition,
ParsingWhileDebugging::kYes));
Handle<Object> result;
bool success = false;
if (throw_on_side_effect) isolate->debug()->StartSideEffectCheckMode();
success = Execution::Call(isolate, eval_fun, receiver, {}).ToHandle(&result);
if (throw_on_side_effect) isolate->debug()->StopSideEffectCheckMode();
if (!success) DCHECK(isolate->has_exception());
return success ? result : MaybeHandle<Object>();
}
DirectHandle<SharedFunctionInfo> DebugEvaluate::ContextBuilder::outer_info()
const {
return direct_handle(frame_inspector_.GetFunction()->shared(), isolate_);
}
DebugEvaluate::ContextBuilder::ContextBuilder(Isolate* isolate,
JavaScriptFrame* frame,
int inlined_jsframe_index)
: isolate_(isolate),
frame_inspector_(frame, inlined_jsframe_index, isolate),
scope_iterator_(isolate, &frame_inspector_,
ScopeIterator::ReparseStrategy::kScriptIfNeeded) {
Handle<Context> outer_context(frame_inspector_.GetFunction()->context(),
isolate);
evaluation_context_ = outer_context;
Factory* factory = isolate->factory();
if (scope_iterator_.Done()) return;
// To evaluate as if we were running eval at the point of the debug break,
// we reconstruct the context chain as follows:
// - To make stack-allocated variables visible, we materialize them and
// use a debug-evaluate context to wrap both the materialized object and
// the original context.
// - Each scope from the break position up to the function scope is wrapped
// in a debug-evaluate context.
// - Between the function scope and the native context, we only resolve
// variable names that are guaranteed to not be shadowed by stack-allocated
// variables. ScopeInfos between the function scope and the native
// context have a blocklist attached to implement that.
// - The various block lists are calculated by the ScopeIterator during
// iteration.
// Context::Lookup has special handling for debug-evaluate contexts:
// - Look up in the materialized stack variables.
// - Look up in the original context.
// - Once we have seen a debug-evaluate context we start to take the
// block lists into account before moving up the context chain.
for (; scope_iterator_.InInnerScope(); scope_iterator_.Next()) {
ScopeIterator::ScopeType scope_type = scope_iterator_.Type();
if (scope_type == ScopeIterator::ScopeTypeScript) break;
ContextChainElement context_chain_element;
if (scope_type == ScopeIterator::ScopeTypeLocal ||
scope_iterator_.DeclaresLocals(ScopeIterator::Mode::STACK)) {
context_chain_element.materialized_object =
scope_iterator_.ScopeObject(ScopeIterator::Mode::STACK);
}
if (scope_iterator_.HasContext()) {
context_chain_element.wrapped_context = scope_iterator_.CurrentContext();
}
context_chain_.push_back(context_chain_element);
}
DirectHandle<ScopeInfo> scope_info =
IsNativeContext(*evaluation_context_)
? DirectHandle<ScopeInfo>::null()
: direct_handle(evaluation_context_->scope_info(), isolate);
for (auto rit = context_chain_.rbegin(); rit != context_chain_.rend();
rit++) {
ContextChainElement element = *rit;
scope_info = ScopeInfo::CreateForWithScope(isolate, scope_info);
scope_info->SetIsDebugEvaluateScope();
// In the case where the "paused function scope" is the script scope
// itself, we don't need (and don't have) a blocklist.
const bool paused_scope_is_script_scope =
scope_iterator_.Done() || scope_iterator_.InInnerScope();
if (rit == context_chain_.rbegin() && !paused_scope_is_script_scope) {
// The DebugEvaluateContext we create for the closure scope is the only
// DebugEvaluateContext with a block list. This means we'll retrieve
// the existing block list from the paused function scope
// and also associate the temporary scope_info we create here with that
// blocklist.
DirectHandle<ScopeInfo> function_scope_info(
frame_inspector_.GetFunction()->shared()->scope_info(), isolate_);
DirectHandle<Object> block_list(
isolate_->LocalsBlockListCacheGet(function_scope_info), isolate_);
CHECK(IsStringSet(*block_list));
isolate_->LocalsBlockListCacheSet(scope_info, Handle<ScopeInfo>::null(),
Cast<StringSet>(block_list));
}
evaluation_context_ = factory->NewDebugEvaluateContext(
evaluation_context_, scope_info, element.materialized_object,
element.wrapped_context);
}
}
void DebugEvaluate::ContextBuilder::UpdateValues() {
scope_iterator_.Restart();
for (ContextChainElement& element : context_chain_) {
if (!element.materialized_object.is_null()) {
DirectHandle<FixedArray> keys =
KeyAccumulator::GetKeys(isolate_, element.materialized_object,
KeyCollectionMode::kOwnOnly,
ENUMERABLE_STRINGS)
.ToHandleChecked();
for (int i = 0; i < keys->length(); i++) {
DCHECK(IsString(keys->get(i)));
Handle<String> key(Cast<String>(keys->get(i)), isolate_);
DirectHandle<Object> value = JSReceiver::GetDataProperty(
isolate_, element.materialized_object, key);
scope_iterator_.SetVariableValue(key, value);
}
}
scope_iterator_.Next();
}
}
// static
bool DebugEvaluate::IsSideEffectFreeIntrinsic(Runtime::FunctionId id) {
// Use macro to include only the non-inlined version of an intrinsic.
#define INTRINSIC_ALLOWLIST(V) \
/* Conversions */ \
V(NumberToStringSlow) \
V(ToBigInt) \
V(ToLength) \
V(ToNumber) \
V(ToObject) \
V(ToString) \
/* Type checks */ \
V(IsArray) \
V(IsJSProxy) \
V(IsJSReceiver) \
V(IsSmi) \
/* Loads */ \
V(LoadLookupSlotForCall) \
V(GetPrivateMember) \
V(GetProperty) \
/* Arrays */ \
V(ArraySpeciesConstructor) \
V(HasFastPackedElements) \
V(NewArray) \
V(NormalizeElements) \
V(TypedArrayGetBuffer) \
/* Errors */ \
V(NewTypeError) \
V(ReThrow) \
V(ThrowCalledNonCallable) \
V(ThrowInvalidStringLength) \
V(ThrowIteratorError) \
V(ThrowIteratorResultNotAnObject) \
V(ThrowPatternAssignmentNonCoercible) \
V(ThrowReferenceError) \
V(ThrowSymbolIteratorInvalid) \
/* Strings */ \
V(StringReplaceOneCharWithString) \
V(StringSubstring) \
V(StringToNumber) \
/* BigInts */ \
V(BigIntEqualToBigInt) \
V(BigIntToNumber) \
/* Literals */ \
V(CreateArrayLiteral) \
V(CreateObjectLiteral) \
V(CreateRegExpLiteral) \
V(DefineClass) \
/* Called from builtins */ \
V(AllocateInYoungGeneration) \
V(AllocateInOldGeneration) \
V(ArrayIncludes_Slow) \
V(ArrayIndexOf) \
V(ArrayIsArray) \
V(GetFunctionName) \
V(GlobalPrint) \
V(HasProperty) \
V(ObjectCreate) \
V(ObjectEntries) \
V(ObjectEntriesSkipFastPath) \
V(ObjectHasOwnProperty) \
V(ObjectKeys) \
V(ObjectValues) \
V(ObjectValuesSkipFastPath) \
V(ObjectGetOwnPropertyNames) \
V(ObjectGetOwnPropertyNamesTryFast) \
V(ObjectIsExtensible) \
V(RegExpInitializeAndCompile) \
V(StackGuard) \
V(HandleNoHeapWritesInterrupts) \
V(StringAdd) \
V(StringCharCodeAt) \
V(StringEqual) \
V(StringParseFloat) \
V(StringParseInt) \
V(SymbolDescriptiveString) \
V(ThrowRangeError) \
V(ThrowTypeError) \
V(ToName) \
V(TransitionElementsKind) \
/* Misc. */ \
V(Call) \
V(CompleteInobjectSlackTrackingForMap) \
V(HasInPrototypeChain) \
V(IncrementUseCounter) \
V(MaxSmi) \
V(NewObject) \
V(StringMaxLength) \
V(StringToArray) \
V(AsyncFunctionEnter) \
V(AsyncFunctionResolve) \
/* Test */ \
V(GetOptimizationStatus) \
V(OptimizeFunctionOnNextCall) \
V(OptimizeOsr)
// Intrinsics with inline versions have to be allowlisted here a second time.
#define INLINE_INTRINSIC_ALLOWLIST(V) \
V(AsyncFunctionEnter) \
V(AsyncFunctionResolve)
#define CASE(Name) case Runtime::k##Name:
#define INLINE_CASE(Name) case Runtime::kInline##Name:
switch (id) {
INTRINSIC_ALLOWLIST(CASE)
INLINE_INTRINSIC_ALLOWLIST(INLINE_CASE)
return true;
default:
if (v8_flags.trace_side_effect_free_debug_evaluate) {
PrintF("[debug-evaluate] intrinsic %s may cause side effect.\n",
Runtime::FunctionForId(id)->name);
}
return false;
}
#undef CASE
#undef INLINE_CASE
#undef INTRINSIC_ALLOWLIST
#undef INLINE_INTRINSIC_ALLOWLIST
}
namespace {
bool BytecodeHasNoSideEffect(interpreter::Bytecode bytecode) {
using interpreter::Bytecode;
using interpreter::Bytecodes;
if (Bytecodes::IsWithoutExternalSideEffects(bytecode)) return true;
if (Bytecodes::IsCallOrConstruct(bytecode)) return true;
if (Bytecodes::IsJumpIfToBoolean(bytecode)) return true;
if (Bytecodes::IsPrefixScalingBytecode(bytecode)) return true;
switch (bytecode) {
// Allowlist for bytecodes.
// Loads.
case Bytecode::kLdaLookupSlot:
case Bytecode::kLdaGlobal:
case Bytecode::kGetNamedProperty:
case Bytecode::kGetKeyedProperty:
case Bytecode::kLdaGlobalInsideTypeof:
case Bytecode::kLdaLookupSlotInsideTypeof:
case Bytecode::kGetIterator:
// Arithmetics.
case Bytecode::kAdd:
case Bytecode::kAddSmi:
case Bytecode::kSub:
case Bytecode::kSubSmi:
case Bytecode::kMul:
case Bytecode::kMulSmi:
case Bytecode::kDiv:
case Bytecode::kDivSmi:
case Bytecode::kMod:
case Bytecode::kModSmi:
case Bytecode::kExp:
case Bytecode::kExpSmi:
case Bytecode::kNegate:
case Bytecode::kBitwiseAnd:
case Bytecode::kBitwiseAndSmi:
case Bytecode::kBitwiseNot:
case Bytecode::kBitwiseOr:
case Bytecode::kBitwiseOrSmi:
case Bytecode::kBitwiseXor:
case Bytecode::kBitwiseXorSmi:
case Bytecode::kShiftLeft:
case Bytecode::kShiftLeftSmi:
case Bytecode::kShiftRight:
case Bytecode::kShiftRightSmi:
case Bytecode::kShiftRightLogical:
case Bytecode::kShiftRightLogicalSmi:
case Bytecode::kInc:
case Bytecode::kDec:
case Bytecode::kLogicalNot:
case Bytecode::kToBooleanLogicalNot:
case Bytecode::kTypeOf:
// Contexts.
case Bytecode::kCreateBlockContext:
case Bytecode::kCreateCatchContext:
case Bytecode::kCreateFunctionContext:
case Bytecode::kCreateEvalContext:
case Bytecode::kCreateWithContext:
// Literals.
case Bytecode::kCreateArrayLiteral:
case Bytecode::kCreateEmptyArrayLiteral:
case Bytecode::kCreateArrayFromIterable:
case Bytecode::kCreateObjectLiteral:
case Bytecode::kCreateEmptyObjectLiteral:
case Bytecode::kCreateRegExpLiteral:
// Allocations.
case Bytecode::kCreateClosure:
case Bytecode::kCreateUnmappedArguments:
case Bytecode::kCreateRestParameter:
// Comparisons.
case Bytecode::kTestEqual:
case Bytecode::kTestEqualStrict:
case Bytecode::kTestLessThan:
case Bytecode::kTestLessThanOrEqual:
case Bytecode::kTestGreaterThan:
case Bytecode::kTestGreaterThanOrEqual:
case Bytecode::kTestInstanceOf:
case Bytecode::kTestIn:
case Bytecode::kTestReferenceEqual:
case Bytecode::kTestUndetectable:
case Bytecode::kTestTypeOf:
case Bytecode::kTestUndefined:
case Bytecode::kTestNull:
// Conversions.
case Bytecode::kToObject:
case Bytecode::kToName:
case Bytecode::kToNumber:
case Bytecode::kToNumeric:
case Bytecode::kToString:
case Bytecode::kToBoolean:
// Misc.
case Bytecode::kIncBlockCounter: // Coverage counters.
case Bytecode::kForInEnumerate:
case Bytecode::kForInPrepare:
case Bytecode::kForInNext:
case Bytecode::kForInStep:
case Bytecode::kJumpLoop:
case Bytecode::kThrow:
case Bytecode::kReThrow:
case Bytecode::kThrowReferenceErrorIfHole:
case Bytecode::kThrowSuperNotCalledIfHole:
case Bytecode::kThrowSuperAlreadyCalledIfNotHole:
case Bytecode::kIllegal:
case Bytecode::kCallJSRuntime:
case Bytecode::kReturn:
case Bytecode::kSetPendingMessage:
return true;
default:
return false;
}
}
DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
switch (id) {
// Allowlist for builtins.
// Object builtins.
case Builtin::kObjectConstructor:
case Builtin::kObjectCreate:
case Builtin::kObjectEntries:
case Builtin::kObjectGetOwnPropertyDescriptor:
case Builtin::kObjectGetOwnPropertyDescriptors:
case Builtin::kObjectGetOwnPropertyNames:
case Builtin::kObjectGetOwnPropertySymbols:
case Builtin::kObjectGetPrototypeOf:
case Builtin::kObjectGroupBy:
case Builtin::kObjectHasOwn:
case Builtin::kObjectIs:
case Builtin::kObjectIsExtensible:
case Builtin::kObjectIsFrozen:
case Builtin::kObjectIsSealed:
case Builtin::kObjectKeys:
case Builtin::kObjectPrototypeValueOf:
case Builtin::kObjectValues:
case Builtin::kObjectPrototypeHasOwnProperty:
case Builtin::kObjectPrototypeIsPrototypeOf:
case Builtin::kObjectPrototypePropertyIsEnumerable:
case Builtin::kObjectPrototypeToString:
case Builtin::kObjectPrototypeToLocaleString:
// Array builtins.
case Builtin::kArrayIsArray:
case Builtin::kArrayConstructor:
case Builtin::kArrayFrom:
case Builtin::kArrayIndexOf:
case Builtin::kArrayOf:
case Builtin::kArrayPrototypeValues:
case Builtin::kArrayIncludes:
case Builtin::kArrayPrototypeAt:
case Builtin::kArrayPrototypeConcat:
case Builtin::kArrayPrototypeEntries:
case Builtin::kArrayPrototypeFind:
case Builtin::kArrayPrototypeFindIndex:
case Builtin::kArrayPrototypeFindLast:
case Builtin::kArrayPrototypeFindLastIndex:
case Builtin::kArrayPrototypeFlat:
case Builtin::kArrayPrototypeFlatMap:
case Builtin::kArrayPrototypeJoin:
case Builtin::kArrayPrototypeKeys:
case Builtin::kArrayPrototypeLastIndexOf:
case Builtin::kArrayPrototypeSlice:
case Builtin::kArrayPrototypeToLocaleString:
case Builtin::kArrayPrototypeToReversed:
case Builtin::kArrayPrototypeToSorted:
case Builtin::kArrayPrototypeToSpliced:
case Builtin::kArrayPrototypeToString:
case Builtin::kArrayPrototypeWith:
case Builtin::kArrayForEach:
case Builtin::kArrayEvery:
case Builtin::kArraySome:
case Builtin::kArrayConcat:
case Builtin::kArrayFilter:
case Builtin::kArrayMap:
case Builtin::kArrayReduce:
case Builtin::kArrayReduceRight:
// Trace builtins.
case Builtin::kIsTraceCategoryEnabled:
case Builtin::kTrace:
// TypedArray builtins.
case Builtin::kTypedArrayConstructor:
case Builtin::kTypedArrayOf:
case Builtin::kTypedArrayPrototypeAt:
case Builtin::kTypedArrayPrototypeBuffer:
case Builtin::kTypedArrayPrototypeByteLength:
case Builtin::kTypedArrayPrototypeByteOffset:
case Builtin::kTypedArrayPrototypeLength:
case Builtin::kTypedArrayPrototypeEntries:
case Builtin::kTypedArrayPrototypeKeys:
case Builtin::kTypedArrayPrototypeValues:
case Builtin::kTypedArrayPrototypeFind:
case Builtin::kTypedArrayPrototypeFindIndex:
case Builtin::kTypedArrayPrototypeFindLast:
case Builtin::kTypedArrayPrototypeFindLastIndex:
case Builtin::kTypedArrayPrototypeIncludes:
case Builtin::kTypedArrayPrototypeJoin:
case Builtin::kTypedArrayPrototypeIndexOf:
case Builtin::kTypedArrayPrototypeLastIndexOf:
case Builtin::kTypedArrayPrototypeSlice:
case Builtin::kTypedArrayPrototypeSubArray:
case Builtin::kTypedArrayPrototypeEvery:
case Builtin::kTypedArrayPrototypeSome:
case Builtin::kTypedArrayPrototypeToLocaleString:
case Builtin::kTypedArrayPrototypeFilter:
case Builtin::kTypedArrayPrototypeMap:
case Builtin::kTypedArrayPrototypeReduce:
case Builtin::kTypedArrayPrototypeReduceRight:
case Builtin::kTypedArrayPrototypeForEach:
case Builtin::kTypedArrayPrototypeToReversed:
case Builtin::kTypedArrayPrototypeToSorted:
case Builtin::kTypedArrayPrototypeWith:
// ArrayBuffer builtins.
case Builtin::kArrayBufferConstructor:
case Builtin::kArrayBufferPrototypeGetByteLength:
case Builtin::kArrayBufferIsView:
case Builtin::kArrayBufferPrototypeSlice:
case Builtin::kReturnReceiver:
// DataView builtins.
case Builtin::kDataViewConstructor:
case Builtin::kDataViewPrototypeGetBuffer:
case Builtin::kDataViewPrototypeGetByteLength:
case Builtin::kDataViewPrototypeGetByteOffset:
case Builtin::kDataViewPrototypeGetInt8:
case Builtin::kDataViewPrototypeGetUint8:
case Builtin::kDataViewPrototypeGetInt16:
case Builtin::kDataViewPrototypeGetUint16:
case Builtin::kDataViewPrototypeGetInt32:
case Builtin::kDataViewPrototypeGetUint32:
case Builtin::kDataViewPrototypeGetFloat16:
case Builtin::kDataViewPrototypeGetFloat32:
case Builtin::kDataViewPrototypeGetFloat64:
case Builtin::kDataViewPrototypeGetBigInt64:
case Builtin::kDataViewPrototypeGetBigUint64:
// Boolean bulitins.
case Builtin::kBooleanConstructor:
case Builtin::kBooleanPrototypeToString:
case Builtin::kBooleanPrototypeValueOf:
// Date builtins.
case Builtin::kDateConstructor:
case Builtin::kDateNow:
case Builtin::kDateParse:
case Builtin::kDatePrototypeGetDate:
case Builtin::kDatePrototypeGetDay:
case Builtin::kDatePrototypeGetFullYear:
case Builtin::kDatePrototypeGetHours:
case Builtin::kDatePrototypeGetMilliseconds:
case Builtin::kDatePrototypeGetMinutes:
case Builtin::kDatePrototypeGetMonth:
case Builtin::kDatePrototypeGetSeconds:
case Builtin::kDatePrototypeGetTime:
case Builtin::kDatePrototypeGetTimezoneOffset:
case Builtin::kDatePrototypeGetUTCDate:
case Builtin::kDatePrototypeGetUTCDay:
case Builtin::kDatePrototypeGetUTCFullYear:
case Builtin::kDatePrototypeGetUTCHours:
case Builtin::kDatePrototypeGetUTCMilliseconds:
case Builtin::kDatePrototypeGetUTCMinutes:
case Builtin::kDatePrototypeGetUTCMonth:
case Builtin::kDatePrototypeGetUTCSeconds:
case Builtin::kDatePrototypeGetYear:
case Builtin::kDatePrototypeToDateString:
case Builtin::kDatePrototypeToISOString:
case Builtin::kDatePrototypeToUTCString:
case Builtin::kDatePrototypeToString:
#ifdef V8_INTL_SUPPORT
case Builtin::kDatePrototypeToLocaleString:
case Builtin::kDatePrototypeToLocaleDateString:
case Builtin::kDatePrototypeToLocaleTimeString:
#endif
case Builtin::kDatePrototypeToTimeString:
case Builtin::kDatePrototypeToJson:
case Builtin::kDatePrototypeToPrimitive:
case Builtin::kDatePrototypeValueOf:
// DisposableStack builtins.
case Builtin::kDisposableStackConstructor:
case Builtin::kDisposableStackPrototypeGetDisposed:
// AsyncDisposableStack builtins.
case Builtin::kAsyncDisposableStackConstructor:
case Builtin::kAsyncDisposableStackPrototypeGetDisposed:
// Map builtins.
case Builtin::kMapConstructor:
case Builtin::kMapGroupBy:
case Builtin::kMapPrototypeForEach:
case Builtin::kMapPrototypeGet:
case Builtin::kMapPrototypeHas:
case Builtin::kMapPrototypeEntries:
case Builtin::kMapPrototypeGetSize:
case Builtin::kMapPrototypeKeys:
case Builtin::kMapPrototypeValues:
// WeakMap builtins.
case Builtin::kWeakMapConstructor:
case Builtin::kWeakMapGet:
case Builtin::kWeakMapPrototypeHas:
// Math builtins.
case Builtin::kMathAbs:
case Builtin::kMathAcos:
case Builtin::kMathAcosh:
case Builtin::kMathAsin:
case Builtin::kMathAsinh:
case Builtin::kMathAtan:
case Builtin::kMathAtanh:
case Builtin::kMathAtan2:
case Builtin::kMathCeil:
case Builtin::kMathCbrt:
case Builtin::kMathExpm1:
case Builtin::kMathClz32:
case Builtin::kMathCos:
case Builtin::kMathCosh:
case Builtin::kMathExp:
case Builtin::kMathFloor:
case Builtin::kMathF16round:
case Builtin::kMathFround:
case Builtin::kMathHypot:
case Builtin::kMathImul:
case Builtin::kMathLog:
case Builtin::kMathLog1p:
case Builtin::kMathLog2:
case Builtin::kMathLog10:
case Builtin::kMathMax:
case Builtin::kMathMin:
case Builtin::kMathPow:
case Builtin::kMathRound:
case Builtin::kMathSign:
case Builtin::kMathSin:
case Builtin::kMathSinh:
case Builtin::kMathSqrt:
case Builtin::kMathTan:
case Builtin::kMathTanh:
case Builtin::kMathTrunc:
// Number builtins.
case Builtin::kNumberConstructor:
case Builtin::kNumberIsFinite:
case Builtin::kNumberIsInteger:
case Builtin::kNumberIsNaN:
case Builtin::kNumberIsSafeInteger:
case Builtin::kNumberParseFloat:
case Builtin::kNumberParseInt:
case Builtin::kNumberPrototypeToExponential:
case Builtin::kNumberPrototypeToFixed:
case Builtin::kNumberPrototypeToPrecision:
case Builtin::kNumberPrototypeToString:
case Builtin::kNumberPrototypeToLocaleString:
case Builtin::kNumberPrototypeValueOf:
// BigInt builtins.
case Builtin::kBigIntConstructor:
case Builtin::kBigIntAsIntN:
case Builtin::kBigIntAsUintN:
case Builtin::kBigIntPrototypeToString:
case Builtin::kBigIntPrototypeValueOf:
// Set builtins.
case Builtin::kSetConstructor:
case Builtin::kSetPrototypeEntries:
case Builtin::kSetPrototypeForEach:
case Builtin::kSetPrototypeGetSize:
case Builtin::kSetPrototypeHas:
case Builtin::kSetPrototypeValues:
// WeakSet builtins.
case Builtin::kWeakSetConstructor:
case Builtin::kWeakSetPrototypeHas:
// String builtins. Strings are immutable.
case Builtin::kStringFromCharCode:
case Builtin::kStringFromCodePoint:
case Builtin::kStringConstructor:
case Builtin::kStringListFromIterable:
case Builtin::kStringPrototypeAnchor:
case Builtin::kStringPrototypeAt:
case Builtin::kStringPrototypeBig:
case Builtin::kStringPrototypeBlink:
case Builtin::kStringPrototypeBold:
case Builtin::kStringPrototypeCharAt:
case Builtin::kStringPrototypeCharCodeAt:
case Builtin::kStringPrototypeCodePointAt:
case Builtin::kStringPrototypeConcat:
case Builtin::kStringPrototypeEndsWith:
case Builtin::kStringPrototypeFixed:
case Builtin::kStringPrototypeFontcolor:
case Builtin::kStringPrototypeFontsize:
case Builtin::kStringPrototypeIncludes:
case Builtin::kStringPrototypeIndexOf:
case Builtin::kStringPrototypeIsWellFormed:
case Builtin::kStringPrototypeItalics:
case Builtin::kStringPrototypeLastIndexOf:
case Builtin::kStringPrototypeLink:
case Builtin::kStringPrototypeMatch:
case Builtin::kStringPrototypeMatchAll:
case Builtin::kStringPrototypePadEnd:
case Builtin::kStringPrototypePadStart:
case Builtin::kStringPrototypeRepeat:
case Builtin::kStringPrototypeReplace:
case Builtin::kStringPrototypeReplaceAll:
case Builtin::kStringPrototypeSearch:
case Builtin::kStringPrototypeSlice:
case Builtin::kStringPrototypeSmall:
case Builtin::kStringPrototypeSplit:
case Builtin::kStringPrototypeStartsWith:
case Builtin::kStringSlowFlatten:
case Builtin::kStringPrototypeStrike:
case Builtin::kStringPrototypeSub:
case Builtin::kStringPrototypeSubstr:
case Builtin::kStringPrototypeSubstring:
case Builtin::kStringPrototypeSup:
case Builtin::kStringPrototypeToString:
case Builtin::kStringPrototypeToLocaleLowerCase:
case Builtin::kStringPrototypeToLocaleUpperCase:
#ifdef V8_INTL_SUPPORT
case Builtin::kStringToLowerCaseIntl:
case Builtin::kStringPrototypeLocaleCompareIntl:
case Builtin::kStringPrototypeToLowerCaseIntl:
case Builtin::kStringPrototypeToUpperCaseIntl:
case Builtin::kStringPrototypeNormalizeIntl:
#else
case Builtin::kStringPrototypeLocaleCompare:
case Builtin::kStringPrototypeToLowerCase:
case Builtin::kStringPrototypeToUpperCase:
case Builtin::kStringPrototypeNormalize:
#endif
case Builtin::kStringPrototypeToWellFormed:
case Builtin::kStringPrototypeTrim:
case Builtin::kStringPrototypeTrimEnd:
case Builtin::kStringPrototypeTrimStart:
case Builtin::kStringPrototypeValueOf:
case Builtin::kStringToNumber:
case Builtin::kStringSubstring:
// Symbol builtins.
case Builtin::kSymbolConstructor:
case Builtin::kSymbolKeyFor:
case Builtin::kSymbolPrototypeToString:
case Builtin::kSymbolPrototypeValueOf:
case Builtin::kSymbolPrototypeToPrimitive:
// JSON builtins.
case Builtin::kJsonParse:
case Builtin::kJsonStringify:
// Global function builtins.
case Builtin::kGlobalDecodeURI:
case Builtin::kGlobalDecodeURIComponent:
case Builtin::kGlobalEncodeURI:
case Builtin::kGlobalEncodeURIComponent:
case Builtin::kGlobalEscape:
case Builtin::kGlobalUnescape:
case Builtin::kGlobalIsFinite:
case Builtin::kGlobalIsNaN:
// Function builtins.
case Builtin::kFunctionPrototypeToString:
case Builtin::kFunctionPrototypeBind:
case Builtin::kFastFunctionPrototypeBind:
case Builtin::kFunctionPrototypeCall:
case Builtin::kFunctionPrototypeApply:
// Error builtins.
case Builtin::kErrorConstructor:
// RegExp builtins.
case Builtin::kRegExpConstructor:
// Reflect builtins.
case Builtin::kReflectApply:
case Builtin::kReflectConstruct:
case Builtin::kReflectGetOwnPropertyDescriptor:
case Builtin::kReflectGetPrototypeOf:
case Builtin::kReflectHas:
case Builtin::kReflectIsExtensible:
case Builtin::kReflectOwnKeys:
// Internal.
case Builtin::kStrictPoisonPillThrower:
case Builtin::kAllocateInYoungGeneration:
case Builtin::kAllocateInOldGeneration:
case Builtin::kConstructVarargs:
case Builtin::kConstructWithArrayLike:
case Builtin::kGetOwnPropertyDescriptor:
case Builtin::kOrdinaryGetOwnPropertyDescriptor:
#if V8_ENABLE_WEBASSEMBLY
case Builtin::kWasmAllocateInYoungGeneration:
case Builtin::kWasmAllocateInOldGeneration:
#endif // V8_ENABLE_WEBASSEMBLY
#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
case Builtin::kGetContinuationPreservedEmbedderData:
#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
return DebugInfo::kHasNoSideEffect;
#ifdef V8_INTL_SUPPORT
// Intl builtins.
case Builtin::kIntlGetCanonicalLocales:
// Intl.Collator builtins.
case Builtin::kCollatorConstructor:
case Builtin::kCollatorInternalCompare:
case Builtin::kCollatorPrototypeCompare:
case Builtin::kCollatorPrototypeResolvedOptions:
case Builtin::kCollatorSupportedLocalesOf:
// Intl.DateTimeFormat builtins.
case Builtin::kDateTimeFormatConstructor:
case Builtin::kDateTimeFormatInternalFormat:
case Builtin::kDateTimeFormatPrototypeFormat:
case Builtin::kDateTimeFormatPrototypeFormatRange:
case Builtin::kDateTimeFormatPrototypeFormatRangeToParts:
case Builtin::kDateTimeFormatPrototypeFormatToParts:
case Builtin::kDateTimeFormatPrototypeResolvedOptions:
case Builtin::kDateTimeFormatSupportedLocalesOf:
// Intl.DisplayNames builtins.
case Builtin::kDisplayNamesConstructor:
case Builtin::kDisplayNamesPrototypeOf:
case Builtin::kDisplayNamesPrototypeResolvedOptions:
case Builtin::kDisplayNamesSupportedLocalesOf:
// Intl.ListFormat builtins.
case Builtin::kListFormatConstructor:
case Builtin::kListFormatPrototypeFormat:
case Builtin::kListFormatPrototypeFormatToParts:
case Builtin::kListFormatPrototypeResolvedOptions:
case Builtin::kListFormatSupportedLocalesOf:
// Intl.Locale builtins.
case Builtin::kLocaleConstructor:
case Builtin::kLocalePrototypeBaseName:
case Builtin::kLocalePrototypeCalendar:
case Builtin::kLocalePrototypeCalendars:
case Builtin::kLocalePrototypeCaseFirst:
case Builtin::kLocalePrototypeCollation:
case Builtin::kLocalePrototypeCollations:
case Builtin::kLocalePrototypeFirstDayOfWeek:
case Builtin::kLocalePrototypeGetCalendars:
case Builtin::kLocalePrototypeGetCollations:
case Builtin::kLocalePrototypeGetHourCycles:
case Builtin::kLocalePrototypeGetNumberingSystems:
case Builtin::kLocalePrototypeGetTextInfo:
case Builtin::kLocalePrototypeGetTimeZones:
case Builtin::kLocalePrototypeGetWeekInfo:
case Builtin::kLocalePrototypeHourCycle:
case Builtin::kLocalePrototypeHourCycles:
case Builtin::kLocalePrototypeLanguage:
case Builtin::kLocalePrototypeMaximize:
case Builtin::kLocalePrototypeMinimize:
case Builtin::kLocalePrototypeNumeric:
case Builtin::kLocalePrototypeNumberingSystem:
case Builtin::kLocalePrototypeNumberingSystems:
case Builtin::kLocalePrototypeRegion:
case Builtin::kLocalePrototypeScript:
case Builtin::kLocalePrototypeTextInfo:
case Builtin::kLocalePrototypeTimeZones:
case Builtin::kLocalePrototypeToString:
case Builtin::kLocalePrototypeWeekInfo:
// Intl.NumberFormat builtins.
case Builtin::kNumberFormatConstructor:
case Builtin::kNumberFormatInternalFormatNumber:
case Builtin::kNumberFormatPrototypeFormatNumber:
case Builtin::kNumberFormatPrototypeFormatToParts:
case Builtin::kNumberFormatPrototypeResolvedOptions:
case Builtin::kNumberFormatSupportedLocalesOf:
// Intl.PluralRules builtins.
case Builtin::kPluralRulesConstructor:
case Builtin::kPluralRulesPrototypeResolvedOptions:
case Builtin::kPluralRulesPrototypeSelect:
case Builtin::kPluralRulesSupportedLocalesOf:
// Intl.RelativeTimeFormat builtins.
case Builtin::kRelativeTimeFormatConstructor:
case Builtin::kRelativeTimeFormatPrototypeFormat:
case Builtin::kRelativeTimeFormatPrototypeFormatToParts:
case Builtin::kRelativeTimeFormatPrototypeResolvedOptions:
case Builtin::kRelativeTimeFormatSupportedLocalesOf:
return DebugInfo::kHasNoSideEffect;
#endif // V8_INTL_SUPPORT
// Set builtins.
case Builtin::kSetIteratorPrototypeNext:
case Builtin::kSetPrototypeAdd:
case Builtin::kSetPrototypeClear:
case Builtin::kSetPrototypeDelete:
// Array builtins.
case Builtin::kArrayIteratorPrototypeNext:
case Builtin::kArrayPrototypeFill:
case Builtin::kArrayPrototypePop:
case Builtin::kArrayPrototypePush:
case Builtin::kArrayPrototypeReverse:
case Builtin::kArrayPrototypeShift:
case Builtin::kArrayPrototypeUnshift:
case Builtin::kArrayPrototypeSort:
case Builtin::kArrayPrototypeSplice:
case Builtin::kArrayUnshift:
// Map builtins.
case Builtin::kMapIteratorPrototypeNext:
case Builtin::kMapPrototypeClear:
case Builtin::kMapPrototypeDelete:
case Builtin::kMapPrototypeSet:
// Date builtins.