• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/ecma_string.h"
17 #include "ecmascript/ecma_vm.h"
18 #include "ecmascript/js_handle.h"
19 #include "ecmascript/js_hclass.h"
20 #include "ecmascript/js_object-inl.h"
21 #include "ecmascript/js_primitive_ref.h"
22 #include "ecmascript/js_tagged_value-inl.h"
23 #include "ecmascript/object_factory.h"
24 #include "ecmascript/object_operator.h"
25 #include "ecmascript/tests/test_helper.h"
26 
27 using namespace panda::ecmascript;
28 
29 namespace panda::test {
30 class JSPrimitiveRefTest : public BaseTestWithScope<false> {
31 };
32 
HWTEST_F_L0(JSPrimitiveRefTest,StringCreate)33 HWTEST_F_L0(JSPrimitiveRefTest, StringCreate)
34 {
35     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
36     JSHandle<JSTaggedValue> hello(thread->GetEcmaVM()->GetFactory()->NewFromASCII("hello"));
37     JSHandle<JSObject> str(JSPrimitiveRef::StringCreate(thread, hello, undefined));
38 
39     JSHandle<JSTaggedValue> idx(thread->GetEcmaVM()->GetFactory()->NewFromASCII("0"));
40     bool status = JSPrimitiveRef::HasProperty(thread, str, idx);
41     ASSERT_TRUE(status);
42 
43     PropertyDescriptor desc(thread);
44     status = JSPrimitiveRef::GetOwnProperty(thread, str, idx, desc);
45     ASSERT_TRUE(status);
46     JSHandle<EcmaString> h = thread->GetEcmaVM()->GetFactory()->NewFromASCII("h");
47     JSHandle<EcmaString> h2 = JSTaggedValue::ToString(thread, desc.GetValue());
48     ASSERT_TRUE(EcmaStringAccessor::Compare(instance, h, h2) == 0);
49 }
50 }  // namespace panda::test
51