// Copyright 2014 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/v8.h" #include "src/accessors.h" #include "src/arguments.h" #include "src/compiler.h" #include "src/deoptimizer.h" #include "src/frames.h" #include "src/runtime/runtime-utils.h" namespace v8 { namespace internal { RUNTIME_FUNCTION(Runtime_IsSloppyModeFunction) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSReceiver, callable, 0); if (!callable->IsJSFunction()) { HandleScope scope(isolate); Handle delegate; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, delegate, Execution::TryGetFunctionDelegate( isolate, Handle(callable))); callable = JSFunction::cast(*delegate); } JSFunction* function = JSFunction::cast(callable); SharedFunctionInfo* shared = function->shared(); return isolate->heap()->ToBoolean(shared->strict_mode() == SLOPPY); } RUNTIME_FUNCTION(Runtime_GetDefaultReceiver) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSReceiver, callable, 0); if (!callable->IsJSFunction()) { HandleScope scope(isolate); Handle delegate; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, delegate, Execution::TryGetFunctionDelegate( isolate, Handle(callable))); callable = JSFunction::cast(*delegate); } JSFunction* function = JSFunction::cast(callable); SharedFunctionInfo* shared = function->shared(); if (shared->native() || shared->strict_mode() == STRICT) { return isolate->heap()->undefined_value(); } // Returns undefined for strict or native functions, or // the associated global receiver for "normal" functions. return function->global_proxy(); } RUNTIME_FUNCTION(Runtime_FunctionGetName) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, f, 0); return f->shared()->name(); } static Handle NameToFunctionName(Handle name) { Handle stringName(name->GetHeap()->empty_string()); // TODO(caitp): Follow proper rules in section 9.2.11 (SetFunctionName) if (name->IsSymbol()) { Handle description(Handle::cast(name)->name(), name->GetIsolate()); if (description->IsString()) { stringName = Handle::cast(description); } } else { stringName = Handle::cast(name); } return stringName; } RUNTIME_FUNCTION(Runtime_FunctionSetName) { HandleScope scope(isolate); DCHECK(args.length() == 2); CONVERT_ARG_HANDLE_CHECKED(JSFunction, f, 0); CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); f->shared()->set_name(*NameToFunctionName(name)); return isolate->heap()->undefined_value(); } RUNTIME_FUNCTION(Runtime_FunctionNameShouldPrintAsAnonymous) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, f, 0); return isolate->heap()->ToBoolean( f->shared()->name_should_print_as_anonymous()); } RUNTIME_FUNCTION(Runtime_FunctionMarkNameShouldPrintAsAnonymous) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, f, 0); f->shared()->set_name_should_print_as_anonymous(true); return isolate->heap()->undefined_value(); } RUNTIME_FUNCTION(Runtime_FunctionIsArrow) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, f, 0); return isolate->heap()->ToBoolean(f->shared()->is_arrow()); } RUNTIME_FUNCTION(Runtime_FunctionIsConciseMethod) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, f, 0); return isolate->heap()->ToBoolean(f->shared()->is_concise_method()); } RUNTIME_FUNCTION(Runtime_FunctionRemovePrototype) { SealHandleScope shs(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, f, 0); RUNTIME_ASSERT(f->RemovePrototype()); return isolate->heap()->undefined_value(); } RUNTIME_FUNCTION(Runtime_FunctionGetScript) { HandleScope scope(isolate); DCHECK(args.length() == 1); CONVERT_ARG_CHECKED(JSFunction, fun, 0); Handle script = Handle(fun->shared()->script(), isolate); if (!script->IsScript()) return isolate->heap()->undefined_value(); return *Script::GetWrapper(Handle