23MaybeDirectHandle<Object> CreateDynamicFunction(Isolate* isolate,
24 BuiltinArguments
args,
28 int const argc =
args.length() - 1;
30 DirectHandle<JSFunction> target =
args.target();
31 DirectHandle<JSObject> target_global_proxy(target->global_proxy(), isolate);
37 HandleScopeImplementer*
impl = isolate->handle_scope_implementer();
38 SaveAndSwitchContext save(isolate,
39 impl->LastEnteredContext()->native_context());
44 DirectHandle<String>
source;
47 IncrementalStringBuilder builder(isolate);
48 builder.AppendCharacter(
'(');
49 builder.AppendCString(token);
50 builder.AppendCStringLiteral(
" anonymous(");
52 for (
int i = 1;
i < argc; ++
i) {
53 if (
i > 1) builder.AppendCharacter(
',');
54 DirectHandle<String> param;
58 builder.AppendString(param);
61 builder.AppendCharacter(
'\n');
62 parameters_end_pos = builder.Length();
63 builder.AppendCStringLiteral(
") {\n");
65 DirectHandle<String> body;
68 builder.AppendString(body);
70 builder.AppendCStringLiteral(
"\n})");
74 bool is_code_like =
true;
75 for (
int i = 0;
i < argc; ++
i) {
84 DirectHandle<JSFunction> function;
92 DirectHandle<Object>
result;
97 function->shared()->set_name_should_print_as_anonymous(
true);
106 DirectHandle<Object> unchecked_new_target =
args.new_target();
107 if (!IsUndefined(*unchecked_new_target, isolate) &&
108 !unchecked_new_target.is_identical_to(target)) {
113 isolate, initial_map,
116 DirectHandle<SharedFunctionInfo> shared_info(function->shared(), isolate);
117 DirectHandle<Map> map =
120 DirectHandle<Context>
context(function->context(), isolate);
121 function = Factory::JSFunctionBuilder{
isolate, shared_info, context}
136 isolate,
result, CreateDynamicFunction(isolate,
args,
"function"));
144 CreateDynamicFunction(isolate,
args,
"function*"));
152 CreateDynamicFunction(isolate,
args,
"async function"));
153 if (!IsJSFunction(*maybe_func))
return *maybe_func;
170 CreateDynamicFunction(isolate,
args,
"async function*"));
171 if (!IsJSFunction(*maybe_func))
return *maybe_func;
185enum class ProtoSource {
191 ProtoSource proto_source) {
192 HandleScope scope(isolate);
194 if (!IsCallable(*
args.receiver())) {
196 isolate, NewTypeError(MessageTemplate::kFunctionBind));
200 DirectHandle<JSReceiver> target =
args.at<JSReceiver>(0);
201 DirectHandle<JSAny>
this_arg = isolate->factory()->undefined_value();
202 DirectHandleVector<Object> argv(isolate, std::max(0,
args.length() - 2));
203 if (
args.length() > 1) {
210 DirectHandle<JSPrototype> proto;
211 if (proto_source == ProtoSource::kUseTargetPrototype) {
215 }
else if (proto_source == ProtoSource::kNormalFunction) {
217 isolate->global_object()->native_context(), isolate);
224 DirectHandle<JSBoundFunction> function;
227 isolate->factory()->NewJSBoundFunction(
228 target,
this_arg, {argv.data(), argv.size()}, proto));
231 isolate, function, target, isolate->factory()->bound__string(),
232 static_cast<int>(argv.size()));
234 DCHECK(isolate->has_exception());
235 return ReadOnlyRoots(isolate).exception();
244 return DoFunctionBind(isolate,
args, ProtoSource::kUseTargetPrototype);
247#if V8_ENABLE_WEBASSEMBLY
248BUILTIN(WebAssemblyFunctionPrototypeBind) {
249 return DoFunctionBind(isolate,
args, ProtoSource::kNormalFunction);
270 isolate, NewTypeError(MessageTemplate::kNotGeneric,
271 isolate->factory()->NewStringFromAsciiChecked(
272 "Function.prototype.toString"),
273 isolate->factory()->Function_string()));
@ kFunctionConstructorReturnedUndefined
static bool AllowDynamicFunction(Isolate *isolate, DirectHandle< JSFunction > target, DirectHandle< JSObject > target_global_proxy)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSFunction > GetFunctionFromString(DirectHandle< NativeContext > context, Handle< i::Object > source, int parameters_end_pos, bool is_code_like)
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)
static DirectHandle< String > ToString(DirectHandle< JSBoundFunction > function)
static Maybe< bool > CopyNameAndLength(Isolate *isolate, DirectHandle< JSFunctionOrBoundFunctionOrWrappedFunction > function, DirectHandle< JSReceiver > target, DirectHandle< String > prefix, int arg_count)
static V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT MaybeHandle< Map > GetDerivedMap(Isolate *isolate, DirectHandle< JSFunction > constructor, DirectHandle< JSReceiver > new_target)
static DirectHandle< String > ToString(DirectHandle< JSFunction > function)
static MaybeDirectHandle< JSPrototype > GetPrototype(Isolate *isolate, DirectHandle< JSReceiver > receiver)
static DirectHandle< Map > AsLanguageMode(Isolate *isolate, DirectHandle< Map > initial_map, DirectHandle< SharedFunctionInfo > shared_info)
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
static bool IsCodeLike(Tagged< Object > obj, Isolate *isolate)
static int GetEvalPosition(Isolate *isolate, DirectHandle< Script > script)
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
#define THROW_NEW_ERROR(isolate, call)
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
#define RETURN_RESULT_OR_FAILURE(isolate, call)
base::Vector< const DirectHandle< Object > > args
DirectHandle< Object > new_target
ZoneVector< RpoNumber > & result
InstructionOperand source
Union< Smi, HeapNumber, BigInt, String, Symbol, Boolean, Null, Undefined, JSReceiver > JSAny
constexpr int kNoSourcePosition
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
kInterpreterTrampolineOffset script
!IsContextMap !IsContextMap native_context
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
auto impl(C *x) -> typename implement< C >::type *
#define DCHECK_LE(v1, v2)
#define DCHECK(condition)