diff options
author | bellard <6490144+bellard@users.noreply.github.com> | 2020-09-06 19:02:03 +0200 |
---|---|---|
committer | bellard <6490144+bellard@users.noreply.github.com> | 2020-09-06 19:02:03 +0200 |
commit | 383e2b06c8af144b5cd729dc7bc4ce2e2613f178 (patch) | |
tree | 77bf320a5bf01cbcd248f9b85a804980bc89f01d /quickjs.h | |
parent | 0e8fffd4de4a10f498f46cd0e99f53da6a523542 (diff) | |
download | quickjs-383e2b06c8af144b5cd729dc7bc4ce2e2613f178.tar.gz quickjs-383e2b06c8af144b5cd729dc7bc4ce2e2613f178.zip |
2020-03-16 release
Diffstat (limited to 'quickjs.h')
-rw-r--r-- | quickjs.h | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -335,6 +335,8 @@ void JS_SetMemoryLimit(JSRuntime *rt, size_t limit); void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold); JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque); void JS_FreeRuntime(JSRuntime *rt); +void *JS_GetRuntimeOpaque(JSRuntime *rt); +void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque); typedef void JS_MarkFunc(JSRuntime *rt, JSGCObjectHeader *gp); void JS_MarkValue(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func); void JS_RunGC(JSRuntime *rt); @@ -508,7 +510,28 @@ static js_force_inline JSValue JS_NewCatchOffset(JSContext *ctx, int32_t val) return JS_MKVAL(JS_TAG_CATCH_OFFSET, val); } -JSValue JS_NewInt64(JSContext *ctx, int64_t v); +static js_force_inline JSValue JS_NewInt64(JSContext *ctx, int64_t val) +{ + JSValue v; + if (val == (int32_t)val) { + v = JS_NewInt32(ctx, val); + } else { + v = __JS_NewFloat64(ctx, val); + } + return v; +} + +static js_force_inline JSValue JS_NewUint32(JSContext *ctx, uint32_t val) +{ + JSValue v; + if (val <= 0x7fffffff) { + v = JS_NewInt32(ctx, val); + } else { + v = __JS_NewFloat64(ctx, val); + } + return v; +} + JSValue JS_NewBigInt64(JSContext *ctx, int64_t v); JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v); @@ -657,7 +680,10 @@ static int inline JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val) int JS_ToInt64(JSContext *ctx, int64_t *pres, JSValueConst val); int JS_ToIndex(JSContext *ctx, uint64_t *plen, JSValueConst val); int JS_ToFloat64(JSContext *ctx, double *pres, JSValueConst val); +/* return an exception if 'val' is a Number */ int JS_ToBigInt64(JSContext *ctx, int64_t *pres, JSValueConst val); +/* same as JS_ToInt64() but allow BigInt */ +int JS_ToInt64Ext(JSContext *ctx, int64_t *pres, JSValueConst val); JSValue JS_NewStringLen(JSContext *ctx, const char *str1, size_t len1); JSValue JS_NewString(JSContext *ctx, const char *str); |