v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-reflect.cc
Go to the documentation of this file.
1// Copyright 2016 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
8#include "src/objects/keys.h"
12
13namespace v8 {
14namespace internal {
15
16// -----------------------------------------------------------------------------
17// ES6 section 26.1 The Reflect Object
18
19// ES6 section 26.1.3 Reflect.defineProperty
20BUILTIN(ReflectDefineProperty) {
21 HandleScope scope(isolate);
22 DCHECK_LE(4, args.length());
23 DirectHandle<Object> target = args.at(1);
25 Handle<JSAny> attributes = args.at<JSAny>(3);
26
27 if (!IsJSReceiver(*target)) {
29 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject,
30 isolate->factory()->NewStringFromAsciiChecked(
31 "Reflect.defineProperty")));
32 }
33
36 Object::ToName(isolate, key));
37
39 if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) {
40 return ReadOnlyRoots(isolate).exception();
41 }
42
44 isolate, Cast<JSReceiver>(target), name, &desc, Just(kDontThrow));
45 MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
46 return *isolate->factory()->ToBoolean(result.FromJust());
47}
48
49// ES6 section 26.1.11 Reflect.ownKeys
50BUILTIN(ReflectOwnKeys) {
51 HandleScope scope(isolate);
52 DCHECK_LE(2, args.length());
53 DirectHandle<Object> target = args.at(1);
54
55 if (!IsJSReceiver(*target)) {
57 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject,
58 isolate->factory()->NewStringFromAsciiChecked(
59 "Reflect.ownKeys")));
60 }
61
64 isolate, keys,
68 return *isolate->factory()->NewJSArrayWithElements(keys);
69}
70
71// ES6 section 26.1.13 Reflect.set
72BUILTIN(ReflectSet) {
73 HandleScope scope(isolate);
74 DirectHandle<Object> target = args.atOrUndefined(isolate, 1);
75 DirectHandle<Object> key = args.atOrUndefined(isolate, 2);
76 DirectHandle<Object> value = args.atOrUndefined(isolate, 3);
77
78 DirectHandle<JSReceiver> target_recv;
79 if (!TryCast<JSReceiver>(target, &target_recv)) {
81 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject,
82 isolate->factory()->NewStringFromAsciiChecked(
83 "Reflect.set")));
84 }
85
87 args.length() > 4 ? direct_handle(args.at<JSAny>(4)) : target_recv;
88
91 Object::ToName(isolate, key));
92
93 PropertyKey lookup_key(isolate, name);
94 LookupIterator it(isolate, receiver, lookup_key, target_recv);
97 MAYBE_RETURN(result, ReadOnlyRoots(isolate).exception());
98 return *isolate->factory()->ToBoolean(result.FromJust());
99}
100
101} // namespace internal
102} // namespace v8
#define BUILTIN(name)
static V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Object > key, PropertyDescriptor *desc, Maybe< ShouldThrow > should_throw)
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
static V8_WARN_UNUSED_RESULT Maybe< bool > SetSuperProperty(LookupIterator *it, DirectHandle< Object > value, StoreOrigin store_origin, Maybe< ShouldThrow > should_throw=Nothing< ShouldThrow >())
Definition objects.cc:2455
static V8_WARN_UNUSED_RESULT HandleType< Name >::MaybeType ToName(Isolate *isolate, HandleType< Object > input)
static bool ToPropertyDescriptor(Isolate *isolate, Handle< JSAny > obj, PropertyDescriptor *desc)
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:284
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
Definition isolate.h:294
#define MAYBE_RETURN(call, value)
Definition isolate.h:408
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
TNode< Object > receiver
ZoneVector< RpoNumber > & result
bool TryCast(Tagged< From > value, Tagged< To > *out)
Definition casting.h:77
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
Definition flags.cc:2086
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
Maybe< T > Just(const T &t)
Definition v8-maybe.h:117
#define DCHECK_LE(v1, v2)
Definition logging.h:490