Commit 1859b040 authored by dcarney@chromium.org's avatar dcarney@chromium.org

add GetOwnPropertyDescriptor to api

R=verwaest@chromium.org

BUG=

Review URL: https://codereview.chromium.org/364923006

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22190 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c1231d42
......@@ -2115,6 +2115,11 @@ class V8_EXPORT Object : public Value {
*/
PropertyAttribute GetPropertyAttributes(Handle<Value> key);
/**
* Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
*/
Local<Value> GetOwnPropertyDescriptor(Local<String> key);
bool Has(Handle<Value> key);
bool Delete(Handle<Value> key);
......
......@@ -3196,6 +3196,26 @@ PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) {
}
Local<Value> v8::Object::GetOwnPropertyDescriptor(Local<String> key) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyDescriptor()",
return Local<Value>());
ENTER_V8(isolate);
i::Handle<i::JSObject> obj = Utils::OpenHandle(this);
i::Handle<i::Name> key_name = Utils::OpenHandle(*key);
i::Handle<i::Object> args[] = { obj, key_name };
EXCEPTION_PREAMBLE(isolate);
i::Handle<i::Object> result;
has_pending_exception = !CallV8HeapFunction(
"ObjectGetOwnPropertyDescriptor",
isolate->factory()->undefined_value(),
ARRAY_SIZE(args),
args).ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
return Utils::ToLocal(result);
}
Local<Value> v8::Object::GetPrototype() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::GetPrototype()", return Local<v8::Value>());
......
......@@ -22870,3 +22870,31 @@ TEST(ScriptSourceURLAndSourceMappingURL) {
"//# sourceURL= bar21.js \n"
"//# sourceMappingURL= bar22.js \n", "bar21.js", "bar22.js");
}
TEST(GetOwnPropertyDescriptor) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
CompileRun(
"var x = { value : 13};"
"Object.defineProperty(x, 'p0', {value : 12});"
"Object.defineProperty(x, 'p1', {"
" set : function(value) { this.value = value; },"
" get : function() { return this.value; },"
"});");
Local<Object> x = Local<Object>::Cast(env->Global()->Get(v8_str("x")));
Local<Value> desc = x->GetOwnPropertyDescriptor(v8_str("no_prop"));
CHECK(desc->IsUndefined());
desc = x->GetOwnPropertyDescriptor(v8_str("p0"));
CHECK_EQ(v8_num(12), Local<Object>::Cast(desc)->Get(v8_str("value")));
desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
Local<Function> set =
Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
Local<Function> get =
Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
CHECK_EQ(v8_num(13), get->Call(x, 0, NULL));
Handle<Value> args[] = { v8_num(14) };
set->Call(x, 1, args);
CHECK_EQ(v8_num(14), get->Call(x, 0, NULL));
}
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