• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2025 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
16const { getTestModule } = require('sealed_function.test.abc');
17
18const stsMod = getTestModule('sealed_function');
19
20const sumDouble = stsMod.getFunction('sum_double');
21const foo = stsMod.getFunction('foo');
22const arrow_func = stsMod.getFunction('arrow_func');
23
24function checkSealed() {
25    ASSERT_TRUE(Object.isSealed(sumDouble));
26    ASSERT_TRUE(Object.isSealed(foo));
27    ASSERT_TRUE(Object.isSealed(arrow_func));
28}
29
30function checkNewProperty() {
31    ASSERT_THROWS(TypeError, () => { foo.newProp = 3; });
32    ASSERT_THROWS(TypeError, () => { sumDouble.newProp = 3; });
33    ASSERT_THROWS(TypeError, () => { arrow_func.newProp = 3; });
34}
35
36function checkNewMethodDefineProperty() {
37    ASSERT_THROWS(TypeError, () => Object.defineProperty(foo, 'newMethod', {
38        value: () => 'defined method',
39        writable: true,
40        configurable: true
41    }));
42
43    ASSERT_THROWS(TypeError, () => Object.defineProperty(sumDouble, 'newMethod', {
44        value: () => 'defined method',
45        writable: true,
46        configurable: true
47    }));
48
49    ASSERT_THROWS(TypeError, () => Object.defineProperty(arrow_func, 'newMethod', {
50        value: () => 'defined method',
51        writable: true,
52        configurable: true
53    }));
54}
55
56checkSealed();
57checkNewProperty();
58checkNewMethodDefineProperty();
59