mirror of
https://github.com/openharmony/ark_js_runtime.git
synced 2026-07-25 22:15:32 -04:00
4fb9fcc443
Description
1. There are many kinds of interfaces to construct ecmastring from objectfactory
in the virtual machine, and the name is not clear, so it is complex to use;
2. Some of the unchecked interfaces are prone to errors during use. If there is
no compression where compression is required, unpredictable errors will occur.
Issue:
#I4ZL7X: ObjectFactory New Ecmastring Rectification
Signed-off-by: xliu <liuxin259@huawei.com>
Change-Id: I856f4e2e1df62823d928d738fa35affa97dbd3ed
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 2021 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.
|
|
*/
|
|
|
|
#ifndef ECMASCRIPT_BASE_BUILTINS_BASE_H
|
|
#define ECMASCRIPT_BASE_BUILTINS_BASE_H
|
|
|
|
#include "ecmascript/base/string_helper.h"
|
|
#include "ecmascript/ecma_runtime_call_info.h"
|
|
#include "ecmascript/ecma_string.h"
|
|
#include "ecmascript/ecma_vm.h"
|
|
#include "ecmascript/global_env_constants-inl.h"
|
|
#include "ecmascript/js_symbol.h"
|
|
#include "ecmascript/js_tagged_value.h"
|
|
#include "ecmascript/object_factory.h"
|
|
#include "ecmascript/runtime_call_id.h"
|
|
#include "ecmascript/tagged_array.h"
|
|
|
|
namespace panda::ecmascript {
|
|
class JSArray;
|
|
namespace base {
|
|
class BuiltinsBase {
|
|
public:
|
|
enum ArgsPosition : uint32_t { FIRST = 0, SECOND, THIRD, FOURTH, FIFTH };
|
|
static JSHandle<TaggedArray> GetArgsArray(EcmaRuntimeCallInfo *msg);
|
|
static inline JSHandle<JSTaggedValue> GetConstructor(EcmaRuntimeCallInfo *msg)
|
|
{
|
|
return msg->GetFunction();
|
|
}
|
|
|
|
static inline JSHandle<JSTaggedValue> GetThis(EcmaRuntimeCallInfo *msg)
|
|
{
|
|
return msg->GetThis();
|
|
}
|
|
|
|
static inline JSHandle<JSTaggedValue> GetNewTarget(EcmaRuntimeCallInfo *msg)
|
|
{
|
|
return msg->GetNewTarget();
|
|
}
|
|
|
|
static inline JSHandle<JSTaggedValue> GetCallArg(EcmaRuntimeCallInfo *msg, uint32_t position)
|
|
{
|
|
if (position >= msg->GetArgsNumber()) {
|
|
JSThread *thread = msg->GetThread();
|
|
return thread->GlobalConstants()->GetHandledUndefined();
|
|
}
|
|
return msg->GetCallArg(position);
|
|
}
|
|
|
|
static inline JSTaggedValue GetTaggedInt(int32_t value)
|
|
{
|
|
return JSTaggedValue(value);
|
|
}
|
|
|
|
static inline JSTaggedValue GetTaggedDouble(double value)
|
|
{
|
|
return JSTaggedValue(value);
|
|
}
|
|
|
|
static inline JSTaggedValue GetTaggedBoolean(bool value)
|
|
{
|
|
return JSTaggedValue(value);
|
|
}
|
|
|
|
static inline JSTaggedValue GetTaggedString(JSThread *thread, const char *str)
|
|
{
|
|
return thread->GetEcmaVM()->GetFactory()->NewFromASCII(str).GetTaggedValue();
|
|
}
|
|
};
|
|
} // namespace base
|
|
} // namespace panda::ecmascript
|
|
|
|
#endif // ECMASCRIPT_BASE_BUILTINS_BASE_H
|