From: rossberg@chromium.org Date: Tue, 6 Nov 2012 12:30:22 +0000 (+0000) Subject: Object.observe: implement map bit and functions to access it. X-Git-Tag: upstream/4.7.83~15733 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=beaccd74cb67073f3c194047a0f73a2ff7b8735c;p=platform%2Fupstream%2Fv8.git Object.observe: implement map bit and functions to access it. R=danno@chromium.org BUG= Review URL: https://codereview.chromium.org/11276028 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12866 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/objects-inl.h b/src/objects-inl.h index bbd1a09..fe8964f 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -3159,6 +3159,16 @@ bool Map::owns_descriptors() { } +void Map::set_is_observed(bool is_observed) { + set_bit_field3(IsObserved::update(bit_field3(), is_observed)); +} + + +bool Map::is_observed() { + return IsObserved::decode(bit_field3()); +} + + void Code::set_flags(Code::Flags flags) { STATIC_ASSERT(Code::NUMBER_OF_KINDS <= KindField::kMax + 1); // Make sure that all call stubs have an arguments count. diff --git a/src/objects.h b/src/objects.h index 50018bf..3e70fa9 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4704,6 +4704,7 @@ class Map: public HeapObject { class FunctionWithPrototype: public BitField {}; class DictionaryMap: public BitField {}; class OwnsDescriptors: public BitField {}; + class IsObserved: public BitField {}; // Tells whether the object in the prototype property will be used // for instances created from this function. If the prototype @@ -4971,6 +4972,8 @@ class Map: public HeapObject { inline bool owns_descriptors(); inline void set_owns_descriptors(bool is_shared); + inline bool is_observed(); + inline void set_is_observed(bool is_observed); MUST_USE_RESULT MaybeObject* RawCopy(int instance_size); MUST_USE_RESULT MaybeObject* CopyWithPreallocatedFieldDescriptors(); diff --git a/src/runtime.cc b/src/runtime.cc index e90e3a9..a8fc88f 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -13222,6 +13222,29 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_HaveSameMap) { return isolate->heap()->ToBoolean(obj1->map() == obj2->map()); } + +RUNTIME_FUNCTION(MaybeObject*, Runtime_IsObserved) { + ASSERT(args.length() == 1); + CONVERT_ARG_CHECKED(JSReceiver, obj, 0); + return isolate->heap()->ToBoolean(obj->map()->is_observed()); +} + + +RUNTIME_FUNCTION(MaybeObject*, Runtime_SetIsObserved) { + ASSERT(args.length() == 2); + CONVERT_ARG_CHECKED(JSReceiver, obj, 0); + CONVERT_BOOLEAN_ARG_CHECKED(is_observed, 1); + if (obj->map()->is_observed() != is_observed) { + MaybeObject* maybe = obj->map()->Copy(); + Map* map; + if (!maybe->To(&map)) return maybe; + map->set_is_observed(is_observed); + obj->set_map(map); + } + return isolate->heap()->undefined_value(); +} + + // ---------------------------------------------------------------------------- // Implementation of Runtime diff --git a/src/runtime.h b/src/runtime.h index c802906..824c7a0 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -317,6 +317,10 @@ namespace internal { F(WeakMapDelete, 2, 1) \ F(WeakMapSet, 3, 1) \ \ + /* Harmony observe */ \ + F(IsObserved, 1, 1) \ + F(SetIsObserved, 2, 1) \ + \ /* Statements */ \ F(NewClosure, 3, 1) \ F(NewObject, 1, 1) \