/**
* A simple Maybe type, representing an object which may or may not have a
- * value.
+ * value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.
*/
template <class T>
class Maybe {
public:
- // TODO(dcarney): remove this constructor, it makes no sense.
- Maybe(bool has, const T& t) : has_value(has), value(t) {}
-
V8_INLINE bool IsJust() const { return has_value; }
V8_INLINE T FromJust() const {
return has_value ? value : default_value;
}
- // TODO(dcarney): make private.
+ V8_INLINE bool operator==(const Maybe& other) const {
+ return (IsJust() == other.IsJust()) &&
+ (!IsJust() || FromJust() == other.FromJust());
+ }
+
+ V8_INLINE bool operator!=(const Maybe& other) const {
+ return !operator==(other);
+ }
+
+ private:
+ Maybe() : has_value(false) {}
+ explicit Maybe(const T& t) : has_value(true), value(t) {}
+
bool has_value;
T value;
- private:
template <class U>
friend Maybe<U> Nothing();
template <class U>
friend Maybe<U> Just(const U& u);
-
- Maybe() : has_value(false) {}
- explicit Maybe(const T& t) : has_value(true), value(t) {}
};
LookupIterator it(object, Handle<Name>::cast(key),
LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- DCHECK(maybe.has_value);
+ DCHECK(maybe.IsJust());
duplicate = it.IsFound();
} else {
uint32_t index = 0;
key->ToArrayIndex(&index);
Maybe<bool> maybe = JSReceiver::HasOwnElement(object, index);
- if (!maybe.has_value) return MaybeHandle<Object>();
- duplicate = maybe.value;
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ duplicate = maybe.FromJust();
}
if (duplicate) {
Handle<Object> args[1] = {key};
{
EXCEPTION_PREAMBLE(isolate_);
Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
- has_pending_exception = !maybe.has_value;
+ has_pending_exception = !maybe.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate_, v8::Local<Value>());
- if (!maybe.value) return v8::Local<Value>();
+ if (!maybe.FromJust()) return v8::Local<Value>();
}
i::Handle<i::Object> value;
EXCEPTION_PREAMBLE(isolate_);
EXCEPTION_PREAMBLE(isolate);
Maybe<PropertyAttributes> result =
i::JSReceiver::GetPropertyAttributes(self, key_name);
- has_pending_exception = !result.has_value;
+ has_pending_exception = !result.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate, static_cast<PropertyAttribute>(NONE));
- if (result.value == ABSENT) return static_cast<PropertyAttribute>(NONE);
- return static_cast<PropertyAttribute>(result.value);
+ if (result.FromJust() == ABSENT) return static_cast<PropertyAttribute>(NONE);
+ return static_cast<PropertyAttribute>(result.FromJust());
}
maybe = i::JSReceiver::HasProperty(self, name);
}
}
- if (!maybe.has_value) has_pending_exception = true;
+ if (!maybe.IsJust()) has_pending_exception = true;
EXCEPTION_BAILOUT_CHECK(isolate, false);
- DCHECK(maybe.has_value);
- return maybe.value;
+ DCHECK(maybe.IsJust());
+ return maybe.FromJust();
}
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe = i::JSReceiver::HasElement(self, index);
- has_pending_exception = !maybe.has_value;
+ has_pending_exception = !maybe.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate, false);
- return maybe.value;
+ return maybe.FromJust();
}
EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe = i::JSReceiver::HasOwnProperty(Utils::OpenHandle(this),
Utils::OpenHandle(*key));
- has_pending_exception = !maybe.has_value;
+ has_pending_exception = !maybe.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate, false);
- return maybe.value;
+ return maybe.FromJust();
}
EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe = i::JSObject::HasRealNamedProperty(
Utils::OpenHandle(this), Utils::OpenHandle(*key));
- has_pending_exception = !maybe.has_value;
+ has_pending_exception = !maybe.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate, false);
- return maybe.value;
+ return maybe.FromJust();
}
EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe =
i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index);
- has_pending_exception = !maybe.has_value;
+ has_pending_exception = !maybe.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate, false);
- return maybe.value;
+ return maybe.FromJust();
}
EXCEPTION_PREAMBLE(isolate);
Maybe<bool> maybe = i::JSObject::HasRealNamedCallbackProperty(
Utils::OpenHandle(this), Utils::OpenHandle(*key));
- has_pending_exception = !maybe.has_value;
+ has_pending_exception = !maybe.IsJust();
EXCEPTION_BAILOUT_CHECK(isolate, false);
- return maybe.value;
+ return maybe.FromJust();
}
i::LookupIterator* it) {
Maybe<PropertyAttributes> attr = i::JSReceiver::GetPropertyAttributes(it);
return it->IsFound() ? Just<PropertyAttribute>(
- static_cast<PropertyAttribute>(attr.value))
+ static_cast<PropertyAttribute>(attr.FromJust()))
: Nothing<PropertyAttribute>();
}
return has_fixed_right_arg_ ? Just(fixed_right_arg_value_) : Nothing<int>();
}
void set_fixed_right_arg(Maybe<int> arg) {
- has_fixed_right_arg_ = arg.has_value;
- if (arg.has_value) fixed_right_arg_value_ = arg.value;
+ has_fixed_right_arg_ = arg.IsJust();
+ if (arg.IsJust()) fixed_right_arg_value_ = arg.FromJust();
}
virtual void RecordToBooleanTypeFeedback(
Isolate* isolate = it->isolate();
Maybe<PropertyAttributes> attrs = JSReceiver::GetPropertyAttributes(it);
- DCHECK(attrs.has_value || isolate->has_pending_exception());
- if (!attrs.has_value || attrs.value == ABSENT) return attrs;
+ DCHECK(attrs.IsJust() || isolate->has_pending_exception());
+ if (!attrs.IsJust() || attrs.FromJust() == ABSENT) return attrs;
Handle<Symbol> unscopables_symbol = isolate->factory()->unscopables_symbol();
Handle<Object> receiver = it->GetReceiver();
maybe = JSReceiver::GetPropertyAttributes(object, name);
}
- if (!maybe.has_value) return Handle<Object>();
+ if (!maybe.IsJust()) return Handle<Object>();
DCHECK(!isolate->has_pending_exception());
- *attributes = maybe.value;
+ *attributes = maybe.FromJust();
- if (maybe.value != ABSENT) {
+ if (maybe.FromJust() != ABSENT) {
if (FLAG_trace_contexts) {
PrintF("=> found property in context object %p\n",
reinterpret_cast<void*>(*object));
HConstant(DoubleToInt32(double_value_), Representation::Integer32(),
NotInNewSpace(), object_);
}
- return Maybe<HConstant*>(res != NULL, res);
+ return res != NULL ? Just(res) : Nothing<HConstant*>();
}
} else if (handle->IsNull()) {
res = new(zone) HConstant(0);
}
- return Maybe<HConstant*>(res != NULL, res);
+ return res != NULL ? Just(res) : Nothing<HConstant*>();
}
// Try to create a new copy of the constant with the new representation.
if (is_truncating_to_int && to.IsInteger32()) {
Maybe<HConstant*> res = constant->CopyToTruncatedInt32(graph()->zone());
- if (res.has_value) new_value = res.value;
+ if (res.IsJust()) new_value = res.FromJust();
} else {
new_value = constant->CopyToRepresentation(to, graph()->zone());
}
HConstant* constant = HConstant::cast(value);
Maybe<HConstant*> number =
constant->CopyToTruncatedNumber(isolate(), zone());
- if (number.has_value) {
+ if (number.IsJust()) {
*expected = Type::Number(zone());
- return AddInstruction(number.value);
+ return AddInstruction(number.FromJust());
}
}
instr = AddUncasted<HMul>(left, right);
break;
case Token::MOD: {
- if (fixed_right_arg.has_value &&
- !right->EqualsInteger32Constant(fixed_right_arg.value)) {
- HConstant* fixed_right = Add<HConstant>(
- static_cast<int>(fixed_right_arg.value));
+ if (fixed_right_arg.IsJust() &&
+ !right->EqualsInteger32Constant(fixed_right_arg.FromJust())) {
+ HConstant* fixed_right =
+ Add<HConstant>(static_cast<int>(fixed_right_arg.FromJust()));
IfBuilder if_same(this);
if_same.If<HCompareNumericAndBranch>(right, fixed_right, Token::EQ);
if_same.Then();
Handle<String> key =
factory->NewStringFromStaticChars("minimumSignificantDigits");
Maybe<bool> maybe = JSReceiver::HasOwnProperty(resolved, key);
- CHECK(maybe.has_value);
- if (maybe.value) {
+ CHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
JSObject::SetProperty(
resolved, factory->NewStringFromStaticChars("minimumSignificantDigits"),
factory->NewNumberFromInt(number_format->getMinimumSignificantDigits()),
key = factory->NewStringFromStaticChars("maximumSignificantDigits");
maybe = JSReceiver::HasOwnProperty(resolved, key);
- CHECK(maybe.has_value);
- if (maybe.value) {
+ CHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
JSObject::SetProperty(
resolved, factory->NewStringFromStaticChars("maximumSignificantDigits"),
factory->NewNumberFromInt(number_format->getMaximumSignificantDigits()),
Handle<String> key =
isolate->factory()->NewStringFromStaticChars("dateFormat");
Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
- CHECK(maybe.has_value);
- if (maybe.value) {
+ CHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
return reinterpret_cast<icu::SimpleDateFormat*>(
obj->GetInternalField(0));
}
Handle<String> key =
isolate->factory()->NewStringFromStaticChars("numberFormat");
Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
- CHECK(maybe.has_value);
- if (maybe.value) {
+ CHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0));
}
Handle<JSObject> obj) {
Handle<String> key = isolate->factory()->NewStringFromStaticChars("collator");
Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
- CHECK(maybe.has_value);
- if (maybe.value) {
+ CHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0));
}
Handle<String> key =
isolate->factory()->NewStringFromStaticChars("breakIterator");
Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, key);
- CHECK(maybe.has_value);
- if (maybe.value) {
+ CHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0));
}
BinaryOpICState::BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state)
- : fixed_right_arg_(Nothing<int>()), isolate_(isolate) {
+ : fixed_right_arg_(
+ HasFixedRightArgField::decode(extra_ic_state)
+ ? Just(1 << FixedRightArgValueField::decode(extra_ic_state))
+ : Nothing<int>()),
+ isolate_(isolate) {
op_ =
static_cast<Token::Value>(FIRST_TOKEN + OpField::decode(extra_ic_state));
- fixed_right_arg_ =
- Maybe<int>(HasFixedRightArgField::decode(extra_ic_state),
- 1 << FixedRightArgValueField::decode(extra_ic_state));
left_kind_ = LeftKindField::decode(extra_ic_state);
- if (fixed_right_arg_.has_value) {
- right_kind_ = Smi::IsValid(fixed_right_arg_.value) ? SMI : INT32;
- } else {
- right_kind_ = RightKindField::decode(extra_ic_state);
- }
+ right_kind_ = fixed_right_arg_.IsJust()
+ ? (Smi::IsValid(fixed_right_arg_.FromJust()) ? SMI : INT32)
+ : RightKindField::decode(extra_ic_state);
result_kind_ = ResultKindField::decode(extra_ic_state);
DCHECK_LE(FIRST_TOKEN, op_);
DCHECK_LE(op_, LAST_TOKEN);
ExtraICState extra_ic_state =
OpField::encode(op_ - FIRST_TOKEN) | LeftKindField::encode(left_kind_) |
ResultKindField::encode(result_kind_) |
- HasFixedRightArgField::encode(fixed_right_arg_.has_value);
- if (fixed_right_arg_.has_value) {
+ HasFixedRightArgField::encode(fixed_right_arg_.IsJust());
+ if (fixed_right_arg_.IsJust()) {
extra_ic_state = FixedRightArgValueField::update(
- extra_ic_state, WhichPowerOf2(fixed_right_arg_.value));
+ extra_ic_state, WhichPowerOf2(fixed_right_arg_.FromJust()));
} else {
extra_ic_state = RightKindField::update(extra_ic_state, right_kind_);
}
do { \
BinaryOpICState state(isolate, op); \
state.left_kind_ = left_kind; \
- state.fixed_right_arg_.has_value = false; \
+ state.fixed_right_arg_ = Nothing<int>(); \
state.right_kind_ = right_kind; \
state.result_kind_ = result_kind; \
Generate(isolate, state); \
do { \
BinaryOpICState state(isolate, op); \
state.left_kind_ = left_kind; \
- state.fixed_right_arg_.has_value = true; \
- state.fixed_right_arg_.value = fixed_right_arg_value; \
+ state.fixed_right_arg_ = Just(fixed_right_arg_value); \
state.right_kind_ = SMI; \
state.result_kind_ = result_kind; \
Generate(isolate, state); \
os << "(" << Token::Name(s.op_);
if (s.CouldCreateAllocationMementos()) os << "_CreateAllocationMementos";
os << ":" << BinaryOpICState::KindToString(s.left_kind_) << "*";
- if (s.fixed_right_arg_.has_value) {
- os << s.fixed_right_arg_.value;
+ if (s.fixed_right_arg_.IsJust()) {
+ os << s.fixed_right_arg_.FromJust();
} else {
os << BinaryOpICState::KindToString(s.right_kind_);
}
base::bits::IsPowerOfTwo32(fixed_right_arg_value) &&
FixedRightArgValueField::is_valid(WhichPowerOf2(fixed_right_arg_value)) &&
(left_kind_ == SMI || left_kind_ == INT32) &&
- (result_kind_ == NONE || !fixed_right_arg_.has_value);
- fixed_right_arg_ = Maybe<int32_t>(has_fixed_right_arg, fixed_right_arg_value);
-
+ (result_kind_ == NONE || !fixed_right_arg_.IsJust());
+ fixed_right_arg_ =
+ has_fixed_right_arg ? Just(fixed_right_arg_value) : Nothing<int32_t>();
result_kind_ = UpdateKind(result, result_kind_);
if (!Token::IsTruncatingBinaryOp(op_)) {
return JSProxy::HasPropertyWithHandler(proxy, name);
}
Maybe<PropertyAttributes> result = GetPropertyAttributes(object, name);
- return result.has_value ? Just(result.value != ABSENT) : Nothing<bool>();
+ return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
}
return JSProxy::HasPropertyWithHandler(proxy, name);
}
Maybe<PropertyAttributes> result = GetOwnPropertyAttributes(object, name);
- return result.has_value ? Just(result.value != ABSENT) : Nothing<bool>();
+ return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
}
}
Maybe<PropertyAttributes> result = JSObject::GetElementAttributeWithReceiver(
Handle<JSObject>::cast(object), object, index, true);
- return result.has_value ? Just(result.value != ABSENT) : Nothing<bool>();
+ return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
}
}
Maybe<PropertyAttributes> result = JSObject::GetElementAttributeWithReceiver(
Handle<JSObject>::cast(object), object, index, false);
- return result.has_value ? Just(result.value != ABSENT) : Nothing<bool>();
+ return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
}
auto result = GetPropertyAttributesWithInterceptor(
it->GetHolder<JSObject>(), it->GetReceiver(), it->name());
if (it->isolate()->has_scheduled_exception()) break;
- if (result.has_value && result.value != ABSENT) return result;
+ if (result.IsJust() && result.FromJust() != ABSENT) return result;
}
it->isolate()->ReportFailedAccessCheck(checked);
RETURN_VALUE_IF_SCHEDULED_EXCEPTION(it->isolate(),
auto result =
JSObject::GetElementAttributeFromInterceptor(object, receiver, index);
if (isolate->has_scheduled_exception()) break;
- if (result.has_value && result.value != ABSENT) return result;
+ if (result.IsJust() && result.FromJust() != ABSENT) return result;
where_to_start = PrototypeIterator::START_AT_PROTOTYPE;
}
isolate->ReportFailedAccessCheck(object);
Maybe<PropertyAttributes> from_interceptor =
JSObject::GetElementAttributeFromInterceptor(js_object, receiver,
index);
- if (!from_interceptor.has_value) return MaybeHandle<Object>();
- if ((from_interceptor.value & READ_ONLY) != 0) {
+ if (!from_interceptor.IsJust()) return MaybeHandle<Object>();
+ if ((from_interceptor.FromJust() & READ_ONLY) != 0) {
return WriteToReadOnlyElement(isolate, receiver, index, value,
language_mode);
}
- done = from_interceptor.value != ABSENT;
+ done = from_interceptor.FromJust() != ABSENT;
}
if (!done &&
Maybe<PropertyAttributes> maybe_attributes =
JSObject::GetPropertyAttributesWithInterceptor(
it->GetHolder<JSObject>(), it->GetReceiver(), it->name());
- if (!maybe_attributes.has_value) return MaybeHandle<Object>();
- done = maybe_attributes.value != ABSENT;
- if (done && (maybe_attributes.value & READ_ONLY) != 0) {
+ if (!maybe_attributes.IsJust()) return MaybeHandle<Object>();
+ done = maybe_attributes.FromJust() != ABSENT;
+ if (done && (maybe_attributes.FromJust() & READ_ONLY) != 0) {
return WriteToReadOnlyProperty(it, value, language_mode);
}
}
DCHECK(!object->IsJSProxy());
DCHECK(!name->AsArrayIndex(&index));
Maybe<PropertyAttributes> maybe = GetPropertyAttributes(&it);
- DCHECK(maybe.has_value);
+ DCHECK(maybe.IsJust());
DCHECK(!it.IsFound());
DCHECK(object->map()->is_extensible() ||
it.isolate()->IsInternallyUsedPropertyName(name));
Maybe<PropertyAttributes> result =
JSObject::GetPropertyAttributesWithInterceptor(
it->GetHolder<JSObject>(), it->GetReceiver(), it->name());
- if (!result.has_value) return result;
- if (result.value != ABSENT) return result;
+ if (!result.IsJust()) return result;
+ if (result.FromJust() != ABSENT) return result;
break;
}
case LookupIterator::ACCESS_CHECK:
Maybe<PropertyAttributes> from_interceptor =
GetElementAttributeFromInterceptor(object, receiver, index);
- if (!from_interceptor.has_value) return Nothing<PropertyAttributes>();
- if (from_interceptor.value != ABSENT) return Just(from_interceptor.value);
+ if (!from_interceptor.IsJust()) return Nothing<PropertyAttributes>();
+ if (from_interceptor.FromJust() != ABSENT)
+ return Just(from_interceptor.FromJust());
return GetElementAttributeWithoutInterceptor(object, receiver, index,
check_prototype);
LookupIterator it(object, hidden, LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = GetPropertyAttributes(&it);
// Cannot get an exception since the hidden_string isn't accessible to JS.
- DCHECK(maybe.has_value);
- return maybe.value != ABSENT;
+ DCHECK(maybe.IsJust());
+ return maybe.FromJust() != ABSENT;
}
bool should_enqueue_change_record = false;
if (object->map()->is_observed()) {
Maybe<bool> maybe = HasOwnElement(object, index);
- if (!maybe.has_value) return MaybeHandle<Object>();
- should_enqueue_change_record = maybe.value;
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ should_enqueue_change_record = maybe.FromJust();
if (should_enqueue_change_record) {
if (!GetOwnElementAccessorPair(object, index).is_null()) {
old_value = Handle<Object>::cast(factory->the_hole_value());
if (should_enqueue_change_record) {
Maybe<bool> maybe = HasOwnElement(object, index);
- if (!maybe.has_value) return MaybeHandle<Object>();
- if (!maybe.value) {
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ if (!maybe.FromJust()) {
Handle<String> name = factory->Uint32ToString(index);
RETURN_ON_EXCEPTION(
isolate, EnqueueChangeRecord(object, "delete", name, old_value),
Handle<String> key_string(String::cast(names->get(i)));
Maybe<PropertyAttributes> maybe =
JSReceiver::GetOwnPropertyAttributes(copy, key_string);
- DCHECK(maybe.has_value);
- PropertyAttributes attributes = maybe.value;
+ DCHECK(maybe.IsJust());
+ PropertyAttributes attributes = maybe.FromJust();
// Only deep copy fields from the object literal expression.
// In particular, don't try to copy the length attribute of
// an array.
Maybe<bool> maybe = HasOwnElement(object, index);
// Workaround for a GCC 4.4.3 bug which leads to "‘preexists’ may be used
// uninitialized in this function".
- if (!maybe.has_value) {
+ if (!maybe.IsJust()) {
DCHECK(false);
return isolate->factory()->undefined_value();
}
- preexists = maybe.value;
+ preexists = maybe.FromJust();
if (preexists && GetOwnElementAccessorPair(object, index).is_null()) {
old_value =
Object::GetElement(isolate, object, index).ToHandleChecked();
}
} else {
LookupIterator it(object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
- CHECK(GetPropertyAttributes(&it).has_value);
+ CHECK(GetPropertyAttributes(&it).IsJust());
preexists = it.IsFound();
if (preexists && (it.state() == LookupIterator::DATA ||
it.GetAccessors()->IsAccessorInfo())) {
} else {
// Lookup the name.
LookupIterator it(object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
- CHECK(GetPropertyAttributes(&it).has_value);
+ CHECK(GetPropertyAttributes(&it).IsJust());
// ES5 forbids turning a property into an accessor if it's not
// configurable. See 8.6.1 (Table 5).
if (it.IsFound() && (it.IsReadOnly() || !it.IsConfigurable())) {
List<uint32_t>* indices) {
Maybe<PropertyAttributes> maybe =
JSReceiver::GetOwnElementAttribute(object, index);
- DCHECK(maybe.has_value);
- DCHECK(maybe.value != ABSENT);
- if (maybe.value == DONT_DELETE) return false;
+ DCHECK(maybe.IsJust());
+ DCHECK(maybe.FromJust() != ABSENT);
+ if (maybe.FromJust() == DONT_DELETE) return false;
Handle<Object> value;
if (!JSObject::GetOwnElementAccessorPair(object, index).is_null()) {
value = Handle<Object>::cast(isolate->factory()->the_hole_value());
Maybe<PropertyAttributes> maybe =
JSReceiver::GetOwnElementAttribute(object, index);
- if (!maybe.has_value) return MaybeHandle<Object>();
- PropertyAttributes old_attributes = maybe.value;
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ PropertyAttributes old_attributes = maybe.FromJust();
Handle<Object> old_value = isolate->factory()->the_hole_value();
Handle<Object> old_length_handle;
Handle<String> name = isolate->factory()->Uint32ToString(index);
maybe = GetOwnElementAttribute(object, index);
- if (!maybe.has_value) return MaybeHandle<Object>();
- PropertyAttributes new_attributes = maybe.value;
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ PropertyAttributes new_attributes = maybe.FromJust();
if (old_attributes == ABSENT) {
if (object->IsJSArray() &&
Handle<Name> key) {
LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it);
- if (!maybe_result.has_value) return Nothing<bool>();
+ if (!maybe_result.IsJust()) return Nothing<bool>();
return Just(it.IsFound());
}
Maybe<PropertyAttributes> result =
GetElementAttributeWithoutInterceptor(object, object, index, false);
- return result.has_value ? Just(result.value != ABSENT) : Nothing<bool>();
+ return result.IsJust() ? Just(result.FromJust() != ABSENT) : Nothing<bool>();
}
Handle<Name> key) {
LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe_result = GetPropertyAttributes(&it);
- return maybe_result.has_value ? Just(it.state() == LookupIterator::ACCESSOR)
- : Nothing<bool>();
+ return maybe_result.IsJust() ? Just(it.state() == LookupIterator::ACCESSOR)
+ : Nothing<bool>();
}
for (uint32_t i = 0; i < length; ++i) {
HandleScope loop_scope(isolate);
Maybe<bool> maybe = JSReceiver::HasElement(receiver, i);
- if (!maybe.has_value) return false;
- if (maybe.value) {
+ if (!maybe.IsJust()) return false;
+ if (maybe.FromJust()) {
Handle<Object> element_value;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, element_value,
visitor->visit(j, element_value);
} else {
Maybe<bool> maybe = JSReceiver::HasElement(receiver, j);
- if (!maybe.has_value) return false;
- if (maybe.value) {
+ if (!maybe.IsJust()) return false;
+ if (maybe.FromJust()) {
// Call GetElement on receiver, not its prototype, or getters won't
// have the correct receiver.
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
visitor->visit(j, element_value);
} else {
Maybe<bool> maybe = JSReceiver::HasElement(receiver, j);
- if (!maybe.has_value) return false;
- if (maybe.value) {
+ if (!maybe.IsJust()) return false;
+ if (maybe.FromJust()) {
// Call GetElement on receiver, not its prototype, or getters won't
// have the correct receiver.
Handle<Object> element_value;
Handle<JSObject> ext(JSObject::cast(function_context->extension()));
Maybe<bool> maybe = JSReceiver::HasProperty(ext, variable_name);
- DCHECK(maybe.has_value);
- if (maybe.value) {
+ DCHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
// We don't expect this to do anything except replacing
// property value.
Runtime::SetObjectProperty(isolate, ext, variable_name, new_value,
if (context->has_extension()) {
Handle<JSObject> ext(JSObject::cast(context->extension()));
Maybe<bool> maybe = JSReceiver::HasProperty(ext, variable_name);
- DCHECK(maybe.has_value);
- if (maybe.value) {
+ DCHECK(maybe.IsJust());
+ if (maybe.FromJust()) {
// We don't expect this to do anything except replacing property value.
Runtime::DefineObjectProperty(ext, variable_name, new_value, NONE)
.Assert();
if (!function->shared()->is_function()) return target;
Maybe<bool> maybe = JSReceiver::HasOwnProperty(
target, isolate->factory()->arguments_string());
- if (!maybe.has_value) return MaybeHandle<JSObject>();
- if (maybe.value) return target;
+ if (!maybe.IsJust()) return MaybeHandle<JSObject>();
+ if (maybe.FromJust()) return target;
// FunctionGetArguments can't throw an exception.
Handle<JSObject> arguments =
// Get attributes.
Maybe<PropertyAttributes> maybe =
JSReceiver::GetOwnElementAttribute(obj, index);
- if (!maybe.has_value) return MaybeHandle<Object>();
- attrs = maybe.value;
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ attrs = maybe.FromJust();
if (attrs == ABSENT) return factory->undefined_value();
// Get AccessorPair if present.
// Get attributes.
LookupIterator it(obj, name, LookupIterator::HIDDEN);
Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it);
- if (!maybe.has_value) return MaybeHandle<Object>();
- attrs = maybe.value;
+ if (!maybe.IsJust()) return MaybeHandle<Object>();
+ attrs = maybe.FromJust();
if (attrs == ABSENT) return factory->undefined_value();
// Get AccessorPair if present.
DCHECK(!key->ToArrayIndex(&index));
LookupIterator it(object, key, LookupIterator::OWN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- if (!maybe.has_value) return isolate->heap()->exception();
+ if (!maybe.IsJust()) return isolate->heap()->exception();
RUNTIME_ASSERT(!it.IsFound());
#endif
Handle<JSObject> object,
Handle<Name> key) {
Maybe<bool> maybe = JSReceiver::HasOwnProperty(object, key);
- if (!maybe.has_value) return isolate->heap()->exception();
- if (maybe.value) return isolate->heap()->true_value();
+ if (!maybe.IsJust()) return isolate->heap()->exception();
+ if (maybe.FromJust()) return isolate->heap()->true_value();
// Handle hidden prototypes. If there's a hidden prototype above this thing
// then we have to check it for properties, because they are supposed to
// look like they are on this object.
} else {
maybe = JSObject::HasRealNamedProperty(js_obj, key);
}
- if (!maybe.has_value) return isolate->heap()->exception();
+ if (!maybe.IsJust()) return isolate->heap()->exception();
DCHECK(!isolate->has_pending_exception());
- if (maybe.value) {
+ if (maybe.FromJust()) {
return isolate->heap()->true_value();
}
Map* map = js_obj->map();
CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
Maybe<bool> maybe = JSReceiver::HasProperty(receiver, key);
- if (!maybe.has_value) return isolate->heap()->exception();
- return isolate->heap()->ToBoolean(maybe.value);
+ if (!maybe.IsJust()) return isolate->heap()->exception();
+ return isolate->heap()->ToBoolean(maybe.FromJust());
}
CONVERT_SMI_ARG_CHECKED(index, 1);
Maybe<bool> maybe = JSReceiver::HasElement(receiver, index);
- if (!maybe.has_value) return isolate->heap()->exception();
- return isolate->heap()->ToBoolean(maybe.value);
+ if (!maybe.IsJust()) return isolate->heap()->exception();
+ return isolate->heap()->ToBoolean(maybe.FromJust());
}
Maybe<PropertyAttributes> maybe =
JSReceiver::GetOwnPropertyAttributes(object, key);
- if (!maybe.has_value) return isolate->heap()->exception();
- if (maybe.value == ABSENT) maybe.value = DONT_ENUM;
- return isolate->heap()->ToBoolean((maybe.value & DONT_ENUM) == 0);
+ if (!maybe.IsJust()) return isolate->heap()->exception();
+ if (maybe.FromJust() == ABSENT) maybe = Just(DONT_ENUM);
+ return isolate->heap()->ToBoolean((maybe.FromJust() & DONT_ENUM) == 0);
}
// Do the lookup own properties only, see ES5 erratum.
LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- if (!maybe.has_value) return isolate->heap()->exception();
+ if (!maybe.IsJust()) return isolate->heap()->exception();
if (it.IsFound()) {
- PropertyAttributes old_attributes = maybe.value;
+ PropertyAttributes old_attributes = maybe.FromJust();
// The name was declared before; check for conflicting re-declarations.
if (is_const) return ThrowRedeclarationError(isolate, name);
// Lookup the property as own on the global object.
LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- DCHECK(maybe.has_value);
- PropertyAttributes old_attributes = maybe.value;
+ DCHECK(maybe.IsJust());
+ PropertyAttributes old_attributes = maybe.FromJust();
PropertyAttributes attr =
static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- if (!maybe.has_value) return isolate->heap()->exception();
- PropertyAttributes old_attributes = maybe.value;
+ if (!maybe.IsJust()) return isolate->heap()->exception();
+ PropertyAttributes old_attributes = maybe.FromJust();
// Ignore if we can't reconfigure the value.
if ((old_attributes & DONT_DELETE) != 0) {
LookupIterator it(global_object, name,
LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
- if (!maybe.has_value) return isolate->heap()->exception();
- if ((maybe.value & DONT_DELETE) != 0) {
+ if (!maybe.IsJust()) return isolate->heap()->exception();
+ if ((maybe.FromJust() & DONT_DELETE) != 0) {
return ThrowRedeclarationError(isolate, name);
}
Maybe<PropertyAttribute> attr =
instance->GetRealNamedPropertyAttributes(v8_str("f"));
CHECK(!try_catch.HasCaught());
- CHECK(attr.has_value);
- CHECK_EQ(attr.value, None);
+ CHECK(Just(None) == attr);
result = another->GetRealNamedProperty(v8_str("f"));
CHECK(try_catch.HasCaught());
attr = another->GetRealNamedPropertyAttributes(v8_str("f"));
CHECK(!try_catch.HasCaught());
- CHECK(attr.has_value);
- CHECK_EQ(attr.value, None);
+ CHECK(Just(None) == attr);
result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f"));
CHECK(try_catch.HasCaught());
attr = another->GetRealNamedPropertyAttributesInPrototypeChain(v8_str("f"));
CHECK(!try_catch.HasCaught());
- CHECK(attr.has_value);
- CHECK_EQ(attr.value, None);
+ CHECK(Just(None) == attr);
result = another->Get(v8_str("f"));
CHECK(try_catch.HasCaught());
attr = with_js_getter->GetRealNamedPropertyAttributes(v8_str("f"));
CHECK(!try_catch.HasCaught());
- CHECK(attr.has_value);
- CHECK_EQ(attr.value, None);
+ CHECK(Just(None) == attr);
result = with_js_getter->Get(v8_str("f"));
CHECK(try_catch.HasCaught());
#include "test/cctest/cctest.h"
using namespace v8::internal;
+using v8::Just;
static void CheckMap(Map* map, int type, int instance_size) {
CHECK(map->IsHeapObject());
Handle<String> object_string = Handle<String>::cast(factory->Object_string());
Handle<GlobalObject> global(CcTest::i_isolate()->context()->global_object());
- v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, object_string);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(global, object_string));
// Check ToString for oddballs
CheckOddball(isolate, heap->true_value(), "true");
heap->CollectGarbage(NEW_SPACE);
// Function should be alive.
- v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, name);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(global, name));
// Check function is retained.
Handle<Object> func_value =
Object::GetProperty(global, name).ToHandleChecked();
// After gc, it should survive.
heap->CollectGarbage(NEW_SPACE);
- maybe = JSReceiver::HasOwnProperty(global, obj_name);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(global, obj_name));
Handle<Object> obj =
Object::GetProperty(global, obj_name).ToHandleChecked();
CHECK(obj->IsJSObject());
Handle<Smi> two(Smi::FromInt(2), isolate);
// check for empty
- v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(!maybe.value);
+ CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
// add first
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
// delete first
JSReceiver::DeleteProperty(obj, first, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(!maybe.value);
+ CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
// add first and then second
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
- maybe = JSReceiver::HasOwnProperty(obj, second);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
// delete first and then second
JSReceiver::DeleteProperty(obj, first, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, second);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
JSReceiver::DeleteProperty(obj, second, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(!maybe.value);
- maybe = JSReceiver::HasOwnProperty(obj, second);
- CHECK(maybe.has_value);
- CHECK(!maybe.value);
+ CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
+ CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, second));
// add first and then second
JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
- maybe = JSReceiver::HasOwnProperty(obj, second);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
// delete second and then first
JSReceiver::DeleteProperty(obj, second, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
JSReceiver::DeleteProperty(obj, first, SLOPPY).Check();
- maybe = JSReceiver::HasOwnProperty(obj, first);
- CHECK(maybe.has_value);
- CHECK(!maybe.value);
- maybe = JSReceiver::HasOwnProperty(obj, second);
- CHECK(maybe.has_value);
- CHECK(!maybe.value);
+ CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
+ CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, second));
// check string and internalized string match
const char* string1 = "fisk";
Handle<String> s1 = factory->NewStringFromAsciiChecked(string1);
JSReceiver::SetProperty(obj, s1, one, SLOPPY).Check();
Handle<String> s1_string = factory->InternalizeUtf8String(string1);
- maybe = JSReceiver::HasOwnProperty(obj, s1_string);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, s1_string));
// check internalized string and string match
const char* string2 = "fugl";
Handle<String> s2_string = factory->InternalizeUtf8String(string2);
JSReceiver::SetProperty(obj, s2_string, one, SLOPPY).Check();
Handle<String> s2 = factory->NewStringFromAsciiChecked(string2);
- maybe = JSReceiver::HasOwnProperty(obj, s2);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, s2));
}
#include "test/cctest/cctest.h"
using namespace v8::internal;
+using v8::Just;
TEST(MarkingDeque) {
{ HandleScope scope(isolate);
Handle<String> func_name = factory->InternalizeUtf8String("theFunction");
- v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, func_name);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(global, func_name));
Handle<Object> func_value =
Object::GetProperty(global, func_name).ToHandleChecked();
CHECK(func_value->IsJSFunction());
{ HandleScope scope(isolate);
Handle<String> obj_name = factory->InternalizeUtf8String("theObject");
- v8::Maybe<bool> maybe = JSReceiver::HasOwnProperty(global, obj_name);
- CHECK(maybe.has_value);
- CHECK(maybe.value);
+ CHECK(Just(true) == JSReceiver::HasOwnProperty(global, obj_name));
Handle<Object> object =
Object::GetProperty(global, obj_name).ToHandleChecked();
CHECK(object->IsJSObject());