1/* 2 * Copyright (c) 2022 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 16import { paramMock } from "../utils" 17 18export function mockStack() { 19 const paramStack = { 20 paramAnyMock: '[PC Preview] unknow any', 21 paramIterMock: '[PC Preview] unknow IterableIterator' 22 } 23 const StackClass = class Stack { 24 constructor(...args) { 25 console.warn('util.Stack interface mocked in the Previewer. How this interface works on the Previewer' + 26 ' may be different from that on a real device.'); 27 this.length = '[PC preview] unknow length'; 28 this.isEmpty = function (...args) { 29 console.warn("Stack.isEmpty interface mocked in the Previewer. How this interface works on the Previewer" + 30 " may be different from that on a real device.") 31 return paramMock.paramBooleanMock; 32 }; 33 this.peek = function (...args) { 34 console.warn("Stack.peek interface mocked in the Previewer. How this interface works on the Previewer" + 35 " may be different from that on a real device.") 36 return paramStack.paramAnyMock; 37 }; 38 this.pop = function (...args) { 39 console.warn("Stack.pop interface mocked in the Previewer. How this interface works on the Previewer" + 40 " may be different from that on a real device.") 41 return paramStack.paramAnyMock; 42 }; 43 this.push = function (...args) { 44 console.warn("Stack.push interface mocked in the Previewer. How this interface works on the Previewer" + 45 " may be different from that on a real device.") 46 return paramStack.paramAnyMock; 47 }; 48 this.locate = function (...args) { 49 console.warn("Stack.locate interface mocked in the Previewer. How this interface works on the Previewer" + 50 " may be different from that on a real device.") 51 return paramMock.paramNumberMock; 52 }; 53 this.forEach = function (...args) { 54 console.warn("Stack.forEach interface mocked in the Previewer. How this interface works on the Previewer" + 55 " may be different from that on a real device.") 56 if (typeof args[0] === 'function') { 57 args[0].call(this, paramMock.businessErrorMock) 58 } 59 }; 60 this[Symbol.iterator] = function (...args) { 61 console.warn("Stack.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 62 " may be different from that on a real device.") 63 let index = 0; 64 const IteratorMock = { 65 next: () => { 66 if (index < 1) { 67 index++; 68 return { 69 value: paramStack.paramAnyMock, 70 done: false 71 }; 72 } else { 73 return { 74 done: true 75 }; 76 } 77 } 78 }; 79 return IteratorMock; 80 } 81 } 82 } 83 return StackClass; 84}