Revision: 17090
Author: [email protected]
Date: Wed Oct 2 18:06:20 2013 UTC
Log: Avoid allocations in Object.observe access check tests
BUG=v8:2907
[email protected]
Review URL: https://codereview.chromium.org/24999007
http://code.google.com/p/v8/source/detail?r=17090
Modified:
/branches/bleeding_edge/test/cctest/cctest.status
/branches/bleeding_edge/test/cctest/test-object-observe.cc
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.status Tue Oct 1 13:54:53
2013 UTC
+++ /branches/bleeding_edge/test/cctest/cctest.status Wed Oct 2 18:06:20
2013 UTC
@@ -34,11 +34,6 @@
# BUG(382): Weird test. Can't guarantee that it never times out.
'test-api/ApplyInterruption': [PASS, TIMEOUT],
- # BUG(2907): Allocation while in DisallowHeapAllocation scope.
- 'test-object-observe/NamedAccessCheck': [SKIP],
- 'test-object-observe/DisallowAllForAccessKeys': [SKIP],
- 'test-object-observe/AccessCheckDisallowApiModifications': [SKIP],
-
# TODO(mstarzinger): Fail gracefully on multiple V8::Dispose calls.
'test-api/InitializeAndDisposeOnce': [SKIP],
'test-api/InitializeAndDisposeMultiple': [SKIP],
=======================================
--- /branches/bleeding_edge/test/cctest/test-object-observe.cc Thu Sep 26
08:21:48 2013 UTC
+++ /branches/bleeding_edge/test/cctest/test-object-observe.cc Wed Oct 2
18:06:20 2013 UTC
@@ -465,34 +465,32 @@
static AccessType g_access_block_type = ACCESS_GET;
+static const uint32_t kBlockedContextIndex = 1337;
static bool NamedAccessAllowUnlessBlocked(Local<Object> host,
- Local<Value> key,
- AccessType type,
- Local<Value>) {
+ Local<Value> key,
+ AccessType type,
+ Local<Value> data) {
if (type != g_access_block_type) return true;
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(
Utils::OpenHandle(*host)->GetIsolate());
Handle<Object> global = isolate->GetCurrentContext()->Global();
- Handle<Value> blacklist = global->Get(String::New("blacklist"));
- if (!blacklist->IsObject()) return true;
- if (key->IsString()) return !blacklist.As<Object>()->Has(key);
- return true;
+ if (!global->Has(kBlockedContextIndex)) return true;
+ return !key->IsString() || !key->Equals(data);
}
static bool IndexedAccessAllowUnlessBlocked(Local<Object> host,
- uint32_t index,
- AccessType type,
- Local<Value>) {
- if (type != ACCESS_GET) return true;
+ uint32_t index,
+ AccessType type,
+ Local<Value> data) {
+ if (type != g_access_block_type) return true;
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(
Utils::OpenHandle(*host)->GetIsolate());
Handle<Object> global = isolate->GetCurrentContext()->Global();
- Handle<Value> blacklist = global->Get(String::New("blacklist"));
- if (!blacklist->IsObject()) return true;
- return !blacklist.As<Object>()->Has(index);
+ if (!global->Has(kBlockedContextIndex)) return true;
+ return index != data->Uint32Value();
}
@@ -501,20 +499,20 @@
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(
Utils::OpenHandle(*host)->GetIsolate());
Handle<Object> global = isolate->GetCurrentContext()->Global();
- Handle<Value> blacklist = global->Get(String::New("blacklist"));
- if (!blacklist->IsObject()) return true;
- return type != ACCESS_KEYS ||
- !blacklist.As<Object>()->Has(String::New("__block_access_keys"));
+ return type != ACCESS_KEYS || !global->Has(kBlockedContextIndex);
}
static Handle<Object> CreateAccessCheckedObject(
NamedSecurityCallback namedCallback,
- IndexedSecurityCallback indexedCallback) {
+ IndexedSecurityCallback indexedCallback,
+ Handle<Value> data = Handle<Value>()) {
Handle<ObjectTemplate> tmpl = ObjectTemplate::New();
- tmpl->SetAccessCheckCallbacks(namedCallback, indexedCallback);
+ tmpl->SetAccessCheckCallbacks(namedCallback, indexedCallback, data);
Handle<Object> instance = tmpl->NewInstance();
- instance->CreationContext()->Global()->Set(String::New("obj"), instance);
+ Handle<Object> global = instance->CreationContext()->Global();
+ global->Set(String::New("obj"), instance);
+ global->Set(kBlockedContextIndex, v8::True());
return instance;
}
@@ -527,10 +525,11 @@
LocalContext context(isolate.GetIsolate());
g_access_block_type = types[i];
Handle<Object> instance = CreateAccessCheckedObject(
- NamedAccessAllowUnlessBlocked, IndexedAccessAlwaysAllowed);
+ NamedAccessAllowUnlessBlocked,
+ IndexedAccessAlwaysAllowed,
+ String::New("foo"));
CompileRun("var records = null;"
"var objNoCheck = {};"
- "var blacklist = {foo: true};"
"var observer = function(r) { records = r };"
"Object.observe(obj, observer);"
"Object.observe(objNoCheck, observer);");
@@ -574,10 +573,10 @@
LocalContext context(isolate.GetIsolate());
g_access_block_type = types[i];
Handle<Object> instance = CreateAccessCheckedObject(
- NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked);
+ NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked,
+ Number::New(7));
CompileRun("var records = null;"
"var objNoCheck = {};"
- "var blacklist = {7: true};"
"var observer = function(r) { records = r };"
"Object.observe(obj, observer);"
"Object.observe(objNoCheck, observer);");
@@ -619,12 +618,12 @@
LocalContext context(isolate.GetIsolate());
g_access_block_type = ACCESS_GET;
Handle<Object> instance = CreateAccessCheckedObject(
- NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked);
+ NamedAccessAlwaysAllowed, IndexedAccessAllowUnlessBlocked,
+ Number::New(1));
CompileRun("var records = null;"
"obj[1] = 'foo';"
"obj.length = 2;"
"var objNoCheck = {1: 'bar', length: 2};"
- "var blacklist = {1: true};"
"observer = function(r) { records = r };"
"Array.observe(obj, observer);"
"Array.observe(objNoCheck, observer);");
@@ -667,7 +666,6 @@
CompileRun("var records = null;"
"var objNoCheck = {};"
"var observer = function(r) { records = r };"
- "var blacklist = {__block_access_keys: true};"
"Object.observe(obj, observer);"
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
@@ -704,7 +702,6 @@
BlockAccessKeys, IndexedAccessAlwaysAllowed);
CompileRun("var records = null;"
"var observer = function(r) { records = r };"
- "var blacklist = {__block_access_keys: true};"
"Object.observe(obj, observer);");
{
LocalContext context2(isolate.GetIsolate());
--
--
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.