quickjs 0.6.3 → 0.6.5
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 +41 -26
- 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: 31bcb05285a3c4c80c6e5c06ec043793debf795c75f82362b317d74d3eb8cf96
|
4
|
+
data.tar.gz: 9032bf6cb129ea65dc52ae5df5ff394056f440c9de52947ab3029e5c0626c554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a12da5b5c71c5d350af754f5b50e47104a379aa53cde68625da76bf6b3e165a804b3ec9d764d52f7e8c87a696a870d948d17381bb044b13536b6e96992e9cea
|
7
|
+
data.tar.gz: 1b0b05872129c9d3850e66b0e5f77c779bb2554801e132380a0937a2d21d393b23317364e775ab9c0779ba074da157d46fdd6779a1b5f0ba690c55e2cbedccbd
|
data/README.md
CHANGED
@@ -153,7 +153,7 @@ vm.eval_code('console.log("log me", null)')
|
|
153
153
|
vm.logs #=> Array of Quickjs::VM::Log
|
154
154
|
vm.logs.last.severity #=> :info
|
155
155
|
vm.logs.last.to_s #=> 'log me null'
|
156
|
-
vm
|
156
|
+
vm.logs.last.raw #=> ['log me', nil]
|
157
157
|
```
|
158
158
|
|
159
159
|
## License
|
data/ext/quickjsrb/quickjsrb.c
CHANGED
@@ -58,17 +58,9 @@ JSValue to_js_value(JSContext *ctx, VALUE r_value)
|
|
58
58
|
{
|
59
59
|
VALUE r_json_str = rb_funcall(r_value, rb_intern("to_json"), 0, NULL);
|
60
60
|
char *str = StringValueCStr(r_json_str);
|
61
|
-
JSValue
|
62
|
-
JSValue j_jsonClass = JS_GetPropertyStr(ctx, j_global, "JSON");
|
63
|
-
JSValue j_parseFunc = JS_GetPropertyStr(ctx, j_jsonClass, "parse");
|
64
|
-
JSValue j_str = JS_NewString(ctx, str);
|
65
|
-
JSValue j_stringified = JS_Call(ctx, j_parseFunc, j_jsonClass, 1, (JSValueConst *)&j_str);
|
66
|
-
JS_FreeValue(ctx, j_global);
|
67
|
-
JS_FreeValue(ctx, j_jsonClass);
|
68
|
-
JS_FreeValue(ctx, j_parseFunc);
|
69
|
-
JS_FreeValue(ctx, j_str);
|
61
|
+
JSValue j_parsed = JS_ParseJSON(ctx, str, strlen(str), "<quickjsrb.c>");
|
70
62
|
|
71
|
-
return
|
63
|
+
return j_parsed;
|
72
64
|
}
|
73
65
|
default:
|
74
66
|
{
|
@@ -115,19 +107,13 @@ VALUE r_try_json_parse(VALUE r_str)
|
|
115
107
|
|
116
108
|
VALUE to_r_json(JSContext *ctx, JSValue j_val)
|
117
109
|
{
|
118
|
-
JSValue
|
119
|
-
JSValue j_jsonClass = JS_GetPropertyStr(ctx, j_global, "JSON");
|
120
|
-
JSValue j_stringifyFunc = JS_GetPropertyStr(ctx, j_jsonClass, "stringify");
|
121
|
-
JSValue j_strigified = JS_Call(ctx, j_stringifyFunc, j_jsonClass, 1, (JSValueConst *)&j_val);
|
110
|
+
JSValue j_stringified = JS_JSONStringify(ctx, j_val, JS_UNDEFINED, JS_UNDEFINED);
|
122
111
|
|
123
|
-
const char *msg = JS_ToCString(ctx,
|
112
|
+
const char *msg = JS_ToCString(ctx, j_stringified);
|
124
113
|
VALUE r_str = rb_str_new2(msg);
|
125
114
|
JS_FreeCString(ctx, msg);
|
126
115
|
|
127
|
-
JS_FreeValue(ctx,
|
128
|
-
JS_FreeValue(ctx, j_stringifyFunc);
|
129
|
-
JS_FreeValue(ctx, j_jsonClass);
|
130
|
-
JS_FreeValue(ctx, j_global);
|
116
|
+
JS_FreeValue(ctx, j_stringified);
|
131
117
|
|
132
118
|
return r_str;
|
133
119
|
}
|
@@ -138,9 +124,7 @@ VALUE to_rb_value(JSContext *ctx, JSValue j_val)
|
|
138
124
|
{
|
139
125
|
case JS_TAG_INT:
|
140
126
|
{
|
141
|
-
|
142
|
-
JS_ToInt32(ctx, &int_res, j_val);
|
143
|
-
return INT2NUM(int_res);
|
127
|
+
return INT2NUM(JS_VALUE_GET_INT(j_val));
|
144
128
|
}
|
145
129
|
case JS_TAG_FLOAT64:
|
146
130
|
{
|
@@ -148,9 +132,7 @@ VALUE to_rb_value(JSContext *ctx, JSValue j_val)
|
|
148
132
|
{
|
149
133
|
return QUICKJSRB_SYM(nanId);
|
150
134
|
}
|
151
|
-
|
152
|
-
JS_ToFloat64(ctx, &double_res, j_val);
|
153
|
-
return DBL2NUM(double_res);
|
135
|
+
return DBL2NUM(JS_VALUE_GET_FLOAT64(j_val));
|
154
136
|
}
|
155
137
|
case JS_TAG_BOOL:
|
156
138
|
{
|
@@ -406,7 +388,40 @@ static JSValue js_quickjsrb_log(JSContext *ctx, JSValueConst _this, int argc, JS
|
|
406
388
|
for (int i = 0; i < argc; i++)
|
407
389
|
{
|
408
390
|
JSValue j_logged = JS_DupValue(ctx, argv[i]);
|
409
|
-
VALUE r_raw
|
391
|
+
VALUE r_raw;
|
392
|
+
if (JS_VALUE_GET_NORM_TAG(j_logged) == JS_TAG_OBJECT && JS_PromiseState(ctx, j_logged) != -1)
|
393
|
+
{
|
394
|
+
r_raw = rb_str_new2("Promise");
|
395
|
+
}
|
396
|
+
else if (JS_IsError(ctx, j_logged))
|
397
|
+
{
|
398
|
+
JSValue j_errorClassName = JS_GetPropertyStr(ctx, j_logged, "name");
|
399
|
+
const char *errorClassName = JS_ToCString(ctx, j_errorClassName);
|
400
|
+
JS_FreeValue(ctx, j_errorClassName);
|
401
|
+
|
402
|
+
JSValue j_errorClassMessage = JS_GetPropertyStr(ctx, j_logged, "message");
|
403
|
+
const char *errorClassMessage = JS_ToCString(ctx, j_errorClassMessage);
|
404
|
+
JS_FreeValue(ctx, j_errorClassMessage);
|
405
|
+
|
406
|
+
JSValue j_stackTrace = JS_GetPropertyStr(ctx, j_logged, "stack");
|
407
|
+
const char *stackTrace = JS_ToCString(ctx, j_stackTrace);
|
408
|
+
JS_FreeValue(ctx, j_stackTrace);
|
409
|
+
|
410
|
+
const char *headlineTemplate = "%s: %s\n%s";
|
411
|
+
int length = snprintf(NULL, 0, headlineTemplate, errorClassName, errorClassMessage, stackTrace);
|
412
|
+
char *headline = (char *)malloc(length + 1);
|
413
|
+
snprintf(headline, length + 1, headlineTemplate, errorClassName, errorClassMessage, stackTrace);
|
414
|
+
JS_FreeCString(ctx, errorClassName);
|
415
|
+
JS_FreeCString(ctx, errorClassMessage);
|
416
|
+
JS_FreeCString(ctx, stackTrace);
|
417
|
+
|
418
|
+
r_raw = rb_str_new2(headline);
|
419
|
+
free(headline);
|
420
|
+
}
|
421
|
+
else
|
422
|
+
{
|
423
|
+
r_raw = to_rb_value(ctx, j_logged);
|
424
|
+
}
|
410
425
|
const char *body = JS_ToCString(ctx, j_logged);
|
411
426
|
VALUE r_c = rb_str_new2(body);
|
412
427
|
JS_FreeCString(ctx, body);
|
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.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hmsk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|