V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
builtins-global.cc
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 
5 #include "src/builtins/builtins-utils-inl.h"
6 #include "src/builtins/builtins.h"
7 #include "src/code-factory.h"
8 #include "src/compiler.h"
9 #include "src/counters.h"
10 #include "src/objects-inl.h"
11 #include "src/uri.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // ES6 section 18.2.6.2 decodeURI (encodedURI)
17 BUILTIN(GlobalDecodeURI) {
18  HandleScope scope(isolate);
19  Handle<String> encoded_uri;
20  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
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)
28 BUILTIN(GlobalDecodeURIComponent) {
29  HandleScope scope(isolate);
30  Handle<String> encoded_uri_component;
31  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
32  isolate, encoded_uri_component,
33  Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
34 
35  RETURN_RESULT_OR_FAILURE(
36  isolate, Uri::DecodeUriComponent(isolate, encoded_uri_component));
37 }
38 
39 // ES6 section 18.2.6.4 encodeURI (uri)
40 BUILTIN(GlobalEncodeURI) {
41  HandleScope scope(isolate);
42  Handle<String> uri;
43  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
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 encodeURIComponenet (uriComponent)
50 BUILTIN(GlobalEncodeURIComponent) {
51  HandleScope scope(isolate);
52  Handle<String> uri_component;
53  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
54  isolate, uri_component,
55  Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
56 
57  RETURN_RESULT_OR_FAILURE(isolate,
58  Uri::EncodeUriComponent(isolate, uri_component));
59 }
60 
61 // ES6 section B.2.1.1 escape (string)
62 BUILTIN(GlobalEscape) {
63  HandleScope scope(isolate);
64  Handle<String> string;
65  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
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)
73 BUILTIN(GlobalUnescape) {
74  HandleScope scope(isolate);
75  Handle<String> string;
76  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
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)
84 BUILTIN(GlobalEval) {
85  HandleScope scope(isolate);
86  Handle<Object> x = args.atOrUndefined(isolate, 1);
87  Handle<JSFunction> target = args.target();
88  Handle<JSObject> target_global_proxy(target->global_proxy(), isolate);
89  if (!x->IsString()) return *x;
90  if (!Builtins::AllowDynamicFunction(isolate, target, target_global_proxy)) {
91  isolate->CountUsage(v8::Isolate::kFunctionConstructorReturnedUndefined);
92  return ReadOnlyRoots(isolate).undefined_value();
93  }
94  Handle<JSFunction> function;
95  ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
96  isolate, function,
97  Compiler::GetFunctionFromString(handle(target->native_context(), isolate),
98  Handle<String>::cast(x),
99  NO_PARSE_RESTRICTION, kNoSourcePosition));
100  RETURN_RESULT_OR_FAILURE(
101  isolate,
102  Execution::Call(isolate, function, target_global_proxy, 0, nullptr));
103 }
104 
105 } // namespace internal
106 } // namespace v8
Definition: libplatform.h:13