Commit 1fcedda6 authored by Dan Carney's avatar Dan Carney

convert object::* to return maybe values

BUG=v8:3929
LOG=y
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/971693002

Cr-Commit-Position: refs/heads/master@{#26940}
parent 5f3914fc
...@@ -434,17 +434,12 @@ class MaybeLocal { ...@@ -434,17 +434,12 @@ class MaybeLocal {
TYPE_CHECK(T, S); TYPE_CHECK(T, S);
} }
V8_INLINE bool IsEmpty() { return val_ == nullptr; } V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
template <class S> template <class S>
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const { V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
if (val_ == NULL) { out->val_ = IsEmpty() ? nullptr : this->val_;
out->val_ = nullptr; return IsEmpty();
return false;
} else {
out->val_ = this->val_;
return true;
}
} }
V8_INLINE Local<T> ToLocalChecked() { V8_INLINE Local<T> ToLocalChecked() {
...@@ -452,6 +447,11 @@ class MaybeLocal { ...@@ -452,6 +447,11 @@ class MaybeLocal {
return Local<T>(val_); return Local<T>(val_);
} }
template <class S>
V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
return IsEmpty() ? default_value : Local<S>(val_);
}
private: private:
T* val_; T* val_;
}; };
...@@ -2490,9 +2490,13 @@ enum AccessControl { ...@@ -2490,9 +2490,13 @@ enum AccessControl {
*/ */
class V8_EXPORT Object : public Value { class V8_EXPORT Object : public Value {
public: public:
// TODO(dcarney): deprecate
bool Set(Handle<Value> key, Handle<Value> value); bool Set(Handle<Value> key, Handle<Value> value);
Maybe<bool> Set(Local<Context> context, Local<Value> key, Local<Value> value);
// TODO(dcarney): deprecate
bool Set(uint32_t index, Handle<Value> value); bool Set(uint32_t index, Handle<Value> value);
Maybe<bool> Set(Local<Context> context, uint32_t index, Local<Value> value);
// Sets an own property on this object bypassing interceptors and // Sets an own property on this object bypassing interceptors and
// overriding accessors or read-only properties. // overriding accessors or read-only properties.
...@@ -2502,46 +2506,74 @@ class V8_EXPORT Object : public Value { ...@@ -2502,46 +2506,74 @@ class V8_EXPORT Object : public Value {
// will only be returned if the interceptor doesn't return a value. // will only be returned if the interceptor doesn't return a value.
// //
// Note also that this only works for named properties. // Note also that this only works for named properties.
// TODO(dcarney): deprecate
bool ForceSet(Handle<Value> key, bool ForceSet(Handle<Value> key,
Handle<Value> value, Handle<Value> value,
PropertyAttribute attribs = None); PropertyAttribute attribs = None);
Maybe<bool> ForceSet(Local<Context> context, Local<Value> key,
Local<Value> value, PropertyAttribute attribs = None);
// TODO(dcarney): deprecate
Local<Value> Get(Handle<Value> key); Local<Value> Get(Handle<Value> key);
MaybeLocal<Value> Get(Local<Context> context, Local<Value> key);
// TODO(dcarney): deprecate
Local<Value> Get(uint32_t index); Local<Value> Get(uint32_t index);
MaybeLocal<Value> Get(Local<Context> context, uint32_t index);
/** /**
* Gets the property attributes of a property which can be None or * Gets the property attributes of a property which can be None or
* any combination of ReadOnly, DontEnum and DontDelete. Returns * any combination of ReadOnly, DontEnum and DontDelete. Returns
* None when the property doesn't exist. * None when the property doesn't exist.
*/ */
// TODO(dcarney): deprecate
PropertyAttribute GetPropertyAttributes(Handle<Value> key); PropertyAttribute GetPropertyAttributes(Handle<Value> key);
Maybe<PropertyAttribute> GetPropertyAttributes(Local<Context> context,
Local<Value> key);
/** /**
* Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3. * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
*/ */
// TODO(dcarney): deprecate
Local<Value> GetOwnPropertyDescriptor(Local<String> key); Local<Value> GetOwnPropertyDescriptor(Local<String> key);
MaybeLocal<Value> GetOwnPropertyDescriptor(Local<Context> context,
Local<String> key);
// TODO(dcarney): deprecate
bool Has(Handle<Value> key); bool Has(Handle<Value> key);
Maybe<bool> Has(Local<Context> context, Local<Value> key);
// TODO(dcarney): deprecate
bool Delete(Handle<Value> key); bool Delete(Handle<Value> key);
Maybe<bool> Delete(Local<Context> context, Local<Value> key);
// TODO(dcarney): deprecate
bool Has(uint32_t index); bool Has(uint32_t index);
Maybe<bool> Has(Local<Context> context, uint32_t index);
// TODO(dcarney): deprecate
bool Delete(uint32_t index); bool Delete(uint32_t index);
Maybe<bool> Delete(Local<Context> context, uint32_t index);
// TODO(dcarney): deprecate
bool SetAccessor(Handle<String> name, bool SetAccessor(Handle<String> name,
AccessorGetterCallback getter, AccessorGetterCallback getter,
AccessorSetterCallback setter = 0, AccessorSetterCallback setter = 0,
Handle<Value> data = Handle<Value>(), Handle<Value> data = Handle<Value>(),
AccessControl settings = DEFAULT, AccessControl settings = DEFAULT,
PropertyAttribute attribute = None); PropertyAttribute attribute = None);
bool SetAccessor(Handle<Name> name, // TODO(dcarney): deprecate
AccessorNameGetterCallback getter, bool SetAccessor(Handle<Name> name, AccessorNameGetterCallback getter,
AccessorNameSetterCallback setter = 0, AccessorNameSetterCallback setter = 0,
Handle<Value> data = Handle<Value>(), Handle<Value> data = Handle<Value>(),
AccessControl settings = DEFAULT, AccessControl settings = DEFAULT,
PropertyAttribute attribute = None); PropertyAttribute attribute = None);
Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
AccessorNameGetterCallback getter,
AccessorNameSetterCallback setter = 0,
MaybeLocal<Value> data = MaybeLocal<Value>(),
AccessControl settings = DEFAULT,
PropertyAttribute attribute = None);
void SetAccessorProperty(Local<Name> name, void SetAccessorProperty(Local<Name> name,
Local<Function> getter, Local<Function> getter,
...@@ -5731,6 +5763,7 @@ class V8_EXPORT V8 { ...@@ -5731,6 +5763,7 @@ class V8_EXPORT V8 {
template <class T> template <class T>
class Maybe { class Maybe {
public: public:
V8_INLINE bool IsNothing() const { return !has_value; }
V8_INLINE bool IsJust() const { return has_value; } V8_INLINE bool IsJust() const { return has_value; }
V8_INLINE T FromJust() const { V8_INLINE T FromJust() const {
......
This diff is collapsed.
...@@ -17915,18 +17915,22 @@ THREADED_TEST(CreationContext) { ...@@ -17915,18 +17915,22 @@ THREADED_TEST(CreationContext) {
instance2 = func2->NewInstance(); instance2 = func2->NewInstance();
} }
CHECK(object1->CreationContext() == context1); {
CheckContextId(object1, 1); Handle<Context> other_context = Context::New(isolate);
CHECK(func1->CreationContext() == context1); Context::Scope scope(other_context);
CheckContextId(func1, 1); CHECK(object1->CreationContext() == context1);
CHECK(instance1->CreationContext() == context1); CheckContextId(object1, 1);
CheckContextId(instance1, 1); CHECK(func1->CreationContext() == context1);
CHECK(object2->CreationContext() == context2); CheckContextId(func1, 1);
CheckContextId(object2, 2); CHECK(instance1->CreationContext() == context1);
CHECK(func2->CreationContext() == context2); CheckContextId(instance1, 1);
CheckContextId(func2, 2); CHECK(object2->CreationContext() == context2);
CHECK(instance2->CreationContext() == context2); CheckContextId(object2, 2);
CheckContextId(instance2, 2); CHECK(func2->CreationContext() == context2);
CheckContextId(func2, 2);
CHECK(instance2->CreationContext() == context2);
CheckContextId(instance2, 2);
}
{ {
Context::Scope scope(context1); Context::Scope scope(context1);
...@@ -17973,6 +17977,8 @@ THREADED_TEST(CreationContextOfJsFunction) { ...@@ -17973,6 +17977,8 @@ THREADED_TEST(CreationContextOfJsFunction) {
function = CompileRun("function foo() {}; foo").As<Object>(); function = CompileRun("function foo() {}; foo").As<Object>();
} }
Handle<Context> other_context = Context::New(CcTest::isolate());
Context::Scope scope(other_context);
CHECK(function->CreationContext() == context); CHECK(function->CreationContext() == context);
CheckContextId(function, 1); CheckContextId(function, 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment