|
110 | 110 | global.URL.revokeObjectURL = function () {}; |
111 | 111 | } |
112 | 112 |
|
| 113 | + // --- URLSearchParams の最小補完 ---------------------------------------- |
| 114 | + // V8 単体には URLSearchParams が存在しないため補完する。 |
| 115 | + // Next2D アプリがクエリ文字列 (?mode=0 等) を解析する際に使用する。 |
| 116 | + if (typeof global.URLSearchParams === "undefined") { |
| 117 | + global.URLSearchParams = class URLSearchParams { |
| 118 | + constructor(init) { |
| 119 | + this._list = []; |
| 120 | + if (typeof init === "string") { |
| 121 | + let query = init; |
| 122 | + if (query.charAt(0) === "?") { |
| 123 | + query = query.slice(1); |
| 124 | + } |
| 125 | + if (query.length) { |
| 126 | + const pairs = query.split("&"); |
| 127 | + for (let i = 0; i < pairs.length; i++) { |
| 128 | + const pair = pairs[i]; |
| 129 | + if (!pair) { |
| 130 | + continue; |
| 131 | + } |
| 132 | + const index = pair.indexOf("="); |
| 133 | + const decode = (value) => { |
| 134 | + try { |
| 135 | + return decodeURIComponent(value.replace(/\+/g, " ")); |
| 136 | + } catch { |
| 137 | + return value; |
| 138 | + } |
| 139 | + }; |
| 140 | + if (index === -1) { |
| 141 | + this._list.push([decode(pair), ""]); |
| 142 | + } else { |
| 143 | + this._list.push([decode(pair.slice(0, index)), decode(pair.slice(index + 1))]); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + } else if (init && typeof init === "object") { |
| 148 | + if (Array.isArray(init)) { |
| 149 | + for (let i = 0; i < init.length; i++) { |
| 150 | + this._list.push([String(init[i][0]), String(init[i][1])]); |
| 151 | + } |
| 152 | + } else if (typeof init.forEach === "function") { |
| 153 | + init.forEach((value, key) => this._list.push([String(key), String(value)])); |
| 154 | + } else { |
| 155 | + for (const key in init) { |
| 156 | + if (Object.prototype.hasOwnProperty.call(init, key)) { |
| 157 | + this._list.push([key, String(init[key])]); |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + get(name) { |
| 164 | + for (let i = 0; i < this._list.length; i++) { |
| 165 | + if (this._list[i][0] === name) { |
| 166 | + return this._list[i][1]; |
| 167 | + } |
| 168 | + } |
| 169 | + return null; |
| 170 | + } |
| 171 | + getAll(name) { |
| 172 | + const result = []; |
| 173 | + for (let i = 0; i < this._list.length; i++) { |
| 174 | + if (this._list[i][0] === name) { |
| 175 | + result.push(this._list[i][1]); |
| 176 | + } |
| 177 | + } |
| 178 | + return result; |
| 179 | + } |
| 180 | + has(name) { |
| 181 | + return this.get(name) !== null; |
| 182 | + } |
| 183 | + set(name, value) { |
| 184 | + const text = String(value); |
| 185 | + let done = false; |
| 186 | + const next = []; |
| 187 | + for (let i = 0; i < this._list.length; i++) { |
| 188 | + if (this._list[i][0] === name) { |
| 189 | + if (!done) { |
| 190 | + next.push([name, text]); |
| 191 | + done = true; |
| 192 | + } |
| 193 | + } else { |
| 194 | + next.push(this._list[i]); |
| 195 | + } |
| 196 | + } |
| 197 | + if (!done) { |
| 198 | + next.push([name, text]); |
| 199 | + } |
| 200 | + this._list = next; |
| 201 | + } |
| 202 | + append(name, value) { |
| 203 | + this._list.push([String(name), String(value)]); |
| 204 | + } |
| 205 | + delete(name) { |
| 206 | + this._list = this._list.filter((pair) => pair[0] !== name); |
| 207 | + } |
| 208 | + forEach(callback, thisArg) { |
| 209 | + for (let i = 0; i < this._list.length; i++) { |
| 210 | + callback.call(thisArg, this._list[i][1], this._list[i][0], this); |
| 211 | + } |
| 212 | + } |
| 213 | + keys() { |
| 214 | + return this._list.map((pair) => pair[0])[Symbol.iterator](); |
| 215 | + } |
| 216 | + values() { |
| 217 | + return this._list.map((pair) => pair[1])[Symbol.iterator](); |
| 218 | + } |
| 219 | + entries() { |
| 220 | + return this._list.map((pair) => [pair[0], pair[1]])[Symbol.iterator](); |
| 221 | + } |
| 222 | + toString() { |
| 223 | + return this._list |
| 224 | + .map((pair) => encodeURIComponent(pair[0]) + "=" + encodeURIComponent(pair[1])) |
| 225 | + .join("&"); |
| 226 | + } |
| 227 | + [Symbol.iterator]() { |
| 228 | + return this.entries(); |
| 229 | + } |
| 230 | + }; |
| 231 | + } |
| 232 | + |
113 | 233 | // --- location (Next2D が参照する場合の最小値) --------------------------- |
114 | 234 | if (typeof global.location === "undefined") { |
115 | 235 | global.location = { |
|
0 commit comments