Skip to content

Instantly share code, notes, and snippets.

@Geequlim
Created July 19, 2020 03:48
Show Gist options
  • Save Geequlim/52ddd9007b0ef3a58e7fd354ec8a0118 to your computer and use it in GitHub Desktop.
Save Geequlim/52ddd9007b0ef3a58e7fd354ec8a0118 to your computer and use it in GitHub Desktop.
QuickJS-Patch
diff --git a/quickjs.c b/quickjs.c
index 8fbb7a3..00d67df 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -73,7 +73,7 @@
#if !defined(EMSCRIPTEN)
/* enable stack limitation */
-#define CONFIG_STACK_CHECK
+// #define CONFIG_STACK_CHECK
#endif
@@ -6138,7 +6138,7 @@ void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt)
#ifdef CONFIG_BIGNUM
"BigNum "
#endif
- CONFIG_VERSION " version, %d-bit, malloc limit: %"PRId64"\n\n",
+ "2020-07-05" " version, %d-bit, malloc limit: %"PRId64"\n\n",
(int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit);
#if 1
if (rt) {
@@ -6757,6 +6757,9 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj,
if (unlikely(p->class_id == JS_CLASS_PROXY))
return js_proxy_setPrototypeOf(ctx, obj, proto_val, throw_flag);
sh = p->shape;
+ if (!sh) {
+ return -1;
+ }
if (sh->proto == proto)
return TRUE;
if (!p->extensible) {
@@ -53311,3 +53314,73 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
JS_AddIntrinsicAtomics(ctx);
#endif
}
+
+
+int JS_GetModuleExportEntriesCount(JSModuleDef *m)
+{
+ return m->export_entries_count;
+}
+
+JSValue JS_GetModuleExportEntry(JSContext *ctx, JSModuleDef *m, int idx)
+{
+ if (idx >= m->export_entries_count || idx < 0)
+ return JS_UNDEFINED;
+ return JS_DupValue(ctx, m->export_entries[idx].u.local.var_ref->value);
+}
+
+JSAtom JS_GetModuleExportEntryName(JSContext *ctx, JSModuleDef *m, int idx)
+{
+ if (idx >= m->export_entries_count || idx < 0)
+ return JS_ATOM_NULL;
+ return JS_DupAtom(ctx, m->export_entries[idx].export_name);
+}
+
+JS_BOOL JS_IsPureCFunction(JSContext *ctx, JSValue val)
+{
+ JSObject *p;
+ if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
+ return FALSE;
+ p = JS_VALUE_GET_OBJ(val);
+ return p->class_id == JS_CLASS_C_FUNCTION;
+}
+
+const JSMallocState* JS_GetMollocState(JSRuntime *rt) {
+ return &rt->malloc_state;
+}
+
+JSValue JS_GetStackFunction(JSContext *ctx, int back_level) {
+ JSRuntime *rt = JS_GetRuntime(ctx);
+ JSValue func = JS_UNDEFINED;
+
+ JSStackFrame *frame = rt->current_stack_frame;
+ int level = 0;
+ while (frame) {
+ if (level >= back_level) {
+ func = JS_DupValue(ctx, frame->cur_func);
+ break;
+ }
+ level += 1;
+ frame = frame->prev_frame;
+ }
+
+ return func;
+}
+
+int JS_GetRefCount(JSValue v) {
+ if (JS_VALUE_HAS_REF_COUNT(v)) {
+ JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v);
+ return p->ref_count;
+ }
+ return 0;
+}
+
+/* return -1 if exception (proxy case) or TRUE/FALSE */
+JS_BOOL JS_IsArrayBuffer(JSValueConst val) {
+ JSObject *p;
+ if (JS_VALUE_GET_TAG(val) == JS_TAG_OBJECT) {
+ p = JS_VALUE_GET_OBJ(val);
+ return p->class_id == JS_CLASS_ARRAY_BUFFER;
+ } else {
+ return FALSE;
+ }
+}
diff --git a/quickjs.h b/quickjs.h
index db29372..9431e81 100644
--- a/quickjs.h
+++ b/quickjs.h
@@ -1020,6 +1020,15 @@ int JS_SetModuleExport(JSContext *ctx, JSModuleDef *m, const char *export_name,
int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
const JSCFunctionListEntry *tab, int len);
+int JS_GetModuleExportEntriesCount(JSModuleDef *m);
+JSValue JS_GetModuleExportEntry(JSContext *ctx, JSModuleDef *m, int idx);
+JSAtom JS_GetModuleExportEntryName(JSContext *ctx, JSModuleDef *m, int idx);
+JSValue JS_GetStackFunction(JSContext *ctx, int back_level);
+JS_BOOL JS_IsPureCFunction(JSContext *ctx, JSValue val);
+const JSMallocState *JS_GetMollocState(JSRuntime *rt);
+int JS_GetRefCount(JSValue val);
+JS_BOOL JS_IsArrayBuffer(JSValueConst val);
+
#undef js_unlikely
#undef js_force_inline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment