quickjs 0.11.2 → 0.13.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CLAUDE.md +62 -0
- data/README.md +7 -1
- data/Rakefile +61 -2
- data/ext/quickjsrb/extconf.rb +11 -0
- data/ext/quickjsrb/quickjsrb.c +128 -6
- data/ext/quickjsrb/quickjsrb.h +35 -31
- data/ext/quickjsrb/quickjsrb_file.c +332 -0
- data/ext/quickjsrb/quickjsrb_file.h +16 -0
- data/ext/quickjsrb/vendor/polyfill-encoding.min.js +1 -0
- data/ext/quickjsrb/vendor/polyfill-file.min.js +1 -0
- data/ext/quickjsrb/vendor/polyfill-intl-en.min.js +10 -9
- data/lib/quickjs/version.rb +1 -1
- data/lib/quickjs.rb +8 -0
- data/polyfills/package-lock.json +465 -0
- data/polyfills/package.json +18 -0
- data/polyfills/rolldown.config.mjs +28 -0
- data/polyfills/src/encoding.js +231 -0
- data/polyfills/src/file.js +218 -0
- data/polyfills/src/intl-en.js +15 -0
- data/sig/quickjs.rbs +69 -1
- metadata +12 -1
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
#include "quickjsrb.h"
|
|
2
|
+
#include "quickjsrb_file.h"
|
|
3
|
+
|
|
4
|
+
static VALUE r_find_alive_rb_file(JSContext *ctx, JSValue j_handle)
|
|
5
|
+
{
|
|
6
|
+
int64_t handle;
|
|
7
|
+
JS_ToInt64(ctx, &handle, j_handle);
|
|
8
|
+
VMData *data = JS_GetContextOpaque(ctx);
|
|
9
|
+
return rb_hash_aref(data->alive_objects, LONG2NUM(handle));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static JSValue js_ruby_file_name(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
13
|
+
{
|
|
14
|
+
VALUE r_file = r_find_alive_rb_file(ctx, argv[0]);
|
|
15
|
+
if (NIL_P(r_file))
|
|
16
|
+
return JS_UNDEFINED;
|
|
17
|
+
|
|
18
|
+
VALUE r_path = rb_funcall(r_file, rb_intern("path"), 0);
|
|
19
|
+
VALUE r_basename = rb_funcall(rb_cFile, rb_intern("basename"), 1, r_path);
|
|
20
|
+
return JS_NewString(ctx, StringValueCStr(r_basename));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static JSValue js_ruby_file_size(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
24
|
+
{
|
|
25
|
+
VALUE r_file = r_find_alive_rb_file(ctx, argv[0]);
|
|
26
|
+
if (NIL_P(r_file))
|
|
27
|
+
return JS_UNDEFINED;
|
|
28
|
+
|
|
29
|
+
VALUE r_size = rb_funcall(r_file, rb_intern("size"), 0);
|
|
30
|
+
return JS_NewInt64(ctx, NUM2LONG(r_size));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static JSValue js_ruby_file_type(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
34
|
+
{
|
|
35
|
+
return JS_NewString(ctx, "");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static JSValue js_ruby_file_last_modified(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
39
|
+
{
|
|
40
|
+
VALUE r_file = r_find_alive_rb_file(ctx, argv[0]);
|
|
41
|
+
if (NIL_P(r_file))
|
|
42
|
+
return JS_UNDEFINED;
|
|
43
|
+
|
|
44
|
+
VALUE r_mtime = rb_funcall(r_file, rb_intern("mtime"), 0);
|
|
45
|
+
VALUE r_epoch_f = rb_funcall(r_mtime, rb_intern("to_f"), 0);
|
|
46
|
+
double epoch_ms = NUM2DBL(r_epoch_f) * 1000.0;
|
|
47
|
+
return JS_NewFloat64(ctx, epoch_ms);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static JSValue js_ruby_file_text(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
51
|
+
{
|
|
52
|
+
VALUE r_file = r_find_alive_rb_file(ctx, argv[0]);
|
|
53
|
+
if (NIL_P(r_file))
|
|
54
|
+
return JS_UNDEFINED;
|
|
55
|
+
|
|
56
|
+
JSValue promise, resolving_funcs[2];
|
|
57
|
+
promise = JS_NewPromiseCapability(ctx, resolving_funcs);
|
|
58
|
+
if (JS_IsException(promise))
|
|
59
|
+
return JS_EXCEPTION;
|
|
60
|
+
|
|
61
|
+
rb_funcall(r_file, rb_intern("rewind"), 0);
|
|
62
|
+
VALUE r_content = rb_funcall(r_file, rb_intern("read"), 0);
|
|
63
|
+
JSValue j_content = JS_NewString(ctx, StringValueCStr(r_content));
|
|
64
|
+
|
|
65
|
+
JSValue ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED, 1, &j_content);
|
|
66
|
+
JS_FreeValue(ctx, j_content);
|
|
67
|
+
JS_FreeValue(ctx, ret);
|
|
68
|
+
JS_FreeValue(ctx, resolving_funcs[0]);
|
|
69
|
+
JS_FreeValue(ctx, resolving_funcs[1]);
|
|
70
|
+
|
|
71
|
+
return promise;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static JSValue js_ruby_file_array_buffer(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
75
|
+
{
|
|
76
|
+
VALUE r_file = r_find_alive_rb_file(ctx, argv[0]);
|
|
77
|
+
if (NIL_P(r_file))
|
|
78
|
+
return JS_UNDEFINED;
|
|
79
|
+
|
|
80
|
+
JSValue promise, resolving_funcs[2];
|
|
81
|
+
promise = JS_NewPromiseCapability(ctx, resolving_funcs);
|
|
82
|
+
if (JS_IsException(promise))
|
|
83
|
+
return JS_EXCEPTION;
|
|
84
|
+
|
|
85
|
+
rb_funcall(r_file, rb_intern("rewind"), 0);
|
|
86
|
+
VALUE r_content = rb_funcall(r_file, rb_intern("read"), 0);
|
|
87
|
+
rb_funcall(r_content, rb_intern("force_encoding"), 1, rb_str_new_cstr("BINARY"));
|
|
88
|
+
long len = RSTRING_LEN(r_content);
|
|
89
|
+
const char *ptr = RSTRING_PTR(r_content);
|
|
90
|
+
|
|
91
|
+
JSValue j_buf = JS_NewArrayBufferCopy(ctx, (const uint8_t *)ptr, len);
|
|
92
|
+
|
|
93
|
+
JSValue ret = JS_Call(ctx, resolving_funcs[0], JS_UNDEFINED, 1, &j_buf);
|
|
94
|
+
JS_FreeValue(ctx, j_buf);
|
|
95
|
+
JS_FreeValue(ctx, ret);
|
|
96
|
+
JS_FreeValue(ctx, resolving_funcs[0]);
|
|
97
|
+
JS_FreeValue(ctx, resolving_funcs[1]);
|
|
98
|
+
|
|
99
|
+
return promise;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static JSValue js_ruby_file_slice(JSContext *ctx, JSValueConst _this, int argc, JSValueConst *argv)
|
|
103
|
+
{
|
|
104
|
+
VALUE r_file = r_find_alive_rb_file(ctx, argv[0]);
|
|
105
|
+
if (NIL_P(r_file))
|
|
106
|
+
return JS_UNDEFINED;
|
|
107
|
+
|
|
108
|
+
VALUE r_size = rb_funcall(r_file, rb_intern("size"), 0);
|
|
109
|
+
long file_size = NUM2LONG(r_size);
|
|
110
|
+
|
|
111
|
+
long start = 0;
|
|
112
|
+
if (argc > 1 && !JS_IsUndefined(argv[1]))
|
|
113
|
+
{
|
|
114
|
+
int64_t s;
|
|
115
|
+
JS_ToInt64(ctx, &s, argv[1]);
|
|
116
|
+
start = (long)s;
|
|
117
|
+
if (start < 0)
|
|
118
|
+
start = file_size + start;
|
|
119
|
+
if (start < 0)
|
|
120
|
+
start = 0;
|
|
121
|
+
if (start > file_size)
|
|
122
|
+
start = file_size;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
long end = file_size;
|
|
126
|
+
if (argc > 2 && !JS_IsUndefined(argv[2]))
|
|
127
|
+
{
|
|
128
|
+
int64_t e;
|
|
129
|
+
JS_ToInt64(ctx, &e, argv[2]);
|
|
130
|
+
end = (long)e;
|
|
131
|
+
if (end < 0)
|
|
132
|
+
end = file_size + end;
|
|
133
|
+
if (end < 0)
|
|
134
|
+
end = 0;
|
|
135
|
+
if (end > file_size)
|
|
136
|
+
end = file_size;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const char *content_type = "";
|
|
140
|
+
if (argc > 3 && JS_IsString(argv[3]))
|
|
141
|
+
content_type = JS_ToCString(ctx, argv[3]);
|
|
142
|
+
|
|
143
|
+
long len = end > start ? end - start : 0;
|
|
144
|
+
|
|
145
|
+
rb_funcall(r_file, rb_intern("rewind"), 0);
|
|
146
|
+
if (start > 0)
|
|
147
|
+
rb_funcall(r_file, rb_intern("seek"), 1, LONG2NUM(start));
|
|
148
|
+
VALUE r_bytes = rb_funcall(r_file, rb_intern("read"), 1, LONG2NUM(len));
|
|
149
|
+
rb_funcall(r_bytes, rb_intern("force_encoding"), 1, rb_str_new_cstr("BINARY"));
|
|
150
|
+
|
|
151
|
+
JSValue j_buf = JS_NewArrayBufferCopy(ctx, (const uint8_t *)RSTRING_PTR(r_bytes), RSTRING_LEN(r_bytes));
|
|
152
|
+
JSValue j_global = JS_GetGlobalObject(ctx);
|
|
153
|
+
JSValue j_uint8_ctor = JS_GetPropertyStr(ctx, j_global, "Uint8Array");
|
|
154
|
+
JSValue j_uint8 = JS_CallConstructor(ctx, j_uint8_ctor, 1, &j_buf);
|
|
155
|
+
|
|
156
|
+
JSValue j_parts = JS_NewArray(ctx);
|
|
157
|
+
JS_SetPropertyUint32(ctx, j_parts, 0, j_uint8);
|
|
158
|
+
|
|
159
|
+
JSValue j_opts = JS_NewObject(ctx);
|
|
160
|
+
JS_SetPropertyStr(ctx, j_opts, "type", JS_NewString(ctx, content_type));
|
|
161
|
+
|
|
162
|
+
JSValue j_blob_ctor = JS_GetPropertyStr(ctx, j_global, "Blob");
|
|
163
|
+
JSValueConst blob_args[2] = {j_parts, j_opts};
|
|
164
|
+
JSValue j_blob = JS_CallConstructor(ctx, j_blob_ctor, 2, blob_args);
|
|
165
|
+
|
|
166
|
+
if (argc > 3 && JS_IsString(argv[3]))
|
|
167
|
+
JS_FreeCString(ctx, content_type);
|
|
168
|
+
|
|
169
|
+
JS_FreeValue(ctx, j_buf);
|
|
170
|
+
JS_FreeValue(ctx, j_uint8_ctor);
|
|
171
|
+
JS_FreeValue(ctx, j_parts);
|
|
172
|
+
JS_FreeValue(ctx, j_opts);
|
|
173
|
+
JS_FreeValue(ctx, j_blob_ctor);
|
|
174
|
+
JS_FreeValue(ctx, j_global);
|
|
175
|
+
|
|
176
|
+
return j_blob;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void quickjsrb_init_file_proxy(VMData *data)
|
|
180
|
+
{
|
|
181
|
+
const char *factory_src =
|
|
182
|
+
"(function(getName, getSize, getType, getLastModified, getText, getArrayBuffer, getSlice) {\n"
|
|
183
|
+
" return function(handle) {\n"
|
|
184
|
+
" var target = Object.create(File.prototype);\n"
|
|
185
|
+
" Object.defineProperty(target, 'rb_object_id', { value: handle, enumerable: false });\n"
|
|
186
|
+
" return new Proxy(target, {\n"
|
|
187
|
+
" getPrototypeOf: function() { return File.prototype; },\n"
|
|
188
|
+
" get: function(target, prop, receiver) {\n"
|
|
189
|
+
" if (prop === 'name') return getName(handle);\n"
|
|
190
|
+
" if (prop === 'size') return getSize(handle);\n"
|
|
191
|
+
" if (prop === 'type') return getType(handle);\n"
|
|
192
|
+
" if (prop === 'lastModified') return getLastModified(handle);\n"
|
|
193
|
+
" if (prop === 'text') return function() { return getText(handle); };\n"
|
|
194
|
+
" if (prop === 'arrayBuffer') return function() { return getArrayBuffer(handle); };\n"
|
|
195
|
+
" if (prop === 'slice') return function(start, end, contentType) { return getSlice(handle, start, end, contentType); };\n"
|
|
196
|
+
" if (prop === Symbol.toStringTag) return 'File';\n"
|
|
197
|
+
" if (prop === 'toString') return function() { return '[object File]'; };\n"
|
|
198
|
+
" return Reflect.get(target, prop, receiver);\n"
|
|
199
|
+
" }\n"
|
|
200
|
+
" });\n"
|
|
201
|
+
" };\n"
|
|
202
|
+
"})";
|
|
203
|
+
JSValue j_factory_fn = JS_Eval(data->context, factory_src, strlen(factory_src), "<file-proxy>", JS_EVAL_TYPE_GLOBAL);
|
|
204
|
+
|
|
205
|
+
JSValue j_helpers[7];
|
|
206
|
+
j_helpers[0] = JS_NewCFunction(data->context, js_ruby_file_name, "__rb_file_name", 1);
|
|
207
|
+
j_helpers[1] = JS_NewCFunction(data->context, js_ruby_file_size, "__rb_file_size", 1);
|
|
208
|
+
j_helpers[2] = JS_NewCFunction(data->context, js_ruby_file_type, "__rb_file_type", 1);
|
|
209
|
+
j_helpers[3] = JS_NewCFunction(data->context, js_ruby_file_last_modified, "__rb_file_last_modified", 1);
|
|
210
|
+
j_helpers[4] = JS_NewCFunction(data->context, js_ruby_file_text, "__rb_file_text", 1);
|
|
211
|
+
j_helpers[5] = JS_NewCFunction(data->context, js_ruby_file_array_buffer, "__rb_file_array_buffer", 1);
|
|
212
|
+
j_helpers[6] = JS_NewCFunction(data->context, js_ruby_file_slice, "__rb_file_slice", 4);
|
|
213
|
+
|
|
214
|
+
data->j_file_proxy_creator = JS_Call(data->context, j_factory_fn, JS_UNDEFINED, 7, j_helpers);
|
|
215
|
+
|
|
216
|
+
JS_FreeValue(data->context, j_factory_fn);
|
|
217
|
+
for (int i = 0; i < 7; i++)
|
|
218
|
+
JS_FreeValue(data->context, j_helpers[i]);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
JSValue quickjsrb_file_to_js(JSContext *ctx, VALUE r_file)
|
|
222
|
+
{
|
|
223
|
+
VMData *data = JS_GetContextOpaque(ctx);
|
|
224
|
+
VALUE r_object_id = rb_funcall(r_file, rb_intern("object_id"), 0);
|
|
225
|
+
rb_hash_aset(data->alive_objects, r_object_id, r_file);
|
|
226
|
+
JSValue j_handle = JS_NewInt64(ctx, NUM2LONG(r_object_id));
|
|
227
|
+
JSValue j_proxy = JS_Call(ctx, data->j_file_proxy_creator, JS_UNDEFINED, 1, &j_handle);
|
|
228
|
+
JS_FreeValue(ctx, j_handle);
|
|
229
|
+
return j_proxy;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static VALUE r_extract_blob_content(JSContext *ctx, JSValue j_val)
|
|
233
|
+
{
|
|
234
|
+
JSValue j_ab_fn = JS_GetPropertyStr(ctx, j_val, "arrayBuffer");
|
|
235
|
+
JSValue j_promise = JS_Call(ctx, j_ab_fn, j_val, 0, NULL);
|
|
236
|
+
JS_FreeValue(ctx, j_ab_fn);
|
|
237
|
+
|
|
238
|
+
JSContext *ctx2;
|
|
239
|
+
while (JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx2) > 0)
|
|
240
|
+
{
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
VALUE r_content = rb_str_new("", 0);
|
|
244
|
+
if (JS_PromiseState(ctx, j_promise) == JS_PROMISE_FULFILLED)
|
|
245
|
+
{
|
|
246
|
+
JSValue j_result = JS_PromiseResult(ctx, j_promise);
|
|
247
|
+
size_t buf_len;
|
|
248
|
+
uint8_t *buf = JS_GetArrayBuffer(ctx, &buf_len, j_result);
|
|
249
|
+
if (buf)
|
|
250
|
+
r_content = rb_str_new((const char *)buf, buf_len);
|
|
251
|
+
JS_FreeValue(ctx, j_result);
|
|
252
|
+
}
|
|
253
|
+
JS_FreeValue(ctx, j_promise);
|
|
254
|
+
|
|
255
|
+
rb_funcall(r_content, rb_intern("force_encoding"), 1, rb_str_new_cstr("BINARY"));
|
|
256
|
+
return r_content;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static void r_populate_blob_attrs(JSContext *ctx, JSValue j_val, VALUE r_obj)
|
|
260
|
+
{
|
|
261
|
+
JSValue j_size = JS_GetPropertyStr(ctx, j_val, "size");
|
|
262
|
+
int64_t size_val;
|
|
263
|
+
JS_ToInt64(ctx, &size_val, j_size);
|
|
264
|
+
rb_iv_set(r_obj, "@size", LONG2NUM(size_val));
|
|
265
|
+
JS_FreeValue(ctx, j_size);
|
|
266
|
+
|
|
267
|
+
JSValue j_type = JS_GetPropertyStr(ctx, j_val, "type");
|
|
268
|
+
const char *type_str = JS_ToCString(ctx, j_type);
|
|
269
|
+
rb_iv_set(r_obj, "@type", rb_str_new_cstr(type_str ? type_str : ""));
|
|
270
|
+
JS_FreeCString(ctx, type_str);
|
|
271
|
+
JS_FreeValue(ctx, j_type);
|
|
272
|
+
|
|
273
|
+
rb_iv_set(r_obj, "@content", r_extract_blob_content(ctx, j_val));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
VALUE quickjsrb_try_convert_js_file(JSContext *ctx, JSValue j_val)
|
|
277
|
+
{
|
|
278
|
+
JSValue j_global = JS_GetGlobalObject(ctx);
|
|
279
|
+
|
|
280
|
+
// Check File first (File extends Blob, so instanceof Blob is also true for Files)
|
|
281
|
+
JSValue j_file_ctor = JS_GetPropertyStr(ctx, j_global, "File");
|
|
282
|
+
if (!JS_IsUndefined(j_file_ctor) && !JS_IsException(j_file_ctor))
|
|
283
|
+
{
|
|
284
|
+
int is_file = JS_IsInstanceOf(ctx, j_val, j_file_ctor);
|
|
285
|
+
JS_FreeValue(ctx, j_file_ctor);
|
|
286
|
+
if (is_file > 0)
|
|
287
|
+
{
|
|
288
|
+
JS_FreeValue(ctx, j_global);
|
|
289
|
+
|
|
290
|
+
VALUE r_quickjs_mod = rb_const_get(rb_cClass, rb_intern("Quickjs"));
|
|
291
|
+
VALUE r_file = rb_funcall(rb_const_get(r_quickjs_mod, rb_intern("File")), rb_intern("new"), 0);
|
|
292
|
+
r_populate_blob_attrs(ctx, j_val, r_file);
|
|
293
|
+
|
|
294
|
+
JSValue j_name = JS_GetPropertyStr(ctx, j_val, "name");
|
|
295
|
+
const char *name_str = JS_ToCString(ctx, j_name);
|
|
296
|
+
rb_iv_set(r_file, "@name", rb_str_new_cstr(name_str ? name_str : ""));
|
|
297
|
+
JS_FreeCString(ctx, name_str);
|
|
298
|
+
JS_FreeValue(ctx, j_name);
|
|
299
|
+
|
|
300
|
+
JSValue j_last_modified = JS_GetPropertyStr(ctx, j_val, "lastModified");
|
|
301
|
+
double last_modified_val;
|
|
302
|
+
JS_ToFloat64(ctx, &last_modified_val, j_last_modified);
|
|
303
|
+
rb_iv_set(r_file, "@last_modified", DBL2NUM(last_modified_val));
|
|
304
|
+
JS_FreeValue(ctx, j_last_modified);
|
|
305
|
+
|
|
306
|
+
return r_file;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else
|
|
310
|
+
{
|
|
311
|
+
JS_FreeValue(ctx, j_file_ctor);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
JSValue j_blob_ctor = JS_GetPropertyStr(ctx, j_global, "Blob");
|
|
315
|
+
JS_FreeValue(ctx, j_global);
|
|
316
|
+
if (JS_IsUndefined(j_blob_ctor) || JS_IsException(j_blob_ctor))
|
|
317
|
+
{
|
|
318
|
+
JS_FreeValue(ctx, j_blob_ctor);
|
|
319
|
+
return Qnil;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
int is_blob = JS_IsInstanceOf(ctx, j_val, j_blob_ctor);
|
|
323
|
+
JS_FreeValue(ctx, j_blob_ctor);
|
|
324
|
+
if (is_blob <= 0)
|
|
325
|
+
return Qnil;
|
|
326
|
+
|
|
327
|
+
VALUE r_quickjs_mod = rb_const_get(rb_cClass, rb_intern("Quickjs"));
|
|
328
|
+
VALUE r_blob = rb_funcall(rb_const_get(r_quickjs_mod, rb_intern("Blob")), rb_intern("new"), 0);
|
|
329
|
+
r_populate_blob_attrs(ctx, j_val, r_blob);
|
|
330
|
+
|
|
331
|
+
return r_blob;
|
|
332
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef QUICKJSRB_FILE_H
|
|
2
|
+
#define QUICKJSRB_FILE_H 1
|
|
3
|
+
|
|
4
|
+
// This header is included by quickjsrb.c (which already includes quickjsrb.h)
|
|
5
|
+
// and quickjsrb_file.c (which includes quickjsrb.h before this header).
|
|
6
|
+
// So we rely on VMData, JSValue, etc. being already defined.
|
|
7
|
+
|
|
8
|
+
void quickjsrb_init_file_proxy(VMData *data);
|
|
9
|
+
JSValue quickjsrb_file_to_js(JSContext *ctx, VALUE r_file);
|
|
10
|
+
|
|
11
|
+
// Check if a JS value is a File instance and convert to Quickjs::File
|
|
12
|
+
// Returns Qnil if not a File
|
|
13
|
+
VALUE quickjsrb_try_convert_js_file(JSContext *ctx, JSValue j_val);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
#endif /* QUICKJSRB_FILE_H */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){var e=class{get encoding(){return`utf-8`}encode(e=``){let t=String(e),n=[];for(let e=0;e<t.length;e++){let r=t.charCodeAt(e);if(r>=55296&&r<=56319&&e+1<t.length){let n=t.charCodeAt(e+1);n>=56320&&n<=57343&&(r=(r-55296)*1024+(n-56320)+65536,e++)}r<=127?n.push(r):r<=2047?n.push(192|r>>6,128|r&63):r<=65535?n.push(224|r>>12,128|r>>6&63,128|r&63):n.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return new Uint8Array(n)}encodeInto(e,t){let n=String(e),r=0,i=0;for(let e=0;e<n.length;e++){let a=n.charCodeAt(e);if(a>=55296&&a<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){if(i+4>t.length)break;a=(a-55296)*1024+(o-56320)+65536,t[i++]=240|a>>18,t[i++]=128|a>>12&63,t[i++]=128|a>>6&63,t[i++]=128|a&63,r+=2,e++;continue}}let o;if(o=a<=127?1:a<=2047?2:3,i+o>t.length)break;o===1?t[i++]=a:o===2?(t[i++]=192|a>>6,t[i++]=128|a&63):(t[i++]=224|a>>12,t[i++]=128|a>>6&63,t[i++]=128|a&63),r++}return{read:r,written:i}}};let t=[`unicode-1-1-utf-8`,`unicode11utf8`,`unicode20utf8`,`utf-8`,`utf8`,`x-unicode20utf8`];function n(e){let n=e.trim().toLowerCase();return t.includes(n)?`utf-8`:null}var r=class{#e;#t;#n;constructor(e=`utf-8`,t={}){let r=n(String(e));if(!r)throw RangeError(`The "${e}" encoding is not supported.`);this.#e=r,this.#t=!!t.fatal,this.#n=!!t.ignoreBOM}get encoding(){return this.#e}get fatal(){return this.#t}get ignoreBOM(){return this.#n}decode(e,t={}){if(e==null)return``;let n;if(e instanceof ArrayBuffer)n=new Uint8Array(e);else if(ArrayBuffer.isView(e))n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else throw TypeError(`The provided value is not of type '(ArrayBuffer or ArrayBufferView)'`);let r=0;return!this.#n&&n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191&&(r=3),i(n,r,this.#t)}};function i(e,t,n){let r=``,i=t;for(;i<e.length;){let t=e[i],a,o;if(t<=127)a=t,o=1;else if((t&224)==192){if(i+1>=e.length||(e[i+1]&192)!=128){if(n)throw TypeError(`The encoded data was not valid.`);r+=`�`,i++;continue}a=(t&31)<<6|e[i+1]&63,o=2}else if((t&240)==224){if(i+2>=e.length||(e[i+1]&192)!=128||(e[i+2]&192)!=128){if(n)throw TypeError(`The encoded data was not valid.`);r+=`�`,i++;continue}a=(t&15)<<12|(e[i+1]&63)<<6|e[i+2]&63,o=3}else if((t&248)==240){if(i+3>=e.length||(e[i+1]&192)!=128||(e[i+2]&192)!=128||(e[i+3]&192)!=128){if(n)throw TypeError(`The encoded data was not valid.`);r+=`�`,i++;continue}a=(t&7)<<18|(e[i+1]&63)<<12|(e[i+2]&63)<<6|e[i+3]&63,o=4}else{if(n)throw TypeError(`The encoded data was not valid.`);r+=`�`,i++;continue}a<=65535?r+=String.fromCharCode(a):(a-=65536,r+=String.fromCharCode(55296+(a>>10),56320+(a&1023))),i+=o}return r}globalThis.TextEncoder=e,globalThis.TextDecoder=r})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){var e=class e{#e;#t;constructor(n,i){if(this.#t=t(i?.type??``),!n){this.#e=new Uint8Array;return}if(!Array.isArray(n))throw TypeError(`Failed to construct 'Blob': The provided value cannot be converted to a sequence.`);let a=[],o=0;for(let t of n){let n;n=typeof t==`string`?r(t):t instanceof ArrayBuffer?new Uint8Array(t):ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof e?t.#e:r(String(t)),a.push(n),o+=n.byteLength}let s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.byteLength;this.#e=s}get size(){return this.#e.byteLength}get type(){return this.#t}slice(r,i,a){let o=this.size,s=r===void 0?0:n(r,o),c=i===void 0?o:n(i,o),l=Math.max(c-s,0),u=new e;return u.#e=this.#e.slice(s,s+l),u.#t=t(a??``),u}text(){return Promise.resolve(i(this.#e))}arrayBuffer(){return Promise.resolve(this.#e.buffer.slice(this.#e.byteOffset,this.#e.byteOffset+this.#e.byteLength))}toString(){return`[object Blob]`}get[Symbol.toStringTag](){return`Blob`}};function t(e){return/[^\x20-\x7E]/.test(e)?``:e.toLowerCase()}function n(e,t){return e<0?Math.max(t+e,0):Math.min(e,t)}function r(e){let t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){let t=e.charCodeAt(n+1);t>=56320&&t<=57343&&(r=(r-55296)*1024+(t-56320)+65536,n++)}r<=127?t.push(r):r<=2047?t.push(192|r>>6,128|r&63):r<=65535?t.push(224|r>>12,128|r>>6&63,128|r&63):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return new Uint8Array(t)}function i(e){let t=``,n=0;for(;n<e.length;){let r,i=e[n];i<=127?(r=i,n++):(i&224)==192?(r=(i&31)<<6|e[n+1]&63,n+=2):(i&240)==224?(r=(i&15)<<12|(e[n+1]&63)<<6|e[n+2]&63,n+=3):(r=(i&7)<<18|(e[n+1]&63)<<12|(e[n+2]&63)<<6|e[n+3]&63,n+=4),r<=65535?t+=String.fromCharCode(r):(r-=65536,t+=String.fromCharCode(55296+(r>>10),56320+(r&1023)))}return t}var a=class extends e{#e;#t;constructor(e,t,n){if(arguments.length<2)throw TypeError(`Failed to construct 'File': 2 arguments required, but only `+arguments.length+` present.`);super(e,n),this.#e=String(t),this.#t=n?.lastModified===void 0?Date.now():Number(n.lastModified)}get name(){return this.#e}get lastModified(){return this.#t}toString(){return`[object File]`}get[Symbol.toStringTag](){return`File`}};globalThis.Blob=e,globalThis.File=a})();
|