quickjs 0.5.0 → 0.5.1
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/README.md +1 -1
- data/ext/quickjsrb/quickjsrb.c +32 -19
- data/lib/quickjs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d949a011a5d0f2a19d351045d6a0de4550beee0908758c477a339af9d1e5863b
|
4
|
+
data.tar.gz: '09a2510b4a484e6b35a7be189cbd4015a3c575c0a318e8514beee56336c0055e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ecb1d0510082d9c0eca95ee6ef7257ff8f15ff4a2ea60fe9bc69e1274de689e71671b0f3f56ddcbe2c23421fa6fcd00b9cafadba653b89550447eb3b2a6310
|
7
|
+
data.tar.gz: af34d0b17332ba6df2e6f6c165d38cdd15ee4684a03f4bc5dc92dac2acdf5512313b263d775e9c942ab70a144e5317b1695b402ecf958ad3a86750662f84e675
|
data/README.md
CHANGED
@@ -158,6 +158,6 @@ vm,logs.last.raw #=> ['log me', nil]
|
|
158
158
|
|
159
159
|
## License
|
160
160
|
|
161
|
-
Every file in `ext/quickjsrb/quickjs` is licensed under [the MIT License Copyright 2017-2021 by Fabrice Bellard and Charlie
|
161
|
+
Every file in `ext/quickjsrb/quickjs` is licensed under [the MIT License Copyright 2017-2021 by Fabrice Bellard and Charlie Gordon](https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/LICENSE).
|
162
162
|
|
163
163
|
For otherwise, [the MIT License, Copyright 2024 by Kengo Hamasaki](/LICENSE).
|
data/ext/quickjsrb/quickjsrb.c
CHANGED
@@ -109,6 +109,25 @@ VALUE r_try_json_parse(VALUE r_str)
|
|
109
109
|
return rb_funcall(rb_const_get(rb_cClass, rb_intern("JSON")), rb_intern("parse"), 1, r_str);
|
110
110
|
}
|
111
111
|
|
112
|
+
VALUE to_r_json(JSContext *ctx, JSValue j_val)
|
113
|
+
{
|
114
|
+
JSValue j_global = JS_GetGlobalObject(ctx);
|
115
|
+
JSValue j_jsonClass = JS_GetPropertyStr(ctx, j_global, "JSON");
|
116
|
+
JSValue j_stringifyFunc = JS_GetPropertyStr(ctx, j_jsonClass, "stringify");
|
117
|
+
JSValue j_strigified = JS_Call(ctx, j_stringifyFunc, j_jsonClass, 1, &j_val);
|
118
|
+
|
119
|
+
const char *msg = JS_ToCString(ctx, j_strigified);
|
120
|
+
VALUE r_str = rb_str_new2(msg);
|
121
|
+
JS_FreeCString(ctx, msg);
|
122
|
+
|
123
|
+
JS_FreeValue(ctx, j_strigified);
|
124
|
+
JS_FreeValue(ctx, j_stringifyFunc);
|
125
|
+
JS_FreeValue(ctx, j_jsonClass);
|
126
|
+
JS_FreeValue(ctx, j_global);
|
127
|
+
|
128
|
+
return r_str;
|
129
|
+
}
|
130
|
+
|
112
131
|
VALUE to_rb_value(JSContext *ctx, JSValue j_val)
|
113
132
|
{
|
114
133
|
switch (JS_VALUE_GET_NORM_TAG(j_val))
|
@@ -135,10 +154,16 @@ VALUE to_rb_value(JSContext *ctx, JSValue j_val)
|
|
135
154
|
}
|
136
155
|
case JS_TAG_STRING:
|
137
156
|
{
|
138
|
-
|
139
|
-
VALUE
|
140
|
-
|
141
|
-
|
157
|
+
int couldntParse;
|
158
|
+
VALUE r_result = rb_protect(r_try_json_parse, to_r_json(ctx, j_val), &couldntParse);
|
159
|
+
if (couldntParse)
|
160
|
+
{
|
161
|
+
return Qnil;
|
162
|
+
}
|
163
|
+
else
|
164
|
+
{
|
165
|
+
return r_result;
|
166
|
+
}
|
142
167
|
}
|
143
168
|
case JS_TAG_OBJECT:
|
144
169
|
{
|
@@ -159,20 +184,7 @@ VALUE to_rb_value(JSContext *ctx, JSValue j_val)
|
|
159
184
|
}
|
160
185
|
// will support other errors like just returning an instance of Error
|
161
186
|
}
|
162
|
-
|
163
|
-
JSValue j_global = JS_GetGlobalObject(ctx);
|
164
|
-
JSValue j_jsonClass = JS_GetPropertyStr(ctx, j_global, "JSON");
|
165
|
-
JSValue j_stringifyFunc = JS_GetPropertyStr(ctx, j_jsonClass, "stringify");
|
166
|
-
JSValue j_strigified = JS_Call(ctx, j_stringifyFunc, j_jsonClass, 1, &j_val);
|
167
|
-
|
168
|
-
const char *msg = JS_ToCString(ctx, j_strigified);
|
169
|
-
VALUE r_str = rb_str_new2(msg);
|
170
|
-
JS_FreeCString(ctx, msg);
|
171
|
-
|
172
|
-
JS_FreeValue(ctx, j_strigified);
|
173
|
-
JS_FreeValue(ctx, j_stringifyFunc);
|
174
|
-
JS_FreeValue(ctx, j_jsonClass);
|
175
|
-
JS_FreeValue(ctx, j_global);
|
187
|
+
VALUE r_str = to_r_json(ctx, j_val);
|
176
188
|
|
177
189
|
if (rb_funcall(r_str, rb_intern("=="), 1, rb_str_new2("undefined")))
|
178
190
|
{
|
@@ -314,8 +326,9 @@ static JSValue js_quickjsrb_call_global(JSContext *ctx, JSValueConst _this, int
|
|
314
326
|
|
315
327
|
VMData *data = JS_GetContextOpaque(ctx);
|
316
328
|
VALUE r_proc = rb_hash_aref(data->defined_functions, rb_str_new2(funcName));
|
329
|
+
// Shouldn't happen
|
317
330
|
if (r_proc == Qnil)
|
318
|
-
{
|
331
|
+
{
|
319
332
|
return JS_ThrowReferenceError(ctx, "Proc `%s` is not defined", funcName); // TODO: Free funcnName
|
320
333
|
}
|
321
334
|
JS_FreeCString(ctx, funcName);
|
data/lib/quickjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hmsk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|