Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Unified Diff: src/objects.h

Issue 1394983005: Restructure Object::SetProperty and related functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Redo again, now using ShouldThrow argument. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/objects.cc » ('j') | src/objects.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 100da7d766e86c8f57b7712b6216d0b72fc39dfa..56d88c6714ac92abb22062a0830536110964c53a 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1025,6 +1025,8 @@ class Object {
HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
#undef IS_TYPE_FUNCTION_DECL
+ enum ShouldThrow { THROW_ON_ERROR, DONT_THROW };
+
// A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
// a keyed store is of the form a[expression] = foo.
enum StoreFromKeyed {
@@ -1216,12 +1218,23 @@ class Object {
MUST_USE_RESULT static MaybeHandle<Object> GetProperty(
LookupIterator* it, LanguageMode language_mode = SLOPPY);
- // Implementation of [[Put]], ECMA-262 5th edition, section 8.12.5.
+
+ // ES6 [[Set]] (when passed DONT_THROW)
+ // Invariants for this and related functions (unless stated otherwise):
+ // 1) When the result is Nothing, an exception is pending.
+ // 2) When passed THROW_ON_ERROR, the result is never Just(false).
+ // In some cases, an exception is thrown regardless of the ShouldThrow
+ // argument. These cases are either in accordance with the spec or not
+ // covered by it (eg., concerning API callbacks).
+ MUST_USE_RESULT static Maybe<bool> SetProperty(LookupIterator* it,
+ Handle<Object> value,
+ LanguageMode language_mode,
+ ShouldThrow should_throw,
+ StoreFromKeyed store_mode);
MUST_USE_RESULT static MaybeHandle<Object> SetProperty(
Handle<Object> object, Handle<Name> name, Handle<Object> value,
LanguageMode language_mode,
StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED);
-
MUST_USE_RESULT static MaybeHandle<Object> SetProperty(
LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
StoreFromKeyed store_mode);
@@ -1235,24 +1248,30 @@ class Object {
MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty(
Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
LanguageMode language_mode);
- MUST_USE_RESULT static MaybeHandle<Object> CannotCreateProperty(
- LookupIterator* it, Handle<Object> value, LanguageMode language_mode);
- MUST_USE_RESULT static MaybeHandle<Object> CannotCreateProperty(
+ MUST_USE_RESULT static Maybe<bool> CannotCreateProperty(
Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
- Handle<Object> value, LanguageMode language_mode);
- MUST_USE_RESULT static MaybeHandle<Object> WriteToReadOnlyProperty(
- LookupIterator* it, Handle<Object> value, LanguageMode language_mode);
- MUST_USE_RESULT static MaybeHandle<Object> WriteToReadOnlyProperty(
+ Handle<Object> value, LanguageMode language_mode,
+ ShouldThrow should_throw);
+ MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty(
+ LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
+ ShouldThrow should_throw);
+ MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty(
Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
- Handle<Object> value, LanguageMode language_mode);
+ Handle<Object> value, LanguageMode language_mode,
+ ShouldThrow should_throw);
MUST_USE_RESULT static MaybeHandle<Object> RedefineNonconfigurableProperty(
Isolate* isolate, Handle<Object> name, Handle<Object> value,
LanguageMode language_mode);
- MUST_USE_RESULT static MaybeHandle<Object> SetDataProperty(
- LookupIterator* it, Handle<Object> value);
+ MUST_USE_RESULT static Maybe<bool> SetDataProperty(LookupIterator* it,
+ Handle<Object> value,
+ ShouldThrow should_throw);
MUST_USE_RESULT static MaybeHandle<Object> AddDataProperty(
LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
LanguageMode language_mode, StoreFromKeyed store_mode);
+ MUST_USE_RESULT static Maybe<bool> AddDataProperty(
+ LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
+ LanguageMode language_mode, ShouldThrow should_throw,
+ StoreFromKeyed store_mode);
MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
Handle<Object> object, Handle<Name> name,
LanguageMode language_mode = SLOPPY);
@@ -1268,16 +1287,16 @@ class Object {
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor(
LookupIterator* it, LanguageMode language_mode);
- MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithAccessor(
- LookupIterator* it, Handle<Object> value, LanguageMode language_mode);
+ MUST_USE_RESULT static Maybe<bool> SetPropertyWithAccessor(
+ LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
+ ShouldThrow should_throw);
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter(
Handle<Object> receiver,
Handle<JSReceiver> getter);
- MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithDefinedSetter(
- Handle<Object> receiver,
- Handle<JSReceiver> setter,
- Handle<Object> value);
+ MUST_USE_RESULT static Maybe<bool> SetPropertyWithDefinedSetter(
+ Handle<Object> receiver, Handle<JSReceiver> setter, Handle<Object> value,
+ ShouldThrow should_throw);
MUST_USE_RESULT static inline MaybeHandle<Object> GetElement(
Isolate* isolate, Handle<Object> object, uint32_t index,
@@ -1370,9 +1389,10 @@ class Object {
Map* GetRootMap(Isolate* isolate);
// Helper for SetProperty and SetSuperProperty.
- MUST_USE_RESULT static MaybeHandle<Object> SetPropertyInternal(
+ // Return value is only meaningful if [found] is set to true on return.
+ MUST_USE_RESULT static Maybe<bool> SetPropertyInternal(
LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
- StoreFromKeyed store_mode, bool* found);
+ ShouldThrow should_throw, StoreFromKeyed store_mode, bool* found);
DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
};
@@ -1791,9 +1811,6 @@ enum AccessorComponent {
enum KeyFilter { SKIP_SYMBOLS, INCLUDE_SYMBOLS };
-enum ShouldThrow { THROW_ON_ERROR, DONT_THROW };
-
-
// JSReceiver includes types on which properties can be defined, i.e.,
// JSObject and JSProxy.
class JSReceiver: public HeapObject {
@@ -2002,8 +2019,9 @@ class JSObject: public JSReceiver {
static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object,
uint32_t limit);
- MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithInterceptor(
- LookupIterator* it, Handle<Object> value);
+ // Beware: This may return Nothing even if there is no pending exception.
rossberg 2015/10/14 15:59:06 In what cases?
neis 2015/10/21 14:42:25 I actually changed the code now such that it behav
+ MUST_USE_RESULT static Maybe<bool> SetPropertyWithInterceptor(
+ LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
// SetLocalPropertyIgnoreAttributes converts callbacks to fields. We need to
// grant an exemption to ExecutableAccessor callbacks in some cases.
@@ -2039,6 +2057,9 @@ class JSObject: public JSReceiver {
static void AddProperty(Handle<JSObject> object, Handle<Name> name,
Handle<Object> value, PropertyAttributes attributes);
+ MUST_USE_RESULT static Maybe<bool> AddDataElement(
+ Handle<JSObject> receiver, uint32_t index, Handle<Object> value,
+ PropertyAttributes attributes, ShouldThrow should_throw);
MUST_USE_RESULT static MaybeHandle<Object> AddDataElement(
Handle<JSObject> receiver, uint32_t index, Handle<Object> value,
PropertyAttributes attributes);
@@ -2315,6 +2336,7 @@ class JSObject: public JSReceiver {
bool ReferencesObject(Object* obj);
// Disallow further properties to be added to the oject.
+ // TODO(neis): Use ShouldThrow to be consistent with SetProperty et al.
MUST_USE_RESULT static Maybe<bool> PreventExtensionsInternal(
Handle<JSObject> object); // ES [[PreventExtensions]]
MUST_USE_RESULT static MaybeHandle<Object> PreventExtensions(
@@ -2465,8 +2487,8 @@ class JSObject: public JSReceiver {
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck(
LookupIterator* it);
- MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithFailedAccessCheck(
- LookupIterator* it, Handle<Object> value);
+ MUST_USE_RESULT static Maybe<bool> SetPropertyWithFailedAccessCheck(
+ LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
// Add a property to a slow-case object.
static void AddSlowProperty(Handle<JSObject> object,
@@ -9501,20 +9523,23 @@ class JSProxy: public JSReceiver {
// If the handler defines an accessor property with a setter, invoke it.
// If it defines an accessor property without a setter, or a data property
- // that is read-only, throw. In all these cases set '*done' to true,
- // otherwise set it to false.
+ // that is read-only, fail. In all these cases set '*done' to true.
+ // Otherwise set it to false, in which case the return value is not
+ // meaningful.
MUST_USE_RESULT
- static MaybeHandle<Object> SetPropertyViaPrototypesWithHandler(
+ static Maybe<bool> SetPropertyViaPrototypesWithHandler(
Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
- Handle<Object> value, LanguageMode language_mode, bool* done);
+ Handle<Object> value, LanguageMode language_mode,
+ ShouldThrow should_throw, bool* done);
MUST_USE_RESULT static Maybe<PropertyAttributes>
GetPropertyAttributesWithHandler(Handle<JSProxy> proxy,
Handle<Object> receiver,
Handle<Name> name);
- MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithHandler(
+ MUST_USE_RESULT static Maybe<bool> SetPropertyWithHandler(
Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name,
- Handle<Object> value, LanguageMode language_mode);
+ Handle<Object> value, LanguageMode language_mode,
+ ShouldThrow should_throw);
// Turn the proxy into an (empty) JSObject.
static void Fix(Handle<JSProxy> proxy);
@@ -10048,7 +10073,6 @@ class JSArray: public JSObject {
static bool HasReadOnlyLength(Handle<JSArray> array);
static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index);
- static MaybeHandle<Object> ReadOnlyLengthError(Handle<JSArray> array);
// Initialize the array with the given capacity. The function may
// fail due to out-of-memory situations, but only if the requested
« no previous file with comments | « no previous file | src/objects.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698