From b013db52910f92f2bdc4928a2c86470c7bddccf0 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 8 Oct 2013 22:56:08 +0300 Subject: [PATCH] change property lookup semantics for plain buffer and pointer values: continue lookup from Buffer and Pointer prototype object, respectively --- src/duk_hobject_props.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/duk_hobject_props.c b/src/duk_hobject_props.c index df1c715e..8d6ce88d 100644 --- a/src/duk_hobject_props.c +++ b/src/duk_hobject_props.c @@ -1664,11 +1664,7 @@ int duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key) { switch (DUK_TVAL_GET_TAG(tv_obj)) { case DUK_TAG_UNDEFINED: - case DUK_TAG_NULL: - case DUK_TAG_BUFFER: - case DUK_TAG_POINTER: { - /* FIXME: add a prototype object for buffers and perhaps for pointers? */ - + case DUK_TAG_NULL: { /* Note: unconditional throw */ DUK_DDDPRINT("base object is undefined, null, buffer, or pointer -> reject"); DUK_ERROR(thr, DUK_ERR_TYPE_ERROR, "invalid base reference for property read"); @@ -1777,6 +1773,19 @@ int duk_hobject_getprop(duk_hthread *thr, duk_tval *tv_obj, duk_tval *tv_key) { break; } + /* Buffer doesn't have virtual properties at the moment (indices or length). */ + case DUK_TAG_BUFFER: { + DUK_DDDPRINT("base object is a buffer, start lookup from buffer prototype"); + curr = thr->builtins[DUK_BIDX_BUFFER_PROTOTYPE]; + break; + } + + case DUK_TAG_POINTER: { + DUK_DDDPRINT("base object is a pointer, start lookup from pointer prototype"); + curr = thr->builtins[DUK_BIDX_POINTER_PROTOTYPE]; + break; + } + default: { /* number */ DUK_DDDPRINT("base object is a number, start lookup from number prototype");