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/* 17 * @tc.name:instanceofic 18 * @tc.desc:test instanceofic 19 * @tc.type: FUNC 20 * @tc.require: issueI5NO8G 21 */ 22 23class F { 24 static [Symbol.hasInstance](instance) { 25 return Array.isArray(instance); 26 } 27}; 28let res; 29 30for (let i = 300; i > 0; --i) { 31 res = [] instanceof F; 32 if (i == 150) { 33 if (res) { 34 print("instanceoficsuccess"); 35 } else { 36 print("instanceoficfailse"); 37 } 38 F[Symbol.hasInstance] = function() { return false }; 39 } 40 if (i == 140) { 41 if (!res) { 42 print("instanceoficsuccess"); 43 } else { 44 print("instanceoficfailse"); 45 } 46 } 47} 48 49let e = new Error("instanceof ic failed") 50for (let index = 0; index <= 30; index++) { 51 if ((e instanceof URIError) === true){ 52 continue 53 } 54} 55print("test success") 56 57for (let index = 0; index <= 30; index++) { 58 function foo() { 59 try { 60 const obj = {}; 61 obj instanceof {}; 62 } catch (e) { 63 64 } 65 } 66 foo(); 67} 68print("test success")