v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
debug-evaluate.cc
Go to the documentation of this file.
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
12#include "src/common/globals.h"
15#include "src/debug/debug.h"
23
24#if V8_ENABLE_WEBASSEMBLY
26#endif // V8_ENABLE_WEBASSEMBLY
27
28namespace v8 {
29namespace internal {
30
31namespace {
32static MaybeDirectHandle<SharedFunctionInfo> GetFunctionInfo(
33 Isolate* isolate, Handle<String> source, REPLMode repl_mode) {
34 ScriptDetails script_details(isolate->factory()->empty_string(),
35 ScriptOriginOptions(true, true));
36 script_details.repl_mode = repl_mode;
37 ScriptCompiler::CompilationDetails compilation_details;
39 isolate, source, script_details, ScriptCompiler::kNoCompileOptions,
41}
42} // namespace
43
45 Handle<String> source,
47 REPLMode repl_mode) {
49 if (!GetFunctionInfo(isolate, source, repl_mode).ToHandle(&shared_info)) {
51 }
52
53 DirectHandle<NativeContext> context = isolate->native_context();
55 Factory::JSFunctionBuilder{isolate, shared_info, context}.Build();
56
57 DisableBreak disable_break_scope(
58 isolate->debug(),
60 mode ==
62
64 isolate->debug()->StartSideEffectCheckMode();
65 }
66 // TODO(cbruni, 1244145): Use host-defined options from script context.
67 DirectHandle<FixedArray> host_defined_options(
68 Cast<Script>(function->shared()->script())->host_defined_options(),
69 isolate);
71 isolate, function,
72 DirectHandle<JSObject>(context->global_proxy(), isolate),
73 host_defined_options);
75 isolate->debug()->StopSideEffectCheckMode();
76 }
77 return result;
78}
79
81 StackFrameId frame_id,
82 int inlined_jsframe_index,
84 bool throw_on_side_effect) {
85 // Handle the processing of break.
86 DisableBreak disable_break_scope(isolate->debug());
87
88 // Get the frame where the debugging is performed.
89 DebuggableStackFrameIterator it(isolate, frame_id);
90#if V8_ENABLE_WEBASSEMBLY
91 if (it.is_wasm()) {
92#if V8_ENABLE_DRUMBRAKE
93 // TODO(paolosev@microsoft.com) - Not supported by Wasm interpreter.
94 if (it.is_wasm_interpreter_entry()) return {};
95#endif // V8_ENABLE_DRUMBRAKE
96 WasmFrame* frame = WasmFrame::cast(it.frame());
98 isolate->native_context()->empty_function()->shared(), isolate);
99 DirectHandle<JSObject> context_extension = GetWasmDebugProxy(frame);
100 DirectHandle<ScopeInfo> scope_info =
102 DirectHandle<Context> context = isolate->factory()->NewWithContext(
103 isolate->native_context(), scope_info, context_extension);
104 return Evaluate(isolate, outer_info, context, context_extension, source,
105 throw_on_side_effect);
106 }
107#endif // V8_ENABLE_WEBASSEMBLY
108
109 CHECK(it.is_javascript());
110 JavaScriptFrame* frame = it.javascript_frame();
111 // This is not a lot different than DebugEvaluate::Global, except that
112 // variables accessible by the function we are evaluating from are
113 // materialized and included on top of the native context. Changes to
114 // the materialized object are written back afterwards.
115 // Note that the native context is taken from the original context chain,
116 // which may not be the current native context of the isolate.
117 ContextBuilder context_builder(isolate, frame, inlined_jsframe_index);
118 if (isolate->has_exception()) return {};
119
120 DirectHandle<Context> context = context_builder.evaluation_context();
121 DirectHandle<JSObject> receiver(context->global_proxy(), isolate);
122 MaybeDirectHandle<Object> maybe_result =
123 Evaluate(isolate, context_builder.outer_info(), context, receiver, source,
124 throw_on_side_effect);
125 if (!maybe_result.is_null()) context_builder.UpdateValues();
126 return maybe_result;
127}
128
130 Isolate* isolate, DirectHandle<String> source) {
131 // Handle the processing of break.
132 DisableBreak disable_break_scope(isolate->debug());
133 Factory* factory = isolate->factory();
135
136 // Get context and receiver.
138 Cast<Context>(it.frame()->context())->native_context(), isolate);
139
140 // Materialize arguments as property on an extension object.
142 DirectHandle<String> arguments_str = factory->arguments_string();
144 materialized, arguments_str,
146 .Check();
147
148 // Materialize receiver.
149 DirectHandle<Object> this_value(it.frame()->receiver(), isolate);
150 DCHECK_EQ(it.frame()->IsConstructor(), IsTheHole(*this_value, isolate));
151 if (!IsTheHole(*this_value, isolate)) {
152 DirectHandle<String> this_str = factory->this_string();
153 JSObject::SetOwnPropertyIgnoreAttributes(materialized, this_str, this_value,
154 NONE)
155 .Check();
156 }
157
158 // Use extension object in a debug-evaluate scope.
159 DirectHandle<ScopeInfo> scope_info =
161 scope_info->SetIsDebugEvaluateScope();
162 DirectHandle<Context> evaluation_context = factory->NewDebugEvaluateContext(
163 native_context, scope_info, materialized, DirectHandle<Context>());
165 native_context->empty_function()->shared(), isolate);
166 DirectHandle<JSObject> receiver(native_context->global_proxy(), isolate);
167 const bool throw_on_side_effect = false;
168 MaybeDirectHandle<Object> maybe_result =
169 Evaluate(isolate, outer_info, evaluation_context, receiver, source,
170 throw_on_side_effect);
171 return maybe_result;
172}
173
174// Compile and evaluate source for the given context.
176 Isolate* isolate, DirectHandle<SharedFunctionInfo> outer_info,
178 DirectHandle<String> source, bool throw_on_side_effect) {
181 isolate, eval_fun,
182 Compiler::GetFunctionFromEval(source, outer_info, context,
186
188 bool success = false;
189 if (throw_on_side_effect) isolate->debug()->StartSideEffectCheckMode();
190 success = Execution::Call(isolate, eval_fun, receiver, {}).ToHandle(&result);
191 if (throw_on_side_effect) isolate->debug()->StopSideEffectCheckMode();
192 if (!success) DCHECK(isolate->has_exception());
193 return success ? result : MaybeHandle<Object>();
194}
195
200
202 JavaScriptFrame* frame,
203 int inlined_jsframe_index)
204 : isolate_(isolate),
205 frame_inspector_(frame, inlined_jsframe_index, isolate),
206 scope_iterator_(isolate, &frame_inspector_,
207 ScopeIterator::ReparseStrategy::kScriptIfNeeded) {
208 Handle<Context> outer_context(frame_inspector_.GetFunction()->context(),
209 isolate);
210 evaluation_context_ = outer_context;
211 Factory* factory = isolate->factory();
212
213 if (scope_iterator_.Done()) return;
214
215 // To evaluate as if we were running eval at the point of the debug break,
216 // we reconstruct the context chain as follows:
217 // - To make stack-allocated variables visible, we materialize them and
218 // use a debug-evaluate context to wrap both the materialized object and
219 // the original context.
220 // - Each scope from the break position up to the function scope is wrapped
221 // in a debug-evaluate context.
222 // - Between the function scope and the native context, we only resolve
223 // variable names that are guaranteed to not be shadowed by stack-allocated
224 // variables. ScopeInfos between the function scope and the native
225 // context have a blocklist attached to implement that.
226 // - The various block lists are calculated by the ScopeIterator during
227 // iteration.
228 // Context::Lookup has special handling for debug-evaluate contexts:
229 // - Look up in the materialized stack variables.
230 // - Look up in the original context.
231 // - Once we have seen a debug-evaluate context we start to take the
232 // block lists into account before moving up the context chain.
235 if (scope_type == ScopeIterator::ScopeTypeScript) break;
236 ContextChainElement context_chain_element;
237 if (scope_type == ScopeIterator::ScopeTypeLocal ||
239 context_chain_element.materialized_object =
241 }
243 context_chain_element.wrapped_context = scope_iterator_.CurrentContext();
244 }
245 context_chain_.push_back(context_chain_element);
246 }
247
248 DirectHandle<ScopeInfo> scope_info =
249 IsNativeContext(*evaluation_context_)
251 : direct_handle(evaluation_context_->scope_info(), isolate);
252 for (auto rit = context_chain_.rbegin(); rit != context_chain_.rend();
253 rit++) {
254 ContextChainElement element = *rit;
255 scope_info = ScopeInfo::CreateForWithScope(isolate, scope_info);
256 scope_info->SetIsDebugEvaluateScope();
257
258 // In the case where the "paused function scope" is the script scope
259 // itself, we don't need (and don't have) a blocklist.
260 const bool paused_scope_is_script_scope =
262 if (rit == context_chain_.rbegin() && !paused_scope_is_script_scope) {
263 // The DebugEvaluateContext we create for the closure scope is the only
264 // DebugEvaluateContext with a block list. This means we'll retrieve
265 // the existing block list from the paused function scope
266 // and also associate the temporary scope_info we create here with that
267 // blocklist.
268 DirectHandle<ScopeInfo> function_scope_info(
269 frame_inspector_.GetFunction()->shared()->scope_info(), isolate_);
270 DirectHandle<Object> block_list(
271 isolate_->LocalsBlockListCacheGet(function_scope_info), isolate_);
272 CHECK(IsStringSet(*block_list));
274 Cast<StringSet>(block_list));
275 }
276
278 evaluation_context_, scope_info, element.materialized_object,
279 element.wrapped_context);
280 }
281}
282
284 scope_iterator_.Restart();
285 for (ContextChainElement& element : context_chain_) {
286 if (!element.materialized_object.is_null()) {
288 KeyAccumulator::GetKeys(isolate_, element.materialized_object,
291 .ToHandleChecked();
292
293 for (int i = 0; i < keys->length(); i++) {
294 DCHECK(IsString(keys->get(i)));
297 isolate_, element.materialized_object, key);
298 scope_iterator_.SetVariableValue(key, value);
299 }
300 }
301 scope_iterator_.Next();
302 }
303}
304
305// static
307// Use macro to include only the non-inlined version of an intrinsic.
308#define INTRINSIC_ALLOWLIST(V) \
309 /* Conversions */ \
310 V(NumberToStringSlow) \
311 V(ToBigInt) \
312 V(ToLength) \
313 V(ToNumber) \
314 V(ToObject) \
315 V(ToString) \
316 /* Type checks */ \
317 V(IsArray) \
318 V(IsJSProxy) \
319 V(IsJSReceiver) \
320 V(IsSmi) \
321 /* Loads */ \
322 V(LoadLookupSlotForCall) \
323 V(GetPrivateMember) \
324 V(GetProperty) \
325 /* Arrays */ \
326 V(ArraySpeciesConstructor) \
327 V(HasFastPackedElements) \
328 V(NewArray) \
329 V(NormalizeElements) \
330 V(TypedArrayGetBuffer) \
331 /* Errors */ \
332 V(NewTypeError) \
333 V(ReThrow) \
334 V(ThrowCalledNonCallable) \
335 V(ThrowInvalidStringLength) \
336 V(ThrowIteratorError) \
337 V(ThrowIteratorResultNotAnObject) \
338 V(ThrowPatternAssignmentNonCoercible) \
339 V(ThrowReferenceError) \
340 V(ThrowSymbolIteratorInvalid) \
341 /* Strings */ \
342 V(StringReplaceOneCharWithString) \
343 V(StringSubstring) \
344 V(StringToNumber) \
345 /* BigInts */ \
346 V(BigIntEqualToBigInt) \
347 V(BigIntToNumber) \
348 /* Literals */ \
349 V(CreateArrayLiteral) \
350 V(CreateObjectLiteral) \
351 V(CreateRegExpLiteral) \
352 V(DefineClass) \
353 /* Called from builtins */ \
354 V(AllocateInYoungGeneration) \
355 V(AllocateInOldGeneration) \
356 V(ArrayIncludes_Slow) \
357 V(ArrayIndexOf) \
358 V(ArrayIsArray) \
359 V(GetFunctionName) \
360 V(GlobalPrint) \
361 V(HasProperty) \
362 V(ObjectCreate) \
363 V(ObjectEntries) \
364 V(ObjectEntriesSkipFastPath) \
365 V(ObjectHasOwnProperty) \
366 V(ObjectKeys) \
367 V(ObjectValues) \
368 V(ObjectValuesSkipFastPath) \
369 V(ObjectGetOwnPropertyNames) \
370 V(ObjectGetOwnPropertyNamesTryFast) \
371 V(ObjectIsExtensible) \
372 V(RegExpInitializeAndCompile) \
373 V(StackGuard) \
374 V(HandleNoHeapWritesInterrupts) \
375 V(StringAdd) \
376 V(StringCharCodeAt) \
377 V(StringEqual) \
378 V(StringParseFloat) \
379 V(StringParseInt) \
380 V(SymbolDescriptiveString) \
381 V(ThrowRangeError) \
382 V(ThrowTypeError) \
383 V(ToName) \
384 V(TransitionElementsKind) \
385 /* Misc. */ \
386 V(Call) \
387 V(CompleteInobjectSlackTrackingForMap) \
388 V(HasInPrototypeChain) \
389 V(IncrementUseCounter) \
390 V(MaxSmi) \
391 V(NewObject) \
392 V(StringMaxLength) \
393 V(StringToArray) \
394 V(AsyncFunctionEnter) \
395 V(AsyncFunctionResolve) \
396 /* Test */ \
397 V(GetOptimizationStatus) \
398 V(OptimizeFunctionOnNextCall) \
399 V(OptimizeOsr)
400
401// Intrinsics with inline versions have to be allowlisted here a second time.
402#define INLINE_INTRINSIC_ALLOWLIST(V) \
403 V(AsyncFunctionEnter) \
404 V(AsyncFunctionResolve)
405
406#define CASE(Name) case Runtime::k##Name:
407#define INLINE_CASE(Name) case Runtime::kInline##Name:
408 switch (id) {
411 return true;
412 default:
413 if (v8_flags.trace_side_effect_free_debug_evaluate) {
414 PrintF("[debug-evaluate] intrinsic %s may cause side effect.\n",
415 Runtime::FunctionForId(id)->name);
416 }
417 return false;
418 }
419
420#undef CASE
421#undef INLINE_CASE
422#undef INTRINSIC_ALLOWLIST
423#undef INLINE_INTRINSIC_ALLOWLIST
424}
425
426namespace {
427
428bool BytecodeHasNoSideEffect(interpreter::Bytecode bytecode) {
431 if (Bytecodes::IsWithoutExternalSideEffects(bytecode)) return true;
432 if (Bytecodes::IsCallOrConstruct(bytecode)) return true;
433 if (Bytecodes::IsJumpIfToBoolean(bytecode)) return true;
434 if (Bytecodes::IsPrefixScalingBytecode(bytecode)) return true;
435 switch (bytecode) {
436 // Allowlist for bytecodes.
437 // Loads.
438 case Bytecode::kLdaLookupSlot:
439 case Bytecode::kLdaGlobal:
440 case Bytecode::kGetNamedProperty:
441 case Bytecode::kGetKeyedProperty:
442 case Bytecode::kLdaGlobalInsideTypeof:
443 case Bytecode::kLdaLookupSlotInsideTypeof:
444 case Bytecode::kGetIterator:
445 // Arithmetics.
446 case Bytecode::kAdd:
447 case Bytecode::kAddSmi:
448 case Bytecode::kSub:
449 case Bytecode::kSubSmi:
450 case Bytecode::kMul:
451 case Bytecode::kMulSmi:
452 case Bytecode::kDiv:
453 case Bytecode::kDivSmi:
454 case Bytecode::kMod:
455 case Bytecode::kModSmi:
456 case Bytecode::kExp:
457 case Bytecode::kExpSmi:
458 case Bytecode::kNegate:
459 case Bytecode::kBitwiseAnd:
460 case Bytecode::kBitwiseAndSmi:
461 case Bytecode::kBitwiseNot:
462 case Bytecode::kBitwiseOr:
463 case Bytecode::kBitwiseOrSmi:
464 case Bytecode::kBitwiseXor:
465 case Bytecode::kBitwiseXorSmi:
466 case Bytecode::kShiftLeft:
467 case Bytecode::kShiftLeftSmi:
468 case Bytecode::kShiftRight:
469 case Bytecode::kShiftRightSmi:
470 case Bytecode::kShiftRightLogical:
471 case Bytecode::kShiftRightLogicalSmi:
472 case Bytecode::kInc:
473 case Bytecode::kDec:
474 case Bytecode::kLogicalNot:
475 case Bytecode::kToBooleanLogicalNot:
476 case Bytecode::kTypeOf:
477 // Contexts.
478 case Bytecode::kCreateBlockContext:
479 case Bytecode::kCreateCatchContext:
480 case Bytecode::kCreateFunctionContext:
481 case Bytecode::kCreateEvalContext:
482 case Bytecode::kCreateWithContext:
483 // Literals.
484 case Bytecode::kCreateArrayLiteral:
485 case Bytecode::kCreateEmptyArrayLiteral:
486 case Bytecode::kCreateArrayFromIterable:
487 case Bytecode::kCreateObjectLiteral:
488 case Bytecode::kCreateEmptyObjectLiteral:
489 case Bytecode::kCreateRegExpLiteral:
490 // Allocations.
491 case Bytecode::kCreateClosure:
492 case Bytecode::kCreateUnmappedArguments:
493 case Bytecode::kCreateRestParameter:
494 // Comparisons.
495 case Bytecode::kTestEqual:
496 case Bytecode::kTestEqualStrict:
497 case Bytecode::kTestLessThan:
498 case Bytecode::kTestLessThanOrEqual:
499 case Bytecode::kTestGreaterThan:
500 case Bytecode::kTestGreaterThanOrEqual:
501 case Bytecode::kTestInstanceOf:
502 case Bytecode::kTestIn:
503 case Bytecode::kTestReferenceEqual:
504 case Bytecode::kTestUndetectable:
505 case Bytecode::kTestTypeOf:
506 case Bytecode::kTestUndefined:
507 case Bytecode::kTestNull:
508 // Conversions.
509 case Bytecode::kToObject:
510 case Bytecode::kToName:
511 case Bytecode::kToNumber:
512 case Bytecode::kToNumeric:
513 case Bytecode::kToString:
514 case Bytecode::kToBoolean:
515 // Misc.
516 case Bytecode::kIncBlockCounter: // Coverage counters.
517 case Bytecode::kForInEnumerate:
518 case Bytecode::kForInPrepare:
519 case Bytecode::kForInNext:
520 case Bytecode::kForInStep:
521 case Bytecode::kJumpLoop:
522 case Bytecode::kThrow:
523 case Bytecode::kReThrow:
524 case Bytecode::kThrowReferenceErrorIfHole:
525 case Bytecode::kThrowSuperNotCalledIfHole:
526 case Bytecode::kThrowSuperAlreadyCalledIfNotHole:
527 case Bytecode::kIllegal:
528 case Bytecode::kCallJSRuntime:
529 case Bytecode::kReturn:
530 case Bytecode::kSetPendingMessage:
531 return true;
532 default:
533 return false;
534 }
535}
536
537DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
538 switch (id) {
539 // Allowlist for builtins.
540 // Object builtins.
541 case Builtin::kObjectConstructor:
542 case Builtin::kObjectCreate:
543 case Builtin::kObjectEntries:
544 case Builtin::kObjectGetOwnPropertyDescriptor:
545 case Builtin::kObjectGetOwnPropertyDescriptors:
546 case Builtin::kObjectGetOwnPropertyNames:
547 case Builtin::kObjectGetOwnPropertySymbols:
548 case Builtin::kObjectGetPrototypeOf:
549 case Builtin::kObjectGroupBy:
550 case Builtin::kObjectHasOwn:
551 case Builtin::kObjectIs:
552 case Builtin::kObjectIsExtensible:
553 case Builtin::kObjectIsFrozen:
554 case Builtin::kObjectIsSealed:
555 case Builtin::kObjectKeys:
556 case Builtin::kObjectPrototypeValueOf:
557 case Builtin::kObjectValues:
558 case Builtin::kObjectPrototypeHasOwnProperty:
559 case Builtin::kObjectPrototypeIsPrototypeOf:
560 case Builtin::kObjectPrototypePropertyIsEnumerable:
561 case Builtin::kObjectPrototypeToString:
562 case Builtin::kObjectPrototypeToLocaleString:
563 // Array builtins.
564 case Builtin::kArrayIsArray:
565 case Builtin::kArrayConstructor:
566 case Builtin::kArrayFrom:
567 case Builtin::kArrayIndexOf:
568 case Builtin::kArrayOf:
569 case Builtin::kArrayPrototypeValues:
570 case Builtin::kArrayIncludes:
571 case Builtin::kArrayPrototypeAt:
572 case Builtin::kArrayPrototypeConcat:
573 case Builtin::kArrayPrototypeEntries:
574 case Builtin::kArrayPrototypeFind:
575 case Builtin::kArrayPrototypeFindIndex:
576 case Builtin::kArrayPrototypeFindLast:
577 case Builtin::kArrayPrototypeFindLastIndex:
578 case Builtin::kArrayPrototypeFlat:
579 case Builtin::kArrayPrototypeFlatMap:
580 case Builtin::kArrayPrototypeJoin:
581 case Builtin::kArrayPrototypeKeys:
582 case Builtin::kArrayPrototypeLastIndexOf:
583 case Builtin::kArrayPrototypeSlice:
584 case Builtin::kArrayPrototypeToLocaleString:
585 case Builtin::kArrayPrototypeToReversed:
586 case Builtin::kArrayPrototypeToSorted:
587 case Builtin::kArrayPrototypeToSpliced:
588 case Builtin::kArrayPrototypeToString:
589 case Builtin::kArrayPrototypeWith:
590 case Builtin::kArrayForEach:
591 case Builtin::kArrayEvery:
592 case Builtin::kArraySome:
593 case Builtin::kArrayConcat:
594 case Builtin::kArrayFilter:
595 case Builtin::kArrayMap:
596 case Builtin::kArrayReduce:
597 case Builtin::kArrayReduceRight:
598 // Trace builtins.
599 case Builtin::kIsTraceCategoryEnabled:
600 case Builtin::kTrace:
601 // TypedArray builtins.
602 case Builtin::kTypedArrayConstructor:
603 case Builtin::kTypedArrayOf:
604 case Builtin::kTypedArrayPrototypeAt:
605 case Builtin::kTypedArrayPrototypeBuffer:
606 case Builtin::kTypedArrayPrototypeByteLength:
607 case Builtin::kTypedArrayPrototypeByteOffset:
608 case Builtin::kTypedArrayPrototypeLength:
609 case Builtin::kTypedArrayPrototypeEntries:
610 case Builtin::kTypedArrayPrototypeKeys:
611 case Builtin::kTypedArrayPrototypeValues:
612 case Builtin::kTypedArrayPrototypeFind:
613 case Builtin::kTypedArrayPrototypeFindIndex:
614 case Builtin::kTypedArrayPrototypeFindLast:
615 case Builtin::kTypedArrayPrototypeFindLastIndex:
616 case Builtin::kTypedArrayPrototypeIncludes:
617 case Builtin::kTypedArrayPrototypeJoin:
618 case Builtin::kTypedArrayPrototypeIndexOf:
619 case Builtin::kTypedArrayPrototypeLastIndexOf:
620 case Builtin::kTypedArrayPrototypeSlice:
621 case Builtin::kTypedArrayPrototypeSubArray:
622 case Builtin::kTypedArrayPrototypeEvery:
623 case Builtin::kTypedArrayPrototypeSome:
624 case Builtin::kTypedArrayPrototypeToLocaleString:
625 case Builtin::kTypedArrayPrototypeFilter:
626 case Builtin::kTypedArrayPrototypeMap:
627 case Builtin::kTypedArrayPrototypeReduce:
628 case Builtin::kTypedArrayPrototypeReduceRight:
629 case Builtin::kTypedArrayPrototypeForEach:
630 case Builtin::kTypedArrayPrototypeToReversed:
631 case Builtin::kTypedArrayPrototypeToSorted:
632 case Builtin::kTypedArrayPrototypeWith:
633 // ArrayBuffer builtins.
634 case Builtin::kArrayBufferConstructor:
635 case Builtin::kArrayBufferPrototypeGetByteLength:
636 case Builtin::kArrayBufferIsView:
637 case Builtin::kArrayBufferPrototypeSlice:
638 case Builtin::kReturnReceiver:
639 // DataView builtins.
640 case Builtin::kDataViewConstructor:
641 case Builtin::kDataViewPrototypeGetBuffer:
642 case Builtin::kDataViewPrototypeGetByteLength:
643 case Builtin::kDataViewPrototypeGetByteOffset:
644 case Builtin::kDataViewPrototypeGetInt8:
645 case Builtin::kDataViewPrototypeGetUint8:
646 case Builtin::kDataViewPrototypeGetInt16:
647 case Builtin::kDataViewPrototypeGetUint16:
648 case Builtin::kDataViewPrototypeGetInt32:
649 case Builtin::kDataViewPrototypeGetUint32:
650 case Builtin::kDataViewPrototypeGetFloat16:
651 case Builtin::kDataViewPrototypeGetFloat32:
652 case Builtin::kDataViewPrototypeGetFloat64:
653 case Builtin::kDataViewPrototypeGetBigInt64:
654 case Builtin::kDataViewPrototypeGetBigUint64:
655 // Boolean bulitins.
656 case Builtin::kBooleanConstructor:
657 case Builtin::kBooleanPrototypeToString:
658 case Builtin::kBooleanPrototypeValueOf:
659 // Date builtins.
660 case Builtin::kDateConstructor:
661 case Builtin::kDateNow:
662 case Builtin::kDateParse:
663 case Builtin::kDatePrototypeGetDate:
664 case Builtin::kDatePrototypeGetDay:
665 case Builtin::kDatePrototypeGetFullYear:
666 case Builtin::kDatePrototypeGetHours:
667 case Builtin::kDatePrototypeGetMilliseconds:
668 case Builtin::kDatePrototypeGetMinutes:
669 case Builtin::kDatePrototypeGetMonth:
670 case Builtin::kDatePrototypeGetSeconds:
671 case Builtin::kDatePrototypeGetTime:
672 case Builtin::kDatePrototypeGetTimezoneOffset:
673 case Builtin::kDatePrototypeGetUTCDate:
674 case Builtin::kDatePrototypeGetUTCDay:
675 case Builtin::kDatePrototypeGetUTCFullYear:
676 case Builtin::kDatePrototypeGetUTCHours:
677 case Builtin::kDatePrototypeGetUTCMilliseconds:
678 case Builtin::kDatePrototypeGetUTCMinutes:
679 case Builtin::kDatePrototypeGetUTCMonth:
680 case Builtin::kDatePrototypeGetUTCSeconds:
681 case Builtin::kDatePrototypeGetYear:
682 case Builtin::kDatePrototypeToDateString:
683 case Builtin::kDatePrototypeToISOString:
684 case Builtin::kDatePrototypeToUTCString:
685 case Builtin::kDatePrototypeToString:
686#ifdef V8_INTL_SUPPORT
687 case Builtin::kDatePrototypeToLocaleString:
688 case Builtin::kDatePrototypeToLocaleDateString:
689 case Builtin::kDatePrototypeToLocaleTimeString:
690#endif
691 case Builtin::kDatePrototypeToTimeString:
692 case Builtin::kDatePrototypeToJson:
693 case Builtin::kDatePrototypeToPrimitive:
694 case Builtin::kDatePrototypeValueOf:
695 // DisposableStack builtins.
696 case Builtin::kDisposableStackConstructor:
697 case Builtin::kDisposableStackPrototypeGetDisposed:
698 // AsyncDisposableStack builtins.
699 case Builtin::kAsyncDisposableStackConstructor:
700 case Builtin::kAsyncDisposableStackPrototypeGetDisposed:
701 // Map builtins.
702 case Builtin::kMapConstructor:
703 case Builtin::kMapGroupBy:
704 case Builtin::kMapPrototypeForEach:
705 case Builtin::kMapPrototypeGet:
706 case Builtin::kMapPrototypeHas:
707 case Builtin::kMapPrototypeEntries:
708 case Builtin::kMapPrototypeGetSize:
709 case Builtin::kMapPrototypeKeys:
710 case Builtin::kMapPrototypeValues:
711 // WeakMap builtins.
712 case Builtin::kWeakMapConstructor:
713 case Builtin::kWeakMapGet:
714 case Builtin::kWeakMapPrototypeHas:
715 // Math builtins.
716 case Builtin::kMathAbs:
717 case Builtin::kMathAcos:
718 case Builtin::kMathAcosh:
719 case Builtin::kMathAsin:
720 case Builtin::kMathAsinh:
721 case Builtin::kMathAtan:
722 case Builtin::kMathAtanh:
723 case Builtin::kMathAtan2:
724 case Builtin::kMathCeil:
725 case Builtin::kMathCbrt:
726 case Builtin::kMathExpm1:
727 case Builtin::kMathClz32:
728 case Builtin::kMathCos:
729 case Builtin::kMathCosh:
730 case Builtin::kMathExp:
731 case Builtin::kMathFloor:
732 case Builtin::kMathF16round:
733 case Builtin::kMathFround:
734 case Builtin::kMathHypot:
735 case Builtin::kMathImul:
736 case Builtin::kMathLog:
737 case Builtin::kMathLog1p:
738 case Builtin::kMathLog2:
739 case Builtin::kMathLog10:
740 case Builtin::kMathMax:
741 case Builtin::kMathMin:
742 case Builtin::kMathPow:
743 case Builtin::kMathRound:
744 case Builtin::kMathSign:
745 case Builtin::kMathSin:
746 case Builtin::kMathSinh:
747 case Builtin::kMathSqrt:
748 case Builtin::kMathTan:
749 case Builtin::kMathTanh:
750 case Builtin::kMathTrunc:
751 // Number builtins.
752 case Builtin::kNumberConstructor:
753 case Builtin::kNumberIsFinite:
754 case Builtin::kNumberIsInteger:
755 case Builtin::kNumberIsNaN:
756 case Builtin::kNumberIsSafeInteger:
757 case Builtin::kNumberParseFloat:
758 case Builtin::kNumberParseInt:
759 case Builtin::kNumberPrototypeToExponential:
760 case Builtin::kNumberPrototypeToFixed:
761 case Builtin::kNumberPrototypeToPrecision:
762 case Builtin::kNumberPrototypeToString:
763 case Builtin::kNumberPrototypeToLocaleString:
764 case Builtin::kNumberPrototypeValueOf:
765 // BigInt builtins.
766 case Builtin::kBigIntConstructor:
767 case Builtin::kBigIntAsIntN:
768 case Builtin::kBigIntAsUintN:
769 case Builtin::kBigIntPrototypeToString:
770 case Builtin::kBigIntPrototypeValueOf:
771 // Set builtins.
772 case Builtin::kSetConstructor:
773 case Builtin::kSetPrototypeEntries:
774 case Builtin::kSetPrototypeForEach:
775 case Builtin::kSetPrototypeGetSize:
776 case Builtin::kSetPrototypeHas:
777 case Builtin::kSetPrototypeValues:
778 // WeakSet builtins.
779 case Builtin::kWeakSetConstructor:
780 case Builtin::kWeakSetPrototypeHas:
781 // String builtins. Strings are immutable.
782 case Builtin::kStringFromCharCode:
783 case Builtin::kStringFromCodePoint:
784 case Builtin::kStringConstructor:
785 case Builtin::kStringListFromIterable:
786 case Builtin::kStringPrototypeAnchor:
787 case Builtin::kStringPrototypeAt:
788 case Builtin::kStringPrototypeBig:
789 case Builtin::kStringPrototypeBlink:
790 case Builtin::kStringPrototypeBold:
791 case Builtin::kStringPrototypeCharAt:
792 case Builtin::kStringPrototypeCharCodeAt:
793 case Builtin::kStringPrototypeCodePointAt:
794 case Builtin::kStringPrototypeConcat:
795 case Builtin::kStringPrototypeEndsWith:
796 case Builtin::kStringPrototypeFixed:
797 case Builtin::kStringPrototypeFontcolor:
798 case Builtin::kStringPrototypeFontsize:
799 case Builtin::kStringPrototypeIncludes:
800 case Builtin::kStringPrototypeIndexOf:
801 case Builtin::kStringPrototypeIsWellFormed:
802 case Builtin::kStringPrototypeItalics:
803 case Builtin::kStringPrototypeLastIndexOf:
804 case Builtin::kStringPrototypeLink:
805 case Builtin::kStringPrototypeMatch:
806 case Builtin::kStringPrototypeMatchAll:
807
808 case Builtin::kStringPrototypePadEnd:
809 case Builtin::kStringPrototypePadStart:
810 case Builtin::kStringPrototypeRepeat:
811 case Builtin::kStringPrototypeReplace:
812 case Builtin::kStringPrototypeReplaceAll:
813 case Builtin::kStringPrototypeSearch:
814 case Builtin::kStringPrototypeSlice:
815 case Builtin::kStringPrototypeSmall:
816 case Builtin::kStringPrototypeSplit:
817 case Builtin::kStringPrototypeStartsWith:
818 case Builtin::kStringSlowFlatten:
819 case Builtin::kStringPrototypeStrike:
820 case Builtin::kStringPrototypeSub:
821 case Builtin::kStringPrototypeSubstr:
822 case Builtin::kStringPrototypeSubstring:
823 case Builtin::kStringPrototypeSup:
824 case Builtin::kStringPrototypeToString:
825 case Builtin::kStringPrototypeToLocaleLowerCase:
826 case Builtin::kStringPrototypeToLocaleUpperCase:
827#ifdef V8_INTL_SUPPORT
828 case Builtin::kStringToLowerCaseIntl:
829 case Builtin::kStringPrototypeLocaleCompareIntl:
830 case Builtin::kStringPrototypeToLowerCaseIntl:
831 case Builtin::kStringPrototypeToUpperCaseIntl:
832 case Builtin::kStringPrototypeNormalizeIntl:
833#else
834 case Builtin::kStringPrototypeLocaleCompare:
835 case Builtin::kStringPrototypeToLowerCase:
836 case Builtin::kStringPrototypeToUpperCase:
837 case Builtin::kStringPrototypeNormalize:
838#endif
839 case Builtin::kStringPrototypeToWellFormed:
840 case Builtin::kStringPrototypeTrim:
841 case Builtin::kStringPrototypeTrimEnd:
842 case Builtin::kStringPrototypeTrimStart:
843 case Builtin::kStringPrototypeValueOf:
844 case Builtin::kStringToNumber:
845 case Builtin::kStringSubstring:
846 // Symbol builtins.
847 case Builtin::kSymbolConstructor:
848 case Builtin::kSymbolKeyFor:
849 case Builtin::kSymbolPrototypeToString:
850 case Builtin::kSymbolPrototypeValueOf:
851 case Builtin::kSymbolPrototypeToPrimitive:
852 // JSON builtins.
853 case Builtin::kJsonParse:
854 case Builtin::kJsonStringify:
855 // Global function builtins.
856 case Builtin::kGlobalDecodeURI:
857 case Builtin::kGlobalDecodeURIComponent:
858 case Builtin::kGlobalEncodeURI:
859 case Builtin::kGlobalEncodeURIComponent:
860 case Builtin::kGlobalEscape:
861 case Builtin::kGlobalUnescape:
862 case Builtin::kGlobalIsFinite:
863 case Builtin::kGlobalIsNaN:
864 // Function builtins.
865 case Builtin::kFunctionPrototypeToString:
866 case Builtin::kFunctionPrototypeBind:
867 case Builtin::kFastFunctionPrototypeBind:
868 case Builtin::kFunctionPrototypeCall:
869 case Builtin::kFunctionPrototypeApply:
870 // Error builtins.
871 case Builtin::kErrorConstructor:
872 // RegExp builtins.
873 case Builtin::kRegExpConstructor:
874 // Reflect builtins.
875 case Builtin::kReflectApply:
876 case Builtin::kReflectConstruct:
877 case Builtin::kReflectGetOwnPropertyDescriptor:
878 case Builtin::kReflectGetPrototypeOf:
879 case Builtin::kReflectHas:
880 case Builtin::kReflectIsExtensible:
881 case Builtin::kReflectOwnKeys:
882 // Internal.
883 case Builtin::kStrictPoisonPillThrower:
884 case Builtin::kAllocateInYoungGeneration:
885 case Builtin::kAllocateInOldGeneration:
886 case Builtin::kConstructVarargs:
887 case Builtin::kConstructWithArrayLike:
888 case Builtin::kGetOwnPropertyDescriptor:
889 case Builtin::kOrdinaryGetOwnPropertyDescriptor:
890#if V8_ENABLE_WEBASSEMBLY
891 case Builtin::kWasmAllocateInYoungGeneration:
892 case Builtin::kWasmAllocateInOldGeneration:
893#endif // V8_ENABLE_WEBASSEMBLY
894#ifdef V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
895 case Builtin::kGetContinuationPreservedEmbedderData:
896#endif // V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA
898
899#ifdef V8_INTL_SUPPORT
900 // Intl builtins.
901 case Builtin::kIntlGetCanonicalLocales:
902 // Intl.Collator builtins.
903 case Builtin::kCollatorConstructor:
904 case Builtin::kCollatorInternalCompare:
905 case Builtin::kCollatorPrototypeCompare:
906 case Builtin::kCollatorPrototypeResolvedOptions:
907 case Builtin::kCollatorSupportedLocalesOf:
908 // Intl.DateTimeFormat builtins.
909 case Builtin::kDateTimeFormatConstructor:
910 case Builtin::kDateTimeFormatInternalFormat:
911 case Builtin::kDateTimeFormatPrototypeFormat:
912 case Builtin::kDateTimeFormatPrototypeFormatRange:
913 case Builtin::kDateTimeFormatPrototypeFormatRangeToParts:
914 case Builtin::kDateTimeFormatPrototypeFormatToParts:
915 case Builtin::kDateTimeFormatPrototypeResolvedOptions:
916 case Builtin::kDateTimeFormatSupportedLocalesOf:
917 // Intl.DisplayNames builtins.
918 case Builtin::kDisplayNamesConstructor:
919 case Builtin::kDisplayNamesPrototypeOf:
920 case Builtin::kDisplayNamesPrototypeResolvedOptions:
921 case Builtin::kDisplayNamesSupportedLocalesOf:
922 // Intl.ListFormat builtins.
923 case Builtin::kListFormatConstructor:
924 case Builtin::kListFormatPrototypeFormat:
925 case Builtin::kListFormatPrototypeFormatToParts:
926 case Builtin::kListFormatPrototypeResolvedOptions:
927 case Builtin::kListFormatSupportedLocalesOf:
928 // Intl.Locale builtins.
929 case Builtin::kLocaleConstructor:
930 case Builtin::kLocalePrototypeBaseName:
931 case Builtin::kLocalePrototypeCalendar:
932 case Builtin::kLocalePrototypeCalendars:
933 case Builtin::kLocalePrototypeCaseFirst:
934 case Builtin::kLocalePrototypeCollation:
935 case Builtin::kLocalePrototypeCollations:
936 case Builtin::kLocalePrototypeFirstDayOfWeek:
937 case Builtin::kLocalePrototypeGetCalendars:
938 case Builtin::kLocalePrototypeGetCollations:
939 case Builtin::kLocalePrototypeGetHourCycles:
940 case Builtin::kLocalePrototypeGetNumberingSystems:
941 case Builtin::kLocalePrototypeGetTextInfo:
942 case Builtin::kLocalePrototypeGetTimeZones:
943 case Builtin::kLocalePrototypeGetWeekInfo:
944 case Builtin::kLocalePrototypeHourCycle:
945 case Builtin::kLocalePrototypeHourCycles:
946 case Builtin::kLocalePrototypeLanguage:
947 case Builtin::kLocalePrototypeMaximize:
948 case Builtin::kLocalePrototypeMinimize:
949 case Builtin::kLocalePrototypeNumeric:
950 case Builtin::kLocalePrototypeNumberingSystem:
951 case Builtin::kLocalePrototypeNumberingSystems:
952 case Builtin::kLocalePrototypeRegion:
953 case Builtin::kLocalePrototypeScript:
954 case Builtin::kLocalePrototypeTextInfo:
955 case Builtin::kLocalePrototypeTimeZones:
956 case Builtin::kLocalePrototypeToString:
957 case Builtin::kLocalePrototypeWeekInfo:
958 // Intl.NumberFormat builtins.
959 case Builtin::kNumberFormatConstructor:
960 case Builtin::kNumberFormatInternalFormatNumber:
961 case Builtin::kNumberFormatPrototypeFormatNumber:
962 case Builtin::kNumberFormatPrototypeFormatToParts:
963 case Builtin::kNumberFormatPrototypeResolvedOptions:
964 case Builtin::kNumberFormatSupportedLocalesOf:
965 // Intl.PluralRules builtins.
966 case Builtin::kPluralRulesConstructor:
967 case Builtin::kPluralRulesPrototypeResolvedOptions:
968 case Builtin::kPluralRulesPrototypeSelect:
969 case Builtin::kPluralRulesSupportedLocalesOf:
970 // Intl.RelativeTimeFormat builtins.
971 case Builtin::kRelativeTimeFormatConstructor:
972 case Builtin::kRelativeTimeFormatPrototypeFormat:
973 case Builtin::kRelativeTimeFormatPrototypeFormatToParts:
974 case Builtin::kRelativeTimeFormatPrototypeResolvedOptions:
975 case Builtin::kRelativeTimeFormatSupportedLocalesOf:
977#endif // V8_INTL_SUPPORT
978
979 // Set builtins.
980 case Builtin::kSetIteratorPrototypeNext:
981 case Builtin::kSetPrototypeAdd:
982 case Builtin::kSetPrototypeClear:
983 case Builtin::kSetPrototypeDelete:
984 // Array builtins.
985 case Builtin::kArrayIteratorPrototypeNext:
986 case Builtin::kArrayPrototypeFill:
987 case Builtin::kArrayPrototypePop:
988 case Builtin::kArrayPrototypePush:
989 case Builtin::kArrayPrototypeReverse:
990 case Builtin::kArrayPrototypeShift:
991 case Builtin::kArrayPrototypeUnshift:
992 case Builtin::kArrayPrototypeSort:
993 case Builtin::kArrayPrototypeSplice:
994 case Builtin::kArrayUnshift:
995 // Map builtins.
996 case Builtin::kMapIteratorPrototypeNext:
997 case Builtin::kMapPrototypeClear:
998 case Builtin::kMapPrototypeDelete:
999 case Builtin::kMapPrototypeSet:
1000 // Date builtins.
1001 case Builtin::kDatePrototypeSetDate:
1002 case Builtin::kDatePrototypeSetFullYear:
1003 case Builtin::kDatePrototypeSetHours:
1004 case Builtin::kDatePrototypeSetMilliseconds:
1005 case Builtin::kDatePrototypeSetMinutes:
1006 case Builtin::kDatePrototypeSetMonth:
1007 case Builtin::kDatePrototypeSetSeconds:
1008 case Builtin::kDatePrototypeSetTime:
1009 case Builtin::kDatePrototypeSetUTCDate:
1010 case Builtin::kDatePrototypeSetUTCFullYear:
1011 case Builtin::kDatePrototypeSetUTCHours:
1012 case Builtin::kDatePrototypeSetUTCMilliseconds:
1013 case Builtin::kDatePrototypeSetUTCMinutes:
1014 case Builtin::kDatePrototypeSetUTCMonth:
1015 case Builtin::kDatePrototypeSetUTCSeconds:
1016 case Builtin::kDatePrototypeSetYear:
1017 // DisposableStack builtins.
1018 case Builtin::kDisposableStackPrototypeUse:
1019 case Builtin::kDisposableStackPrototypeDispose:
1020 case Builtin::kDisposableStackPrototypeAdopt:
1021 case Builtin::kDisposableStackPrototypeDefer:
1022 case Builtin::kDisposableStackPrototypeMove:
1023 // AsyncDisposableStack builtins.
1024 case Builtin::kAsyncDisposableStackPrototypeUse:
1025 case Builtin::kAsyncDisposableStackPrototypeDisposeAsync:
1026 case Builtin::kAsyncDisposableStackPrototypeAdopt:
1027 case Builtin::kAsyncDisposableStackPrototypeDefer:
1028 case Builtin::kAsyncDisposableStackPrototypeMove:
1029 // RegExp builtins.
1030 case Builtin::kRegExpPrototypeTest:
1031 case Builtin::kRegExpPrototypeExec:
1032 case Builtin::kRegExpPrototypeSplit:
1033 case Builtin::kRegExpPrototypeFlagsGetter:
1034 case Builtin::kRegExpPrototypeGlobalGetter:
1035 case Builtin::kRegExpPrototypeHasIndicesGetter:
1036 case Builtin::kRegExpPrototypeIgnoreCaseGetter:
1037 case Builtin::kRegExpPrototypeMatch:
1038 case Builtin::kRegExpPrototypeMatchAll:
1039 case Builtin::kRegExpPrototypeMultilineGetter:
1040 case Builtin::kRegExpPrototypeDotAllGetter:
1041 case Builtin::kRegExpPrototypeUnicodeGetter:
1042 case Builtin::kRegExpPrototypeUnicodeSetsGetter:
1043 case Builtin::kRegExpPrototypeStickyGetter:
1044 case Builtin::kRegExpPrototypeReplace:
1045 case Builtin::kRegExpPrototypeSearch:
1047
1048 // Debugging builtins.
1049 case Builtin::kDebugPrintFloat64:
1050 case Builtin::kDebugPrintWordPtr:
1052
1053 default:
1054 if (v8_flags.trace_side_effect_free_debug_evaluate) {
1055 PrintF("[debug-evaluate] built-in %s may cause side effect.\n",
1056 Builtins::name(id));
1057 }
1059 }
1060}
1061
1062bool BytecodeRequiresRuntimeCheck(interpreter::Bytecode bytecode) {
1064 switch (bytecode) {
1065 case Bytecode::kSetNamedProperty:
1066 case Bytecode::kDefineNamedOwnProperty:
1067 case Bytecode::kSetKeyedProperty:
1068 case Bytecode::kStaInArrayLiteral:
1069 case Bytecode::kDefineKeyedOwnPropertyInLiteral:
1070 case Bytecode::kStaCurrentContextSlot:
1071 return true;
1072 default:
1074 }
1075}
1076
1077} // anonymous namespace
1078
1079// static
1082 if (v8_flags.trace_side_effect_free_debug_evaluate) {
1083 PrintF("[debug-evaluate] Checking function %s for side effect.\n",
1084 info->DebugNameCStr().get());
1085 }
1086
1087 DCHECK(info->is_compiled());
1088 DCHECK(!info->needs_script_context());
1089 if (info->HasBytecodeArray()) {
1090 // Check bytecodes against allowlist.
1091 Handle<BytecodeArray> bytecode_array(info->GetBytecodeArray(isolate),
1092 isolate);
1093 if (v8_flags.trace_side_effect_free_debug_evaluate) {
1094 Print(*bytecode_array);
1095 }
1096 bool requires_runtime_checks = false;
1097 for (interpreter::BytecodeArrayIterator it(bytecode_array); !it.done();
1098 it.Advance()) {
1099 interpreter::Bytecode bytecode = it.current_bytecode();
1100 if (BytecodeHasNoSideEffect(bytecode)) continue;
1101 if (BytecodeRequiresRuntimeCheck(bytecode)) {
1102 requires_runtime_checks = true;
1103 continue;
1104 }
1105
1106 if (v8_flags.trace_side_effect_free_debug_evaluate) {
1107 PrintF("[debug-evaluate] bytecode %s may cause side effect.\n",
1109 }
1110
1111 // Did not match allowlist.
1113 }
1114 return requires_runtime_checks ? DebugInfo::kRequiresRuntimeChecks
1116 } else if (info->IsApiFunction()) {
1117 Tagged<Code> code = info->GetCode(isolate);
1118 if (code->is_builtin()) {
1119 return code->builtin_id() == Builtin::kHandleApiCallOrConstruct
1122 }
1123 } else {
1124 // Check built-ins against allowlist.
1125 Builtin builtin =
1126 info->HasBuiltinId() ? info->builtin_id() : Builtin::kNoBuiltinId;
1128 DebugInfo::SideEffectState state = BuiltinGetSideEffectState(builtin);
1129 return state;
1130 }
1131
1133}
1134
1135#ifdef DEBUG
1136static bool TransitivelyCalledBuiltinHasNoSideEffect(Builtin caller,
1137 Builtin callee) {
1138 switch (callee) {
1139 // Transitively called Builtins:
1140 case Builtin::kAbort:
1141 case Builtin::kAbortCSADcheck:
1142 case Builtin::kAdaptorWithBuiltinExitFrame0:
1143 case Builtin::kAdaptorWithBuiltinExitFrame1:
1144 case Builtin::kAdaptorWithBuiltinExitFrame2:
1145 case Builtin::kAdaptorWithBuiltinExitFrame3:
1146 case Builtin::kAdaptorWithBuiltinExitFrame4:
1147 case Builtin::kAdaptorWithBuiltinExitFrame5:
1148 case Builtin::kArrayConstructorImpl:
1149 case Builtin::kArrayEveryLoopContinuation:
1150 case Builtin::kArrayFilterLoopContinuation:
1151 case Builtin::kArrayFindIndexLoopContinuation:
1152 case Builtin::kArrayFindLoopContinuation:
1153 case Builtin::kArrayFindLastIndexLoopContinuation:
1154 case Builtin::kArrayFindLastLoopContinuation:
1155 case Builtin::kArrayForEachLoopContinuation:
1156 case Builtin::kArrayIncludesHoleyDoubles:
1157 case Builtin::kArrayIncludesPackedDoubles:
1158 case Builtin::kArrayIncludesSmi:
1159 case Builtin::kArrayIncludesSmiOrObject:
1160 case Builtin::kArrayIndexOfHoleyDoubles:
1161 case Builtin::kArrayIndexOfPackedDoubles:
1162 case Builtin::kArrayIndexOfSmi:
1163 case Builtin::kArrayIndexOfSmiOrObject:
1164 case Builtin::kArrayMapLoopContinuation:
1165 case Builtin::kArrayReduceLoopContinuation:
1166 case Builtin::kArrayReduceRightLoopContinuation:
1167 case Builtin::kArraySomeLoopContinuation:
1168 case Builtin::kArrayTimSort:
1169 case Builtin::kArrayTimSortIntoCopy:
1170 case Builtin::kCall_ReceiverIsAny:
1171 case Builtin::kCall_ReceiverIsNotNullOrUndefined:
1172 case Builtin::kCall_ReceiverIsNullOrUndefined:
1173 case Builtin::kCallWithArrayLike:
1174 case Builtin::kCEntry_Return1_ArgvOnStack_NoBuiltinExit:
1175 case Builtin::kCEntry_Return1_ArgvOnStack_BuiltinExit:
1176 case Builtin::kCEntry_Return1_ArgvInRegister_NoBuiltinExit:
1177 case Builtin::kCEntry_Return2_ArgvOnStack_NoBuiltinExit:
1178 case Builtin::kCEntry_Return2_ArgvOnStack_BuiltinExit:
1179 case Builtin::kCEntry_Return2_ArgvInRegister_NoBuiltinExit:
1180 case Builtin::kWasmCEntry:
1181 case Builtin::kCloneFastJSArray:
1182 case Builtin::kCloneFastJSArrayFillingHoles:
1183 case Builtin::kConstruct:
1184 case Builtin::kConvertToLocaleString:
1185 case Builtin::kCreateTypedArray:
1186 case Builtin::kDirectCEntry:
1187 case Builtin::kDoubleToI:
1188 case Builtin::kExtractFastJSArray:
1189 case Builtin::kFastNewObject:
1190 case Builtin::kFindOrderedHashMapEntry:
1191 case Builtin::kFindOrderedHashSetEntry:
1192 case Builtin::kFlattenIntoArrayWithMapFn:
1193 case Builtin::kFlattenIntoArrayWithoutMapFn:
1194 case Builtin::kGenericArrayToReversed:
1195 case Builtin::kGenericArrayWith:
1196 case Builtin::kGetProperty:
1197 case Builtin::kGetPropertyWithReceiver:
1198 case Builtin::kGroupByGeneric:
1199 case Builtin::kHasProperty:
1200 case Builtin::kCreateHTML:
1201 case Builtin::kMapIteratorToList:
1202 case Builtin::kNonNumberToNumber:
1203 case Builtin::kNonPrimitiveToPrimitive_Number:
1204 case Builtin::kNumberToString:
1205 case Builtin::kObjectToString:
1206 case Builtin::kOrderedHashTableHealIndex:
1207 case Builtin::kOrdinaryToPrimitive_Number:
1208 case Builtin::kOrdinaryToPrimitive_String:
1209 case Builtin::kParseInt:
1210 case Builtin::kProxyHasProperty:
1211 case Builtin::kProxyIsExtensible:
1212 case Builtin::kProxyGetPrototypeOf:
1213 case Builtin::kRecordWriteSaveFP:
1214 case Builtin::kRecordWriteIgnoreFP:
1215 case Builtin::kSetOrSetIteratorToList:
1216 case Builtin::kStringAdd_CheckNone:
1217 case Builtin::kStringEqual:
1218 case Builtin::kStringIndexOf:
1219 case Builtin::kStringRepeat:
1220 case Builtin::kStringToList:
1221 case Builtin::kBigIntEqual:
1222 case Builtin::kToInteger:
1223 case Builtin::kToLength:
1224 case Builtin::kToName:
1225 case Builtin::kToObject:
1226 case Builtin::kToString:
1227 case Builtin::kTypedArrayMergeSort:
1228#ifdef V8_IS_TSAN
1229 case Builtin::kTSANRelaxedStore8IgnoreFP:
1230 case Builtin::kTSANRelaxedStore8SaveFP:
1231 case Builtin::kTSANRelaxedStore16IgnoreFP:
1232 case Builtin::kTSANRelaxedStore16SaveFP:
1233 case Builtin::kTSANRelaxedStore32IgnoreFP:
1234 case Builtin::kTSANRelaxedStore32SaveFP:
1235 case Builtin::kTSANRelaxedStore64IgnoreFP:
1236 case Builtin::kTSANRelaxedStore64SaveFP:
1237 case Builtin::kTSANSeqCstStore8IgnoreFP:
1238 case Builtin::kTSANSeqCstStore8SaveFP:
1239 case Builtin::kTSANSeqCstStore16IgnoreFP:
1240 case Builtin::kTSANSeqCstStore16SaveFP:
1241 case Builtin::kTSANSeqCstStore32IgnoreFP:
1242 case Builtin::kTSANSeqCstStore32SaveFP:
1243 case Builtin::kTSANSeqCstStore64IgnoreFP:
1244 case Builtin::kTSANSeqCstStore64SaveFP:
1245 case Builtin::kTSANRelaxedLoad32IgnoreFP:
1246 case Builtin::kTSANRelaxedLoad32SaveFP:
1247 case Builtin::kTSANRelaxedLoad64IgnoreFP:
1248 case Builtin::kTSANRelaxedLoad64SaveFP:
1249#endif // V8_IS_TSAN
1250 case Builtin::kWeakMapLookupHashIndex:
1251 return true;
1252 case Builtin::kJoinStackPop:
1253 case Builtin::kJoinStackPush:
1254 switch (caller) {
1255 case Builtin::kArrayPrototypeJoin:
1256 case Builtin::kArrayPrototypeToLocaleString:
1257 case Builtin::kTypedArrayPrototypeJoin:
1258 case Builtin::kTypedArrayPrototypeToLocaleString:
1259 return true;
1260 default:
1261 return false;
1262 }
1263 case Builtin::kFastCreateDataProperty:
1264 switch (caller) {
1265 case Builtin::kArrayOf:
1266 case Builtin::kArrayPrototypeSlice:
1267 case Builtin::kArrayPrototypeToSpliced:
1268 case Builtin::kArrayPrototypeWith:
1269 case Builtin::kArrayFilter:
1270 case Builtin::kArrayFrom:
1271 return true;
1272 default:
1273 return false;
1274 }
1275 case Builtin::kSetProperty:
1276 switch (caller) {
1277 case Builtin::kArrayOf:
1278 case Builtin::kArrayPrototypeSlice:
1279 case Builtin::kArrayPrototypeToSorted:
1280 case Builtin::kArrayFrom:
1281 case Builtin::kTypedArrayPrototypeMap:
1282 case Builtin::kStringPrototypeMatchAll:
1283 return true;
1284 default:
1285 return false;
1286 }
1287 case Builtin::kRegExpMatchFast:
1288 // This is not a problem. We force String.prototype.match to take the
1289 // slow path so that this call is not made.
1290 return caller == Builtin::kStringPrototypeMatch;
1291 case Builtin::kRegExpReplace:
1292 // This is not a problem. We force String.prototype.replace to take the
1293 // slow path so that this call is not made.
1294 return caller == Builtin::kStringPrototypeReplace;
1295 case Builtin::kRegExpSplit:
1296 // This is not a problem. We force String.prototype.split to take the
1297 // slow path so that this call is not made.
1298 return caller == Builtin::kStringPrototypeSplit;
1299 case Builtin::kRegExpSearchFast:
1300 // This is not a problem. We force String.prototype.split to take the
1301 // slow path so that this call is not made.
1302 return caller == Builtin::kStringPrototypeSearch;
1303 default:
1304 return false;
1305 }
1306}
1307
1308// static
1309void DebugEvaluate::VerifyTransitiveBuiltins(Isolate* isolate) {
1310 // TODO(yangguo): also check runtime calls.
1311 bool failed = false;
1312 bool sanity_check = false;
1313 for (Builtin caller = Builtins::kFirst; caller <= Builtins::kLast; ++caller) {
1314 DebugInfo::SideEffectState state = BuiltinGetSideEffectState(caller);
1315 if (state != DebugInfo::kHasNoSideEffect) continue;
1316 Tagged<Code> code = isolate->builtins()->code(caller);
1319
1320 for (RelocIterator it(code, mode); !it.done(); it.next()) {
1321 RelocInfo* rinfo = it.rinfo();
1322 DCHECK(RelocInfo::IsCodeTargetMode(rinfo->rmode()));
1323 Tagged<Code> lookup_result =
1324 isolate->heap()->FindCodeForInnerPointer(rinfo->target_address());
1325 Builtin callee = lookup_result->builtin_id();
1326 if (BuiltinGetSideEffectState(callee) == DebugInfo::kHasNoSideEffect) {
1327 continue;
1328 }
1329 if (TransitivelyCalledBuiltinHasNoSideEffect(caller, callee)) {
1330 sanity_check = true;
1331 continue;
1332 }
1333 PrintF("Allowlisted builtin %s calls non-allowlisted builtin %s\n",
1334 Builtins::name(caller), Builtins::name(callee));
1335 failed = true;
1336 }
1337 }
1338 CHECK(!failed);
1339#if defined(V8_TARGET_ARCH_PPC64) || defined(V8_TARGET_ARCH_MIPS64) || \
1340 defined(V8_TARGET_ARCH_RISCV32) || defined(V8_TARGET_ARCH_RISCV64)
1341 // Isolate-independent builtin calls and jumps do not emit reloc infos
1342 // on PPC. We try to avoid using PC relative code due to performance
1343 // issue with especially older hardwares.
1344 // MIPS64 doesn't have PC relative code currently.
1345 // TODO(mips): Add PC relative code to MIPS64.
1346 USE(sanity_check);
1347#else
1348 CHECK(sanity_check);
1349#endif
1350}
1351#endif // DEBUG
1352
1353// static
1355 Handle<BytecodeArray> bytecode_array) {
1356 for (interpreter::BytecodeArrayIterator it(bytecode_array); !it.done();
1357 it.Advance()) {
1358 interpreter::Bytecode bytecode = it.current_bytecode();
1359 if (BytecodeRequiresRuntimeCheck(bytecode)) it.ApplyDebugBreak();
1360 }
1361}
1362
1363} // namespace internal
1364} // namespace v8
Isolate * isolate_
static Handle< JSObject > FunctionGetArguments(JavaScriptFrame *frame, int inlined_jsframe_index)
Definition accessors.cc:520
static constexpr Builtin kFirst
Definition builtins.h:112
static constexpr bool IsBuiltinId(Builtin builtin)
Definition builtins.h:128
static constexpr Builtin kLast
Definition builtins.h:113
static V8_EXPORT_PRIVATE const char * name(Builtin builtin)
Definition builtins.cc:226
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSFunction > GetFunctionFromEval(DirectHandle< String > source, DirectHandle< SharedFunctionInfo > outer_info, DirectHandle< Context > context, LanguageMode language_mode, ParseRestriction restriction, int parameters_end_pos, int eval_position, ParsingWhileDebugging parsing_while_debugging=ParsingWhileDebugging::kNo)
Definition compiler.cc:3250
static MaybeDirectHandle< SharedFunctionInfo > GetSharedFunctionInfoForScript(Isolate *isolate, Handle< String > source, const ScriptDetails &script_details, ScriptCompiler::CompileOptions compile_options, ScriptCompiler::NoCacheReason no_cache_reason, NativesFlag is_natives_code, ScriptCompiler::CompilationDetails *compilation_details)
Definition compiler.cc:4062
DirectHandle< Context > evaluation_context() const
std::vector< ContextChainElement > context_chain_
ContextBuilder(Isolate *isolate, JavaScriptFrame *frame, int inlined_jsframe_index)
DirectHandle< SharedFunctionInfo > outer_info() const
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > Global(Isolate *isolate, Handle< String > source, debug::EvaluateGlobalMode mode, REPLMode repl_mode=REPLMode::kNo)
static void ApplySideEffectChecks(Handle< BytecodeArray > bytecode_array)
static MaybeDirectHandle< Object > WithTopmostArguments(Isolate *isolate, DirectHandle< String > source)
static bool IsSideEffectFreeIntrinsic(Runtime::FunctionId id)
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > Local(Isolate *isolate, StackFrameId frame_id, int inlined_jsframe_index, DirectHandle< String > source, bool throw_on_side_effect)
static DebugInfo::SideEffectState FunctionGetSideEffectState(Isolate *isolate, DirectHandle< SharedFunctionInfo > info)
static MaybeDirectHandle< Object > Evaluate(Isolate *isolate, DirectHandle< SharedFunctionInfo > outer_info, DirectHandle< Context > context, DirectHandle< Object > receiver, DirectHandle< String > source, bool throw_on_side_effect)
static V8_INLINE const DirectHandle null()
Definition handles.h:661
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > CallScript(Isolate *isolate, DirectHandle< JSFunction > callable, DirectHandle< Object > receiver, DirectHandle< Object > host_defined_options)
Definition execution.cc:535
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > Call(Isolate *isolate, DirectHandle< Object > callable, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args)
Definition execution.cc:523
V8_WARN_UNUSED_RESULT Handle< JSFunction > Build()
Definition factory.cc:4732
Handle< JSObject > NewSlowJSObjectWithNullProto()
Definition factory.cc:2998
Handle< Context > NewDebugEvaluateContext(DirectHandle< Context > previous, DirectHandle< ScopeInfo > scope_info, DirectHandle< JSReceiver > extension, DirectHandle< Context > wrapped)
Definition factory.cc:1434
Handle< JSFunction > GetFunction() const
void LocalsBlockListCacheSet(DirectHandle< ScopeInfo > scope_info, DirectHandle< ScopeInfo > outer_scope_info, DirectHandle< StringSet > locals_blocklist)
Definition isolate.cc:7565
Tagged< Object > LocalsBlockListCacheGet(DirectHandle< ScopeInfo > scope_info)
Definition isolate.cc:7593
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > V8_EXPORT_PRIVATE SetOwnPropertyIgnoreAttributes(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static Handle< Object > GetDataProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
static MaybeHandle< FixedArray > GetKeys(Isolate *isolate, DirectHandle< JSReceiver > object, KeyCollectionMode mode, PropertyFilter filter, GetKeysConversion keys_conversion=GetKeysConversion::kKeepNumbers, bool is_for_in=false, bool skip_indices=false)
Definition keys.cc:97
V8_INLINE bool is_null() const
static constexpr bool IsCodeTargetMode(Mode mode)
Definition reloc-info.h:197
static constexpr int ModeMask(Mode mode)
Definition reloc-info.h:272
static V8_EXPORT_PRIVATE const Function * FunctionForId(FunctionId id)
Definition runtime.cc:350
static V8_EXPORT_PRIVATE DirectHandle< ScopeInfo > CreateForWithScope(Isolate *isolate, MaybeDirectHandle< ScopeInfo > outer_scope)
bool DeclaresLocals(Mode mode) const
Handle< JSObject > ScopeObject(Mode mode)
Handle< Context > CurrentContext() const
static constexpr bool IsCallRuntime(Bytecode bytecode)
Definition bytecodes.h:858
static const char * ToString(Bytecode bytecode)
Definition bytecodes.cc:123
#define INTRINSIC_ALLOWLIST(V)
#define INLINE_INTRINSIC_ALLOWLIST(V)
#define INLINE_CASE(Name)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:291
Isolate * isolate
TNode< Object > receiver
ZoneVector< RpoNumber > & result
LiftoffAssembler::CacheState state
constexpr int kNoSourcePosition
Definition globals.h:850
void PrintF(const char *format,...)
Definition utils.cc:39
Tagged(T object) -> Tagged< T >
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
void Print(Tagged< Object > obj)
Definition objects.h:774
@ NO_PARSE_RESTRICTION
Definition globals.h:1654
DirectHandle< JSObject > GetWasmDebugProxy(WasmFrame *frame)
V8_EXPORT_PRIVATE FlagValues v8_flags
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK(condition)
Definition logging.h:124
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define USE(...)
Definition macros.h:293