|
| 1 | +// Copyright JS Foundation and other contributors, http://js.foundation |
| 2 | +// |
| 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 | +var recursion_counter = 0; |
| 16 | +var recursion_limit = 1000; |
| 17 | +var fz_globalObject = this |
| 18 | + |
| 19 | +function fz_is_primitive(value) { |
| 20 | + var value_type = typeof value |
| 21 | + if (value_type !== "function" && value_type !== "object") |
| 22 | + return value_type |
| 23 | +} |
| 24 | + |
| 25 | +function fz_starts_with(str, pattern) { |
| 26 | + for (var i = 0; i < pattern.length; i++) |
| 27 | + if (str[i] !== pattern[i]) |
| 28 | + return |
| 29 | + return true |
| 30 | +} |
| 31 | + |
| 32 | +function fz_collect_values(value) { |
| 33 | + if (++recursion_counter >= recursion_limit) { |
| 34 | + return |
| 35 | + } |
| 36 | + |
| 37 | + var primitive = fz_is_primitive(value) |
| 38 | + if (primitive) |
| 39 | + return |
| 40 | + var prop_names = Object.getOwnPropertyNames(value) |
| 41 | + for (var i = 0; i < prop_names.length; i++) { |
| 42 | + var prop_name = prop_names[i] |
| 43 | + if (!fz_starts_with(prop_name, "fz_")) { |
| 44 | + fz_collect_values(value[prop_name]) |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +fz_collect_values(fz_globalObject) |
0 commit comments