fix string hash bug
This commit is contained in:
@@ -526,7 +526,7 @@ JS_BOOL js_key_equal_str (JSValue a, const char *str) {
|
||||
}
|
||||
|
||||
if (!JS_IsPtr (a)) return FALSE;
|
||||
JSText *ta = (JSText *)JS_VALUE_GET_PTR (a);
|
||||
JSText *ta = (JSText *)chase (a);
|
||||
if (objhdr_type (ta->hdr) != OBJ_TEXT) return FALSE;
|
||||
uint64_t txt_len = objhdr_cap56 (ta->hdr);
|
||||
if (txt_len != len) return FALSE;
|
||||
@@ -704,6 +704,16 @@ int rec_set_own (JSContext *ctx, JSValue *pobj, JSValue k, JSValue val) {
|
||||
rec->slots[insert_slot].val = val;
|
||||
rec->len++;
|
||||
|
||||
#ifdef VALIDATE_GC
|
||||
/* Verify the just-inserted key is findable */
|
||||
int verify = rec_find_slot (rec, k);
|
||||
if (verify <= 0) {
|
||||
fprintf (stderr, "rec_set_own: INSERTED KEY NOT FINDABLE! slot=%d insert_slot=%d len=%u\n",
|
||||
verify, insert_slot, (uint32_t)rec->len);
|
||||
abort ();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1873,6 +1883,12 @@ JSText *js_alloc_string (JSContext *ctx, int max_len) {
|
||||
/* Initialize objhdr_t with OBJ_TEXT type and capacity in cap56 */
|
||||
str->hdr = objhdr_make (max_len, OBJ_TEXT, false, false, false, false);
|
||||
str->length = 0; /* length starts at 0, capacity is in hdr */
|
||||
/* Zero packed data so odd-length strings have deterministic padding.
|
||||
js_malloc is a bump allocator and does not zero memory; without this,
|
||||
the last word's unused low 32 bits contain garbage, causing
|
||||
fash64_hash_words and JSText_equal (memcmp) to produce inconsistent
|
||||
results for different allocations of the same text content. */
|
||||
memset (str->packed, 0, data_words * sizeof (uint64_t));
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -3514,9 +3530,9 @@ JSValue JS_GetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key) {
|
||||
return JS_GetProperty (ctx, this_obj, key);
|
||||
}
|
||||
|
||||
/* CAUTION: rec_set_own is NOT GC-safe if rec_resize is implemented.
|
||||
Currently safe because rec_resize always fails.
|
||||
When resize is implemented, rec pointer may become stale. */
|
||||
/* rec_set_own calls rec_resize which can move the record.
|
||||
JS_SetProperty uses a local copy so the caller's JSValue is NOT updated;
|
||||
the VM must call mach_resolve_forward after store operations. */
|
||||
int JS_SetPropertyKey (JSContext *ctx, JSValue this_obj, JSValue key, JSValue val) {
|
||||
if (JS_IsRecord (key)) {
|
||||
if (!JS_IsRecord (this_obj)) {
|
||||
|
||||
Reference in New Issue
Block a user