Commit 6c8472bd authored by rossberg@chromium.org's avatar rossberg@chromium.org

Fix and test use of property descriptor objects.

R=kmillikin@chromium.org
BUG=v8:1543
TEST=

Review URL: http://codereview.chromium.org/7828080

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9364 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 41eb990a
......@@ -1327,6 +1327,8 @@ void Genesis::InstallNativeFunctions() {
configure_instance_fun);
INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
INSTALL_NATIVE(JSObject, "functionCache", function_cache);
INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor",
to_complete_property_descriptor);
}
void Genesis::InstallExperimentalNativeFunctions() {
......
......@@ -134,6 +134,8 @@ enum BindingFlags {
V(MAP_CACHE_INDEX, Object, map_cache) \
V(CONTEXT_DATA_INDEX, Object, data) \
V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \
V(TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX, JSFunction, \
to_complete_property_descriptor) \
V(DERIVED_HAS_TRAP_INDEX, JSFunction, derived_has_trap) \
V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap)
......@@ -252,6 +254,7 @@ class Context: public FixedArray {
OUT_OF_MEMORY_INDEX,
CONTEXT_DATA_INDEX,
ALLOW_CODE_GEN_FROM_STRINGS_INDEX,
TO_COMPLETE_PROPERTY_DESCRIPTOR_INDEX,
DERIVED_HAS_TRAP_INDEX,
DERIVED_GET_TRAP_INDEX,
DERIVED_SET_TRAP_INDEX,
......
......@@ -2296,8 +2296,29 @@ MUST_USE_RESULT PropertyAttributes JSProxy::GetPropertyAttributeWithHandler(
if (result->IsUndefined()) return ABSENT;
// TODO(rossberg): convert result to PropertyAttributes
return NONE;
bool has_pending_exception;
Object** argv[] = { result.location() };
Handle<Object> desc =
Execution::Call(isolate->to_complete_property_descriptor(), result,
ARRAY_SIZE(argv), argv, &has_pending_exception);
if (has_pending_exception) return NONE;
// Convert result to PropertyAttributes.
Handle<String> enum_n = isolate->factory()->LookupAsciiSymbol("enumerable");
Handle<Object> enumerable(v8::internal::GetProperty(desc, enum_n));
if (isolate->has_pending_exception()) return NONE;
Handle<String> conf_n = isolate->factory()->LookupAsciiSymbol("configurable");
Handle<Object> configurable(v8::internal::GetProperty(desc, conf_n));
if (isolate->has_pending_exception()) return NONE;
Handle<String> writ_n = isolate->factory()->LookupAsciiSymbol("writable");
Handle<Object> writable(v8::internal::GetProperty(desc, writ_n));
if (isolate->has_pending_exception()) return NONE;
int attributes = NONE;
if (enumerable->ToBoolean()->IsFalse()) attributes |= DONT_ENUM;
if (configurable->ToBoolean()->IsFalse()) attributes |= DONT_DELETE;
if (writable->ToBoolean()->IsFalse()) attributes |= READ_ONLY;
return static_cast<PropertyAttributes>(attributes);
}
......
......@@ -28,8 +28,9 @@
// Flags: --harmony-proxies
// TODO(rossberg): for-in for proxies not implemented.
// TODO(rossberg): integer-index properties not implemented properly.
// TODO(rossberg): for-in not implemented on proxies.
// Helper.
......@@ -1079,7 +1080,7 @@ function TestInForDerived2(handler, create) {
var o = Object.create(p)
assertTrue("a" in o)
assertEquals("a", key)
// TODO(rossberg): integer indexes not correctly imlemeted yet
// TODO(rossberg): integer indexes not correctly implemented yet
// assertTrue(99 in o)
// assertEquals("99", key)
assertFalse("z" in o)
......@@ -1164,6 +1165,62 @@ TestInForDerived(Proxy.create({
// Property descriptor conversion.
var descget
function TestDescriptorGetOrder(handler) {
var p = Proxy.create(handler)
var o = Object.create(p, {b: {value: 0}})
TestDescriptorGetOrder2(function(n) { p[n] }, "vV")
TestDescriptorGetOrder2(function(n) { n in p }, "")
TestDescriptorGetOrder2(function(n) { o[n] }, "vV")
TestDescriptorGetOrder2(function(n) { n in o }, "eEcCvVwWgs")
}
function TestDescriptorGetOrder2(f, access) {
descget = ""
f("a")
assertEquals(access, descget)
// TODO(rossberg): integer indexes not correctly implemented yet.
// descget = ""
// f(99)
// assertEquals(access, descget)
descget = ""
f("z")
assertEquals("", descget)
}
TestDescriptorGetOrder({
getPropertyDescriptor: function(k) {
if (k >= "z") return void 0
// Return a proxy as property descriptor, so that we can log accesses.
return Proxy.create({
get: function(r, attr) {
descget += attr[0].toUpperCase()
return true
},
has: function(attr) {
descget += attr[0]
switch (attr) {
case "writable":
case "enumerable":
case "configurable":
case "value":
return true
case "get":
case "set":
return false
default:
assertUnreachable()
}
}
})
}
})
// Own Properties (Object.prototype.hasOwnProperty).
var key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment