Reviewers: danno,
Description:
Object.observe: implement map bit and functions to access it.
[email protected]
BUG=
Please review this at https://codereview.chromium.org/11276028/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/objects-inl.h
M src/objects.h
M src/runtime.h
M src/runtime.cc
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
4e7d8f8c08702943ef60fb3692b5ceb56482ec5d..640ca5e498e13feb7bc68a1a3dc0d093736f81bf
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -3151,6 +3151,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.
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
0d1a69cb9882985fa282c4e2f3dc4a5fa98c9523..5952da8933f38b61baf7a59457f142f4c17962b9
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4701,6 +4701,7 @@ class Map: public HeapObject {
class FunctionWithPrototype: public BitField<bool, 23, 1> {};
class DictionaryMap: public BitField<bool, 24, 1> {};
class OwnsDescriptors: public BitField<bool, 25, 1> {};
+ class IsObserved: public BitField<bool, 26, 1> {};
// Tells whether the object in the prototype property will be used
// for instances created from this function. If the prototype
@@ -4968,6 +4969,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();
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
b0a6b5e81427e1588a89f1c269a2b1e90c78f98b..6d3412b7fd246a25bea2622b8330a0d41f6bc5c2
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>(&map)) return maybe;
+ map->set_is_observed(is_observed);
+ obj->set_map(map);
+ }
+ return isolate->heap()->undefined_value();
+}
+
+
//
----------------------------------------------------------------------------
// Implementation of Runtime
Index: src/runtime.h
diff --git a/src/runtime.h b/src/runtime.h
index
c8029065f6908ce9f5d04c695dea00ffb098d687..824c7a0078d1dcd8aadb9eaff9aabe29a1473c5c
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) \
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev