* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/js_arguments.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript {
bool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle<JSArguments> &args,
const JSHandle<JSTaggedValue> &key, PropertyDescriptor &desc)
{
JSObject::OrdinaryGetOwnProperty(thread, JSHandle<JSObject>(args), key, desc);
if (desc.IsEmpty()) {
return true;
}
JSHandle<EcmaString> caller = thread->GetEcmaVM()->GetFactory()->NewFromASCII("caller");
if (desc.IsDataDescriptor() && JSTaggedValue::SameValue(thread, key.GetTaggedValue(), caller.GetTaggedValue()) &&
desc.GetValue()->IsJSFunction()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "Arguments GetOwnProperty: type error", false);
}
return true;
}
bool JSArguments::DefineOwnProperty(JSThread *thread, const JSHandle<JSArguments> &args,
const JSHandle<JSTaggedValue> &key, const PropertyDescriptor &desc)
{
bool allowed = JSObject::OrdinaryDefineOwnProperty(thread, JSHandle<JSObject>(args), key, desc);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, allowed);
return true;
}
OperationResult JSArguments::GetProperty(JSThread *thread, const JSHandle<JSArguments> &args,
const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &receiver)
{
return JSTaggedValue::GetProperty(thread, JSHandle<JSTaggedValue>::Cast(args), key, receiver);
}
bool JSArguments::SetProperty(JSThread *thread, const JSHandle<JSArguments> &args, const JSHandle<JSTaggedValue> &key,
const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &receiver)
{
return JSTaggedValue::SetProperty(thread, JSHandle<JSTaggedValue>::Cast(args), key, value, receiver);
}
bool JSArguments::DeleteProperty(JSThread *thread, const JSHandle<JSArguments> &args,
const JSHandle<JSTaggedValue> &key)
{
bool result = JSTaggedValue::DeleteProperty(thread, JSHandle<JSTaggedValue>(args), key);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result);
return result;
}
}