• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 */
15let a = [];
16Object.defineProperty(a, "length", {writable: false});
17function f() {
18  return a.pop();
19}
20try{
21    f();
22    assert_unreachable();
23} catch (e) {
24    assert_equal(e instanceof TypeError, true)
25}
26
27function f1() {
28    let x = [0,0,0,0,0];
29    Object.defineProperty(x, 'length', {value : 4, enumerable : true});
30}
31try{
32    f1();
33    assert_unreachable();
34} catch (e) {
35    assert_equal(e instanceof TypeError, true)
36}
37
38let array = [];
39Object.defineProperty(array, 'length', {writable: false});
40assert_equal(array.length, 0);
41try {
42    array.shift()
43    assert_unreachable();
44    assert_unreachable();
45} catch (e) {
46    assert_equal(e instanceof TypeError, true)
47}
48let object = { length: 0 };
49Object.defineProperty(object, 'length', {writable: false});
50assert_equal(object.length, 0);
51try {
52    Array.prototype.shift.call(object)
53    assert_unreachable();
54} catch {
55    var str = "true";
56    assert_equal(str, "true")
57}
58
59Object.defineProperty(this, 'x', {
60  configurable: true,
61  get: function () {return 100}
62});
63Object.defineProperty(this, 'x', {
64  value: 10
65});
66assert_equal(JSON.stringify(Object.getOwnPropertyDescriptor(this, 'x')), '{"value":10,"writable":false,"enumerable":false,"configurable":true}');
67
68const o1 = {
69  k: 1
70};
71for (let i = 0; i < 1100; i++) {
72  Object.defineProperty(o1, "k" + i, {
73    value: 0,
74    enumerable: false
75  });
76}
77assert_equal(JSON.stringify(o1), '{"k":1}')
78
79function fn() { };
80let v0 = function fn1() { }.bind(fn);
81Object.defineProperty(v0, "length", {
82  writable: true
83})
84v0.length = 42;
85assert_equal(v0.length, 42)
86
87test_end();