v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-global.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
11#include "src/strings/uri.h"
12
13namespace v8 {
14namespace internal {
15
16// ES6 section 18.2.6.2 decodeURI (encodedURI)
17BUILTIN(GlobalDecodeURI) {
18 HandleScope scope(isolate);
19 DirectHandle<String> encoded_uri;
21 isolate, encoded_uri,
22 Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
23
24 RETURN_RESULT_OR_FAILURE(isolate, Uri::DecodeUri(isolate, encoded_uri));
25}
26
27// ES6 section 18.2.6.3 decodeURIComponent (encodedURIComponent)
28BUILTIN(GlobalDecodeURIComponent) {
29 HandleScope scope(isolate);
30 DirectHandle<String> encoded_uri_component;
32 isolate, encoded_uri_component,
33 Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
34
36 isolate, Uri::DecodeUriComponent(isolate, encoded_uri_component));
37}
38
39// ES6 section 18.2.6.4 encodeURI (uri)
40BUILTIN(GlobalEncodeURI) {
41 HandleScope scope(isolate);
44 isolate, uri, Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
45
46 RETURN_RESULT_OR_FAILURE(isolate, Uri::EncodeUri(isolate, uri));
47}
48
49// ES6 section 18.2.6.5 encodeURIComponent (uriComponent)
50BUILTIN(GlobalEncodeURIComponent) {
51 HandleScope scope(isolate);
52 DirectHandle<String> uri_component;
54 isolate, uri_component,
55 Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
56
58 Uri::EncodeUriComponent(isolate, uri_component));
59}
60
61// ES6 section B.2.1.1 escape (string)
62BUILTIN(GlobalEscape) {
63 HandleScope scope(isolate);
66 isolate, string,
67 Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
68
69 RETURN_RESULT_OR_FAILURE(isolate, Uri::Escape(isolate, string));
70}
71
72// ES6 section B.2.1.2 unescape (string)
73BUILTIN(GlobalUnescape) {
74 HandleScope scope(isolate);
77 isolate, string,
78 Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
79
80 RETURN_RESULT_OR_FAILURE(isolate, Uri::Unescape(isolate, string));
81}
82
83// ES6 section 18.2.1 eval (x)
84BUILTIN(GlobalEval) {
85 HandleScope scope(isolate);
86 Handle<Object> x = args.atOrUndefined(isolate, 1);
87 DirectHandle<JSFunction> target = args.target();
88 DirectHandle<JSObject> target_global_proxy(target->global_proxy(), isolate);
89 if (!Builtins::AllowDynamicFunction(isolate, target, target_global_proxy)) {
91 return ReadOnlyRoots(isolate).undefined_value();
92 }
93
94 // Run embedder pre-checks before executing eval. If the argument is a
95 // non-String (or other object the embedder doesn't know to handle), then
96 // return it directly.
98 bool unhandled_object;
99 std::tie(source, unhandled_object) =
101 isolate, direct_handle(target->native_context(), isolate), x);
102 if (unhandled_object) return *x;
103
106 isolate, function,
108 direct_handle(target->native_context(), isolate), source,
111 isolate, Execution::Call(isolate, function, target_global_proxy, {}));
112}
113
114} // namespace internal
115} // namespace v8
#define BUILTIN(name)
@ kFunctionConstructorReturnedUndefined
Definition v8-isolate.h:504
static bool AllowDynamicFunction(Isolate *isolate, DirectHandle< JSFunction > target, DirectHandle< JSObject > target_global_proxy)
Definition builtins.cc:534
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSFunction > GetFunctionFromValidatedString(DirectHandle< NativeContext > context, MaybeDirectHandle< String > source, ParseRestriction restriction, int parameters_end_pos)
Definition compiler.cc:3470
static V8_WARN_UNUSED_RESULT std::pair< MaybeDirectHandle< String >, bool > ValidateDynamicCompilationSource(Isolate *isolate, DirectHandle< NativeContext > context, Handle< i::Object > source_object, bool is_code_like=false)
Definition compiler.cc:3427
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
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
static MaybeDirectHandle< String > EncodeUriComponent(Isolate *isolate, DirectHandle< String > component)
Definition uri.h:35
static MaybeDirectHandle< String > Unescape(Isolate *isolate, Handle< String > string)
Definition uri.cc:514
static MaybeDirectHandle< String > DecodeUri(Isolate *isolate, DirectHandle< String > uri)
Definition uri.h:17
static MaybeDirectHandle< String > DecodeUriComponent(Isolate *isolate, DirectHandle< String > component)
Definition uri.h:23
static MaybeDirectHandle< String > Escape(Isolate *isolate, Handle< String > string)
Definition uri.cc:507
static MaybeDirectHandle< String > EncodeUri(Isolate *isolate, DirectHandle< String > uri)
Definition uri.h:29
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:284
#define RETURN_RESULT_OR_FAILURE(isolate, call)
Definition isolate.h:264
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
int x
InstructionOperand source
constexpr int kNoSourcePosition
Definition globals.h:850
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
@ NO_PARSE_RESTRICTION
Definition globals.h:1654
template const char * string