Commit deeddc7e authored by adamk@chromium.org's avatar adamk@chromium.org

Remove duplication and unnecessary HandleScope from HasElement helper functions

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13736 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc9b8176
......@@ -3373,11 +3373,6 @@ PropertyAttributes JSObject::GetElementAttributeWithReceiver(
return GetElementAttributeWithInterceptor(receiver, index, continue_search);
}
// Handle [] on String objects.
if (this->IsStringObjectWithCharacterAt(index)) {
return static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
}
return GetElementAttributeWithoutInterceptor(
receiver, index, continue_search);
}
......@@ -3429,28 +3424,25 @@ PropertyAttributes JSObject::GetElementAttributeWithInterceptor(
PropertyAttributes JSObject::GetElementAttributeWithoutInterceptor(
JSReceiver* receiver, uint32_t index, bool continue_search) {
Isolate* isolate = GetIsolate();
HandleScope scope(isolate);
Handle<JSReceiver> hreceiver(receiver);
Handle<JSObject> holder(this);
PropertyAttributes attr = holder->GetElementsAccessor()->GetAttributes(
*hreceiver, *holder, index);
PropertyAttributes attr = GetElementsAccessor()->GetAttributes(
receiver, this, index);
if (attr != ABSENT) return attr;
if (holder->IsStringObjectWithCharacterAt(index)) {
// Handle [] on String objects.
if (IsStringObjectWithCharacterAt(index)) {
return static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
}
if (!continue_search) return ABSENT;
Object* pt = holder->GetPrototype();
Object* pt = GetPrototype();
if (pt->IsJSProxy()) {
// We need to follow the spec and simulate a call to [[GetOwnProperty]].
return JSProxy::cast(pt)->GetElementAttributeWithHandler(*hreceiver, index);
return JSProxy::cast(pt)->GetElementAttributeWithHandler(receiver, index);
}
if (pt->IsNull()) return ABSENT;
return JSObject::cast(pt)->GetElementAttributeWithReceiver(
*hreceiver, index, true);
receiver, index, true);
}
......
......@@ -17197,6 +17197,27 @@ TEST(HasOwnProperty) {
}
TEST(IndexedInterceptorWithStringProto) {
v8::HandleScope scope;
Handle<ObjectTemplate> templ = ObjectTemplate::New();
templ->SetIndexedPropertyHandler(NULL,
NULL,
HasOwnPropertyIndexedPropertyQuery);
LocalContext context;
context->Global()->Set(v8_str("obj"), templ->NewInstance());
CompileRun("var s = new String('foobar'); obj.__proto__ = s;");
// These should be intercepted.
CHECK(CompileRun("42 in obj")->BooleanValue());
CHECK(CompileRun("'42' in obj")->BooleanValue());
// These should fall through to the String prototype.
CHECK(CompileRun("0 in obj")->BooleanValue());
CHECK(CompileRun("'0' in obj")->BooleanValue());
// And these should both fail.
CHECK(!CompileRun("32 in obj")->BooleanValue());
CHECK(!CompileRun("'32' in obj")->BooleanValue());
}
void CheckCodeGenerationAllowed() {
Handle<Value> result = CompileRun("eval('42')");
CHECK_EQ(42, result->Int32Value());
......
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