1/** 2 * Copyright (c) 2021-2024 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 16export function deepEqual(x, y) { 17 // Approximate comparison for objects imported from ets, fails for some corner cases 18 if (x === y) { 19 return true; 20 } else if ((typeof x == "object" && x != null) && (typeof y == "object" && y != null)) { 21 if (Object.getPrototypeOf(x) !== Object.getPrototypeOf(y)) { 22 return false; 23 } 24 // Ets object fields are stored in prototype, but we cannot get them 25 // with Object.getPrototypeOf(x)[property] 26 for (let prop in x) { 27 if (Object.hasOwn(x, prop) != Object.hasOwn(y, prop)) { 28 return false; 29 } 30 if (!deepEqual(x[prop], y[prop])) { 31 return false; 32 } 33 } 34 // Check if y does not have properties not present in x 35 for (let prop in y) { 36 if (y[prop] !== undefined && x[prop] === undefined) { 37 return false; 38 } 39 } 40 return true; 41 } else { 42 return false; 43 } 44} 45 46function JsClass(value) { 47 this.int_value = value; 48} 49 50let const_obj = new JsClass(1); 51function create_obj() { 52 return new JsClass(1); 53} 54function create_null_obj() { 55 return null; 56} 57 58% @type_infos.each do |type_info| 59% fn_name = "js_get_#{type_info.name}" 60export let js_get_<%= type_info.name %> = function() { 61 return <%= type_info.value %>; 62} 63 64% end 65 66var saved_values = [undefined, undefined]; 67 68export let js_set = function(index, value) { 69 saved_values[index] = value; 70 return index; 71} 72 73export let js_check_set = function(index, value) { 74 return deepEqual(saved_values[0], saved_values[1]) ? 0 : 1; 75} 76