#include "src/builtins/builtins-utils-inl.h"
#include "src/builtins/builtins.h"
#include "src/codegen/code-factory.h"
#include "src/codegen/compiler.h"
#include "src/logging/counters.h"
#include "src/objects/objects-inl.h"
#include "src/strings/uri.h"
namespace v8 {
namespace internal {
BUILTIN(GlobalDecodeURI) {
HandleScope scope(isolate);
DirectHandle<String> encoded_uri;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, encoded_uri,
Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
RETURN_RESULT_OR_FAILURE(isolate, Uri::DecodeUri(isolate, encoded_uri));
}
BUILTIN(GlobalDecodeURIComponent) {
HandleScope scope(isolate);
DirectHandle<String> encoded_uri_component;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, encoded_uri_component,
Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
RETURN_RESULT_OR_FAILURE(
isolate, Uri::DecodeUriComponent(isolate, encoded_uri_component));
}
BUILTIN(GlobalEncodeURI) {
HandleScope scope(isolate);
DirectHandle<String> uri;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, uri, Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
RETURN_RESULT_OR_FAILURE(isolate, Uri::EncodeUri(isolate, uri));
}
BUILTIN(GlobalEncodeURIComponent) {
HandleScope scope(isolate);
DirectHandle<String> uri_component;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, uri_component,
Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
RETURN_RESULT_OR_FAILURE(isolate,
Uri::EncodeUriComponent(isolate, uri_component));
}
BUILTIN(GlobalEscape) {
HandleScope scope(isolate);
Handle<String> string;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, string,
Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
RETURN_RESULT_OR_FAILURE(isolate, Uri::Escape(isolate, string));
}
BUILTIN(GlobalUnescape) {
HandleScope scope(isolate);
Handle<String> string;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, string,
Object::ToString(isolate, args.atOrUndefined(isolate, 1)));
RETURN_RESULT_OR_FAILURE(isolate, Uri::Unescape(isolate, string));
}
BUILTIN(GlobalEval) {
HandleScope scope(isolate);
Handle<Object> x = args.atOrUndefined(isolate, 1);
DirectHandle<JSFunction> target = args.target();
DirectHandle<JSObject> target_global_proxy(target->global_proxy(), isolate);
if (!Builtins::AllowDynamicFunction(isolate, target, target_global_proxy)) {
isolate->CountUsage(v8::Isolate::kFunctionConstructorReturnedUndefined);
return ReadOnlyRoots(isolate).undefined_value();
}
MaybeDirectHandle<String> source;
bool unhandled_object;
std::tie(source, unhandled_object) =
Compiler::ValidateDynamicCompilationSource(
isolate, direct_handle(target->native_context(), isolate), x);
if (unhandled_object) return *x;
DirectHandle<JSFunction> function;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, function,
Compiler::GetFunctionFromValidatedString(
isolate, direct_handle(target->native_context(), isolate), source,
NO_PARSE_RESTRICTION, kNoSourcePosition));
RETURN_RESULT_OR_FAILURE(
isolate, Execution::Call(isolate, function, target_global_proxy, {}));
}
}
}