diff options
Diffstat (limited to 'js/src/builtin')
-rw-r--r-- | js/src/builtin/MapObject.h | 20 | ||||
-rw-r--r-- | js/src/builtin/Object.cpp | 14 | ||||
-rw-r--r-- | js/src/builtin/ReflectParse.cpp | 44 | ||||
-rw-r--r-- | js/src/builtin/TypedObject.cpp | 6 | ||||
-rw-r--r-- | js/src/builtin/TypedObject.h | 2 |
5 files changed, 61 insertions, 25 deletions
diff --git a/js/src/builtin/MapObject.h b/js/src/builtin/MapObject.h index 5382adfd2..a9f685ea0 100644 --- a/js/src/builtin/MapObject.h +++ b/js/src/builtin/MapObject.h @@ -52,14 +52,22 @@ class HashableValue } }; -template <> -class RootedBase<HashableValue> { +template <typename Wrapper> +class WrappedPtrOperations<HashableValue, Wrapper> +{ public: - MOZ_MUST_USE bool setValue(JSContext* cx, HandleValue v) { - return static_cast<JS::Rooted<HashableValue>*>(this)->get().setValue(cx, v); - } Value value() const { - return static_cast<const JS::Rooted<HashableValue>*>(this)->get().get(); + return static_cast<const Wrapper*>(this)->get().get(); + } +}; + +template <typename Wrapper> +class MutableWrappedPtrOperations<HashableValue, Wrapper> + : public WrappedPtrOperations<HashableValue, Wrapper> +{ + public: + MOZ_MUST_USE bool setValue(JSContext* cx, HandleValue v) { + return static_cast<Wrapper*>(this)->get().setValue(cx, v); } }; diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp index 1221d2daf..d661a222e 100644 --- a/js/src/builtin/Object.cpp +++ b/js/src/builtin/Object.cpp @@ -69,18 +69,18 @@ js::obj_propertyIsEnumerable(JSContext* cx, unsigned argc, Value* vp) JSObject* obj = &args.thisv().toObject(); /* Step 3. */ - Shape* shape; + PropertyResult prop; if (obj->isNative() && - NativeLookupOwnProperty<NoGC>(cx, &obj->as<NativeObject>(), id, &shape)) + NativeLookupOwnProperty<NoGC>(cx, &obj->as<NativeObject>(), id, &prop)) { /* Step 4. */ - if (!shape) { + if (!prop) { args.rval().setBoolean(false); return true; } /* Step 5. */ - unsigned attrs = GetShapeAttributes(obj, shape); + unsigned attrs = GetPropertyAttributes(obj, prop); args.rval().setBoolean((attrs & JSPROP_ENUMERATE) != 0); return true; } @@ -582,11 +582,11 @@ js::obj_hasOwnProperty(JSContext* cx, unsigned argc, Value* vp) jsid id; if (args.thisv().isObject() && ValueToId<NoGC>(cx, idValue, &id)) { JSObject* obj = &args.thisv().toObject(); - Shape* prop; + PropertyResult prop; if (obj->isNative() && NativeLookupOwnProperty<NoGC>(cx, &obj->as<NativeObject>(), id, &prop)) { - args.rval().setBoolean(!!prop); + args.rval().setBoolean(prop.isFound()); return true; } } @@ -839,7 +839,7 @@ EnumerableOwnProperties(JSContext* cx, const JS::CallArgs& args, EnumerableOwnPr value = nobj->getDenseOrTypedArrayElement(JSID_TO_INT(id)); } else { shape = nobj->lookup(cx, id); - if (!shape || !(GetShapeAttributes(nobj, shape) & JSPROP_ENUMERATE)) + if (!shape || !(shape->attributes() & JSPROP_ENUMERATE)) continue; if (!shape->isAccessorShape()) { if (!NativeGetExistingProperty(cx, nobj, nobj, shape, &value)) diff --git a/js/src/builtin/ReflectParse.cpp b/js/src/builtin/ReflectParse.cpp index c4a5e8138..48437a1f1 100644 --- a/js/src/builtin/ReflectParse.cpp +++ b/js/src/builtin/ReflectParse.cpp @@ -77,7 +77,7 @@ enum BinaryOperator { /* binary */ BINOP_BITOR, BINOP_BITXOR, BINOP_BITAND, /* misc */ - BINOP_IN, BINOP_INSTANCEOF, + BINOP_IN, BINOP_INSTANCEOF, BINOP_COALESCE, BINOP_LIMIT }; @@ -153,6 +153,7 @@ static const char* const binopNames[] = { "&", /* BINOP_BITAND */ "in", /* BINOP_IN */ "instanceof", /* BINOP_INSTANCEOF */ + "??" /* BINOP_COALESCE */ }; static const char* const unopNames[] = { @@ -564,7 +565,7 @@ class NodeBuilder MOZ_MUST_USE bool updateExpression(HandleValue expr, bool incr, bool prefix, TokenPos* pos, MutableHandleValue dst); - MOZ_MUST_USE bool logicalExpression(bool lor, HandleValue left, HandleValue right, TokenPos* pos, + MOZ_MUST_USE bool logicalExpression(ParseNodeKind kind, HandleValue left, HandleValue right, TokenPos* pos, MutableHandleValue dst); MOZ_MUST_USE bool conditionalExpression(HandleValue test, HandleValue cons, HandleValue alt, @@ -1086,12 +1087,35 @@ NodeBuilder::updateExpression(HandleValue expr, bool incr, bool prefix, TokenPos } bool -NodeBuilder::logicalExpression(bool lor, HandleValue left, HandleValue right, TokenPos* pos, +NodeBuilder::logicalExpression(ParseNodeKind kind, + HandleValue left, + HandleValue right, + TokenPos* pos, MutableHandleValue dst) { RootedValue opName(cx); - if (!atomValue(lor ? "||" : "&&", &opName)) - return false; + switch (kind) { + case PNK_COALESCE: + if (!atomValue("??", &opName)) { + return false; + } + break; + + case PNK_OR: + if (!atomValue("||", &opName)) { + return false; + } + break; + + case PNK_AND: + if (!atomValue("&&", &opName)) { + return false; + } + break; + + default: + LOCAL_NOT_REACHED("unexpected logical operator type"); + } RootedValue cb(cx, callbacks[AST_LOGICAL_EXPR]); if (!cb.isNull()) @@ -1989,6 +2013,8 @@ ASTSerializer::binop(ParseNodeKind kind, JSOp op) return BINOP_IN; case PNK_INSTANCEOF: return BINOP_INSTANCEOF; + case PNK_COALESCE: + return BINOP_COALESCE; default: return BINOP_ERR; } @@ -2648,8 +2674,9 @@ ASTSerializer::leftAssociate(ParseNode* pn, MutableHandleValue dst) MOZ_ASSERT(pn->pn_count >= 1); ParseNodeKind kind = pn->getKind(); - bool lor = kind == PNK_OR; - bool logop = lor || (kind == PNK_AND); + bool logop = (kind == PNK_COALESCE || + kind == PNK_OR || + kind == PNK_AND); ParseNode* head = pn->pn_head; RootedValue left(cx); @@ -2663,7 +2690,7 @@ ASTSerializer::leftAssociate(ParseNode* pn, MutableHandleValue dst) TokenPos subpos(pn->pn_pos.begin, next->pn_pos.end); if (logop) { - if (!builder.logicalExpression(lor, left, right, &subpos, &left)) + if (!builder.logicalExpression(kind, left, right, &subpos, &left)) return false; } else { BinaryOperator op = binop(pn->getKind(), pn->getOp()); @@ -2876,6 +2903,7 @@ ASTSerializer::expression(ParseNode* pn, MutableHandleValue dst) builder.conditionalExpression(test, cons, alt, &pn->pn_pos, dst); } + case PNK_COALESCE: case PNK_OR: case PNK_AND: return leftAssociate(pn, dst); diff --git a/js/src/builtin/TypedObject.cpp b/js/src/builtin/TypedObject.cpp index 4c938568f..2796848c0 100644 --- a/js/src/builtin/TypedObject.cpp +++ b/js/src/builtin/TypedObject.cpp @@ -1671,10 +1671,10 @@ TypeDescr::hasProperty(const JSAtomState& names, jsid id) /* static */ bool TypedObject::obj_lookupProperty(JSContext* cx, HandleObject obj, HandleId id, - MutableHandleObject objp, MutableHandleShape propp) + MutableHandleObject objp, MutableHandle<PropertyResult> propp) { if (obj->as<TypedObject>().typeDescr().hasProperty(cx->names(), id)) { - MarkNonNativePropertyFound<CanGC>(propp); + propp.setNonNativeProperty(); objp.set(obj); return true; } @@ -1682,7 +1682,7 @@ TypedObject::obj_lookupProperty(JSContext* cx, HandleObject obj, HandleId id, RootedObject proto(cx, obj->staticPrototype()); if (!proto) { objp.set(nullptr); - propp.set(nullptr); + propp.setNotFound(); return true; } diff --git a/js/src/builtin/TypedObject.h b/js/src/builtin/TypedObject.h index 4fcd30cb0..83700001d 100644 --- a/js/src/builtin/TypedObject.h +++ b/js/src/builtin/TypedObject.h @@ -509,7 +509,7 @@ class TypedObject : public ShapedObject static MOZ_MUST_USE bool obj_lookupProperty(JSContext* cx, HandleObject obj, HandleId id, MutableHandleObject objp, - MutableHandleShape propp); + MutableHandle<PropertyResult> propp); static MOZ_MUST_USE bool obj_defineProperty(JSContext* cx, HandleObject obj, HandleId id, Handle<PropertyDescriptor> desc, |