From 3f8ed7c30d2b3d3f1693c8a3b26f5e76d96e25ae Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Mon, 20 Feb 2012 10:17:25 +0000 Subject: [PATCH] Add a missing check for a failure result. Function calls that may return a failure must use the result. Enforce this by adding missing MUST_USE_RESULT to their declarations. Review URL: https://chromiumcodereview.appspot.com/9421032 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10748 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/bootstrapper.cc | 12 +++-- src/elements.cc | 4 +- src/objects.h | 121 ++++++++++++++++++++++++-------------------- 3 files changed, 78 insertions(+), 59 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index b77e46751..0f5b9c84a 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -196,7 +196,7 @@ class Genesis BASE_EMBEDDED { // detached from the other objects in the snapshot. void HookUpInnerGlobal(Handle inner_global); // New context initialization. Used for creating a context from scratch. - void InitializeGlobal(Handle inner_global, + bool InitializeGlobal(Handle inner_global, Handle empty_function); void InitializeExperimentalGlobal(); // Installs the contents of the native .js files on the global objects. @@ -828,7 +828,7 @@ void Genesis::HookUpInnerGlobal(Handle inner_global) { // This is only called if we are not using snapshots. The equivalent // work in the snapshot case is done in HookUpInnerGlobal. -void Genesis::InitializeGlobal(Handle inner_global, +bool Genesis::InitializeGlobal(Handle inner_global, Handle empty_function) { // --- G l o b a l C o n t e x t --- // Use the empty function as closure (no scope info). @@ -1032,7 +1032,10 @@ void Genesis::InitializeGlobal(Handle inner_global, Handle name = factory->NewStringFromAscii(CStrVector("JSON")); Handle cons = factory->NewFunction(name, factory->the_hole_value()); - cons->SetInstancePrototype(global_context()->initial_object_prototype()); + { MaybeObject* result = cons->SetInstancePrototype( + global_context()->initial_object_prototype()); + if (result->IsFailure()) return false; + } cons->SetInstanceClassName(*name); Handle json_object = factory->NewJSObject(cons, TENURED); ASSERT(json_object->IsJSObject()); @@ -1243,6 +1246,7 @@ void Genesis::InitializeGlobal(Handle inner_global, global_context()->set_random_seed(*zeroed_byte_array); memset(zeroed_byte_array->GetDataStartAddress(), 0, kRandomStateSize); } + return true; } @@ -2314,7 +2318,7 @@ Genesis::Genesis(Isolate* isolate, Handle global_proxy = CreateNewGlobals(global_template, global_object, &inner_global); HookUpGlobalProxy(inner_global, global_proxy); - InitializeGlobal(inner_global, empty_function); + if (!InitializeGlobal(inner_global, empty_function)) return; InstallJSFunctionResultCaches(); InitializeNormalizedMapCaches(); if (!InstallNatives()) return; diff --git a/src/elements.cc b/src/elements.cc index b62e144e3..c15c44d2e 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -911,7 +911,9 @@ MaybeObject* ElementsAccessorBase:: MaybeObject* maybe_obj = array->GetHeap()->AllocateFixedArray(1); if (!maybe_obj->To(&new_backing_store)) return maybe_obj; new_backing_store->set(0, length); - array->SetContent(new_backing_store); + { MaybeObject* result = array->SetContent(new_backing_store); + if (result->IsFailure()) return result; + } return array; } diff --git a/src/objects.h b/src/objects.h index e833c3311..8b994eaed 100644 --- a/src/objects.h +++ b/src/objects.h @@ -928,10 +928,11 @@ class Object : public MaybeObject { JSReceiver* getter); static Handle GetElement(Handle object, uint32_t index); - inline MaybeObject* GetElement(uint32_t index); + MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index); // For use when we know that no exception can be thrown. inline Object* GetElementNoExceptionThrown(uint32_t index); - MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); + MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver, + uint32_t index); // Return the object's prototype (might be Heap::null_value()). Object* GetPrototype(); @@ -1603,22 +1604,23 @@ class JSObject: public JSReceiver { MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); // Used from Object::GetProperty(). - MaybeObject* GetPropertyWithFailedAccessCheck( + MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck( Object* receiver, LookupResult* result, String* name, PropertyAttributes* attributes); - MaybeObject* GetPropertyWithInterceptor( + MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor( JSReceiver* receiver, String* name, PropertyAttributes* attributes); - MaybeObject* GetPropertyPostInterceptor( + MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor( + JSReceiver* receiver, + String* name, + PropertyAttributes* attributes); + MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor( JSReceiver* receiver, String* name, PropertyAttributes* attributes); - MaybeObject* GetLocalPropertyPostInterceptor(JSReceiver* receiver, - String* name, - PropertyAttributes* attributes); // Returns true if this is an instance of an api function and has // been modified since it was created. May give false positives. @@ -1668,18 +1670,21 @@ class JSObject: public JSReceiver { inline void ValidateSmiOnlyElements(); // Makes sure that this object can contain HeapObject as elements. - inline MaybeObject* EnsureCanContainHeapObjectElements(); + MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements(); // Makes sure that this object can contain the specified elements. - inline MaybeObject* EnsureCanContainElements(Object** elements, - uint32_t count, - EnsureElementsMode mode); - inline MaybeObject* EnsureCanContainElements(FixedArrayBase* elements, - EnsureElementsMode mode); - MaybeObject* EnsureCanContainElements(Arguments* arguments, - uint32_t first_arg, - uint32_t arg_count, - EnsureElementsMode mode); + MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( + Object** elements, + uint32_t count, + EnsureElementsMode mode); + MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( + FixedArrayBase* elements, + EnsureElementsMode mode); + MUST_USE_RESULT MaybeObject* EnsureCanContainElements( + Arguments* arguments, + uint32_t first_arg, + uint32_t arg_count, + EnsureElementsMode mode); // Do we want to keep the elements in fast case when increasing the // capacity? @@ -1762,7 +1767,8 @@ class JSObject: public JSReceiver { // Returns the index'th element. // The undefined object if index is out of bounds. - MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); + MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver, + uint32_t index); enum SetFastElementsCapacityMode { kAllowSmiOnlyElements, @@ -2069,11 +2075,12 @@ class JSObject: public JSReceiver { Object* structure, uint32_t index, Object* holder); - MaybeObject* SetElementWithCallback(Object* structure, - uint32_t index, - Object* value, - JSObject* holder, - StrictModeFlag strict_mode); + MUST_USE_RESULT MaybeObject* SetElementWithCallback( + Object* structure, + uint32_t index, + Object* value, + JSObject* holder, + StrictModeFlag strict_mode); MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( uint32_t index, Object* value, @@ -2140,9 +2147,11 @@ class JSObject: public JSReceiver { // If no hidden properties object has been put on this object, // return undefined, unless create_if_absent is true, in which case // a new dictionary is created, added to this object, and returned. - MaybeObject* GetHiddenPropertiesDictionary(bool create_if_absent); + MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary( + bool create_if_absent); // Updates the existing hidden properties dictionary. - MaybeObject* SetHiddenPropertiesDictionary(StringDictionary* dictionary); + MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary( + StringDictionary* dictionary); DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); }; @@ -2289,7 +2298,7 @@ class FixedDoubleArray: public FixedArrayBase { // Setter and getter for elements. inline double get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, double value); inline void set_the_hole(int index); @@ -3614,7 +3623,7 @@ class ExternalPixelArray: public ExternalArray { // Setter and getter. inline uint8_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, uint8_t value); // This accessor applies the correct conversion from Smi, HeapNumber and @@ -3643,12 +3652,12 @@ class ExternalByteArray: public ExternalArray { public: // Setter and getter. inline int8_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, int8_t value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalByteArray* cast(Object* obj); @@ -3672,12 +3681,12 @@ class ExternalUnsignedByteArray: public ExternalArray { public: // Setter and getter. inline uint8_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, uint8_t value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalUnsignedByteArray* cast(Object* obj); @@ -3701,12 +3710,12 @@ class ExternalShortArray: public ExternalArray { public: // Setter and getter. inline int16_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, int16_t value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalShortArray* cast(Object* obj); @@ -3730,12 +3739,12 @@ class ExternalUnsignedShortArray: public ExternalArray { public: // Setter and getter. inline uint16_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, uint16_t value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalUnsignedShortArray* cast(Object* obj); @@ -3759,12 +3768,12 @@ class ExternalIntArray: public ExternalArray { public: // Setter and getter. inline int32_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, int32_t value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalIntArray* cast(Object* obj); @@ -3788,12 +3797,12 @@ class ExternalUnsignedIntArray: public ExternalArray { public: // Setter and getter. inline uint32_t get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, uint32_t value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalUnsignedIntArray* cast(Object* obj); @@ -3817,12 +3826,12 @@ class ExternalFloatArray: public ExternalArray { public: // Setter and getter. inline float get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, float value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalFloatArray* cast(Object* obj); @@ -3846,12 +3855,12 @@ class ExternalDoubleArray: public ExternalArray { public: // Setter and getter. inline double get_scalar(int index); - inline MaybeObject* get(int index); + MUST_USE_RESULT inline MaybeObject* get(int index); inline void set(int index, double value); // This accessor applies the correct conversion from Smi, HeapNumber // and undefined. - MaybeObject* SetValue(uint32_t index, Object* value); + MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); // Casting. static inline ExternalDoubleArray* cast(Object* obj); @@ -4769,7 +4778,8 @@ class Map: public HeapObject { Object* GetPrototypeTransition(Object* prototype); - MaybeObject* PutPrototypeTransition(Object* prototype, Map* map); + MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype, + Map* map); static const int kMaxPreAllocatedPropertyFields = 255; @@ -5661,7 +5671,8 @@ class JSFunction: public JSObject { // The initial map for an object created by this constructor. inline Map* initial_map(); inline void set_initial_map(Map* value); - inline MaybeObject* set_initial_map_and_cache_transitions(Map* value); + MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions( + Map* value); inline bool has_initial_map(); // Get and set the prototype property on a JSFunction. If the @@ -5672,7 +5683,7 @@ class JSFunction: public JSObject { inline bool has_instance_prototype(); inline Object* prototype(); inline Object* instance_prototype(); - MaybeObject* SetInstancePrototype(Object* value); + MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value); MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); // After prototype is removed, it will not be created when accessed, and @@ -6185,12 +6196,14 @@ class CompilationCacheTable: public HashTable