OLD | NEW |
(Empty) | |
| 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.h" |
| 6 #include "src/builtins/builtins-utils.h" |
| 7 |
| 8 #include "src/uri.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 |
| 13 // ES6 section 18.2.6.2 decodeURI (encodedURI) |
| 14 BUILTIN(GlobalDecodeURI) { |
| 15 HandleScope scope(isolate); |
| 16 Handle<String> encoded_uri; |
| 17 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 18 isolate, encoded_uri, |
| 19 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 20 |
| 21 RETURN_RESULT_OR_FAILURE(isolate, Uri::DecodeUri(isolate, encoded_uri)); |
| 22 } |
| 23 |
| 24 // ES6 section 18.2.6.3 decodeURIComponent (encodedURIComponent) |
| 25 BUILTIN(GlobalDecodeURIComponent) { |
| 26 HandleScope scope(isolate); |
| 27 Handle<String> encoded_uri_component; |
| 28 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 29 isolate, encoded_uri_component, |
| 30 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 31 |
| 32 RETURN_RESULT_OR_FAILURE( |
| 33 isolate, Uri::DecodeUriComponent(isolate, encoded_uri_component)); |
| 34 } |
| 35 |
| 36 // ES6 section 18.2.6.4 encodeURI (uri) |
| 37 BUILTIN(GlobalEncodeURI) { |
| 38 HandleScope scope(isolate); |
| 39 Handle<String> uri; |
| 40 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 41 isolate, uri, Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 42 |
| 43 RETURN_RESULT_OR_FAILURE(isolate, Uri::EncodeUri(isolate, uri)); |
| 44 } |
| 45 |
| 46 // ES6 section 18.2.6.5 encodeURIComponenet (uriComponent) |
| 47 BUILTIN(GlobalEncodeURIComponent) { |
| 48 HandleScope scope(isolate); |
| 49 Handle<String> uri_component; |
| 50 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 51 isolate, uri_component, |
| 52 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 53 |
| 54 RETURN_RESULT_OR_FAILURE(isolate, |
| 55 Uri::EncodeUriComponent(isolate, uri_component)); |
| 56 } |
| 57 |
| 58 // ES6 section B.2.1.1 escape (string) |
| 59 BUILTIN(GlobalEscape) { |
| 60 HandleScope scope(isolate); |
| 61 Handle<String> string; |
| 62 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 63 isolate, string, |
| 64 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 65 |
| 66 RETURN_RESULT_OR_FAILURE(isolate, Uri::Escape(isolate, string)); |
| 67 } |
| 68 |
| 69 // ES6 section B.2.1.2 unescape (string) |
| 70 BUILTIN(GlobalUnescape) { |
| 71 HandleScope scope(isolate); |
| 72 Handle<String> string; |
| 73 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 74 isolate, string, |
| 75 Object::ToString(isolate, args.atOrUndefined(isolate, 1))); |
| 76 |
| 77 RETURN_RESULT_OR_FAILURE(isolate, Uri::Unescape(isolate, string)); |
| 78 } |
| 79 |
| 80 // ES6 section 18.2.1 eval (x) |
| 81 BUILTIN(GlobalEval) { |
| 82 HandleScope scope(isolate); |
| 83 Handle<Object> x = args.atOrUndefined(isolate, 1); |
| 84 Handle<JSFunction> target = args.target<JSFunction>(); |
| 85 Handle<JSObject> target_global_proxy(target->global_proxy(), isolate); |
| 86 if (!x->IsString()) return *x; |
| 87 Handle<JSFunction> function; |
| 88 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 89 isolate, function, |
| 90 Builtins::CompileString(handle(target->native_context(), isolate), |
| 91 Handle<String>::cast(x), NO_PARSE_RESTRICTION)); |
| 92 RETURN_RESULT_OR_FAILURE( |
| 93 isolate, |
| 94 Execution::Call(isolate, function, target_global_proxy, 0, nullptr)); |
| 95 } |
| 96 |
| 97 } // namespace internal |
| 98 } // namespace v8 |
OLD | NEW |