Reviewers: Sven Panne,
Message:
It's not clear to me if this was intended behavior for some reason; if it
was,
I'd be interested if we could change it. Blink would like to be able to set
hidden values to undefined and have that properly reflected through the API.
Description:
Allow users of the V8 API to distinguish between unset and undefined
HiddenValues
BUG=v8:2746
Please review this at https://codereview.chromium.org/17781002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/api.cc
M src/objects.h
M src/objects.cc
M src/runtime.cc
M test/cctest/test-api.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
8ca858dca91d367e5ba9bb849c8a22ec3f673a1d..014d82ee4f0aab86c5f16ca339c22b335c42753b
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3935,7 +3935,7 @@ v8::Local<v8::Value>
v8::Object::GetHiddenValue(v8::Handle<v8::String> key) {
i::Handle<i::String> key_string =
isolate->factory()->InternalizeString(key_obj);
i::Handle<i::Object> result(self->GetHiddenProperty(*key_string),
isolate);
- if (result->IsUndefined()) return v8::Local<v8::Value>();
+ if (result->IsTheHole()) return v8::Local<v8::Value>();
return Utils::ToLocal(result);
}
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
8633012ba1ee19d2dcf3281812aec031d0cc3b3b..5265901435a67a697244f6001b7e058ea8e73c3b
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4734,7 +4734,7 @@ Object* JSObject::GetHiddenProperty(Name* key) {
// For a proxy, use the prototype as target object.
Object* proxy_parent = GetPrototype();
// If the proxy is detached, return undefined.
- if (proxy_parent->IsNull()) return GetHeap()->undefined_value();
+ if (proxy_parent->IsNull()) return GetHeap()->the_hole_value();
ASSERT(proxy_parent->IsJSGlobalObject());
return JSObject::cast(proxy_parent)->GetHiddenProperty(key);
}
@@ -4748,15 +4748,14 @@ Object* JSObject::GetHiddenProperty(Name* key) {
if (key == GetHeap()->identity_hash_string()) {
return inline_value;
} else {
- return GetHeap()->undefined_value();
+ return GetHeap()->the_hole_value();
}
}
- if (inline_value->IsUndefined()) return GetHeap()->undefined_value();
+ if (inline_value->IsUndefined()) return GetHeap()->the_hole_value();
ObjectHashTable* hashtable = ObjectHashTable::cast(inline_value);
Object* entry = hashtable->Lookup(key);
- if (entry->IsTheHole()) return GetHeap()->undefined_value();
return entry;
}
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
2e2a01845b7661696bc4fb841701891526d5d4eb..d3abed115be674d2c292ab2b50c0a880f03f8a0f
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1996,7 +1996,7 @@ class JSObject: public JSReceiver {
Handle<Object> value);
// Returns a failure if a GC is required.
MUST_USE_RESULT MaybeObject* SetHiddenProperty(Name* key, Object* value);
- // Gets the value of a hidden property with the given key. Returns
undefined
+ // Gets the value of a hidden property with the given key. Returns the
hole
// if the property doesn't exist (or if called on a detached proxy),
// otherwise returns the value set for the key.
Object* GetHiddenProperty(Name* key);
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
8917c585908bf89da27d23cf03d0c92d2130447d..86f7f0f430abe3d79d2d63d20f090923f3e20c69
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -13380,6 +13380,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_GetOverflowedStackTrace) {
CONVERT_ARG_CHECKED(JSObject, error_object, 0);
String* key = isolate->heap()->hidden_stack_trace_string();
Object* result = error_object->GetHiddenProperty(key);
+ if (result->IsTheHole()) result = isolate->heap()->undefined_value();
RUNTIME_ASSERT(result->IsJSArray() ||
result->IsString() ||
result->IsUndefined());
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
c39b4292b19d68109118832e79c9afc9329d001d..b95f292b6e1c1763e1eefd64086ed7ebcbc8fe6d
100755
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -19280,6 +19280,18 @@ THREADED_TEST(Regress2535) {
}
+THREADED_TEST(Regress2746) {
+ LocalContext context;
+ v8::HandleScope scope(context->GetIsolate());
+ Local<Object> obj = Object::New();
+ Local<String> key = String::New("key");
+ obj->SetHiddenValue(key, v8::Undefined());
+ Local<Value> value = obj->GetHiddenValue(key);
+ CHECK(!value.IsEmpty());
+ CHECK(value->IsUndefined());
+}
+
+
#ifndef WIN32
class ThreadInterruptTest {
public:
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.