| Index: test/cctest/test-api.cc
|
| ===================================================================
|
| --- test/cctest/test-api.cc (revision 7030)
|
| +++ test/cctest/test-api.cc (working copy)
|
| @@ -2368,13 +2368,32 @@
|
| }
|
|
|
|
|
| -// Test that overwritten toString methods are not invoked on uncaught
|
| -// exception formatting. However, they are invoked when performing
|
| -// normal error string conversions.
|
| +static v8::Handle<Value> Fail(const v8::Arguments& args) {
|
| + ApiTestFuzzer::Fuzz();
|
| + CHECK(false);
|
| + return v8::Undefined();
|
| +}
|
| +
|
| +
|
| +// Test that overwritten methods are not invoked on uncaught exception
|
| +// formatting. However, they are invoked when performing normal error
|
| +// string conversions.
|
| TEST(APIThrowMessageOverwrittenToString) {
|
| v8::HandleScope scope;
|
| v8::V8::AddMessageListener(check_reference_error_message);
|
| - LocalContext context;
|
| + Local<ObjectTemplate> templ = ObjectTemplate::New();
|
| + templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail));
|
| + LocalContext context(NULL, templ);
|
| + CompileRun("asdf;");
|
| + CompileRun("var limit = {};"
|
| + "limit.valueOf = fail;"
|
| + "Error.stackTraceLimit = limit;");
|
| + CompileRun("asdf");
|
| + CompileRun("Array.prototype.pop = fail;");
|
| + CompileRun("Object.prototype.hasOwnProperty = fail;");
|
| + CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }");
|
| + CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }");
|
| + CompileRun("String.prototype.toString = function f() { return 'Yikes'; }");
|
| CompileRun("ReferenceError.prototype.toString ="
|
| " function() { return 'Whoops' }");
|
| CompileRun("asdf;");
|
| @@ -5289,11 +5308,13 @@
|
| }
|
|
|
|
|
| +static bool allowed_access_type[v8::ACCESS_KEYS] = { false };
|
| static bool NamedAccessBlocker(Local<v8::Object> global,
|
| Local<Value> name,
|
| v8::AccessType type,
|
| Local<Value> data) {
|
| - return Context::GetCurrent()->Global()->Equals(global);
|
| + return Context::GetCurrent()->Global()->Equals(global) ||
|
| + allowed_access_type[type];
|
| }
|
|
|
|
|
| @@ -5333,7 +5354,7 @@
|
| }
|
|
|
|
|
| -THREADED_TEST(AccessControl) {
|
| +TEST(AccessControl) {
|
| v8::HandleScope handle_scope;
|
| v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
|
|
|
| @@ -5359,6 +5380,15 @@
|
|
|
| v8::Handle<v8::Object> global0 = context0->Global();
|
|
|
| + // Define a property with JS getter and setter.
|
| + CompileRun(
|
| + "function getter() { return 'getter'; };\n"
|
| + "function setter() { return 'setter'; }\n"
|
| + "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
|
| +
|
| + Local<Value> getter = global0->Get(v8_str("getter"));
|
| + Local<Value> setter = global0->Get(v8_str("setter"));
|
| +
|
| v8::HandleScope scope1;
|
|
|
| v8::Persistent<Context> context1 = Context::New();
|
| @@ -5367,40 +5397,118 @@
|
| v8::Handle<v8::Object> global1 = context1->Global();
|
| global1->Set(v8_str("other"), global0);
|
|
|
| - v8::Handle<Value> value;
|
| -
|
| // Access blocked property
|
| - value = v8_compile("other.blocked_prop = 1")->Run();
|
| - value = v8_compile("other.blocked_prop")->Run();
|
| - CHECK(value->IsUndefined());
|
| + CompileRun("other.blocked_prop = 1");
|
|
|
| - value = v8_compile("propertyIsEnumerable.call(other, 'blocked_prop')")->Run();
|
| - CHECK(value->IsFalse());
|
| + ExpectUndefined("other.blocked_prop");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
|
| + ExpectFalse("propertyIsEnumerable.call(other, 'blocked_prop')");
|
|
|
| + // Enable ACCESS_HAS
|
| + allowed_access_type[v8::ACCESS_HAS] = true;
|
| + ExpectUndefined("other.blocked_prop");
|
| + // ... and now we can get the descriptor...
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'blocked_prop').value");
|
| + // ... and enumerate the property.
|
| + ExpectTrue("propertyIsEnumerable.call(other, 'blocked_prop')");
|
| + allowed_access_type[v8::ACCESS_HAS] = false;
|
| +
|
| + CompileRun("other.js_accessor_p = 2");
|
| +
|
| + ExpectUndefined("other.js_accessor_p");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')");
|
| +
|
| + // Enable ACCESS_HAS.
|
| + allowed_access_type[v8::ACCESS_HAS] = true;
|
| + ExpectUndefined("other.js_accessor_p");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
|
| + allowed_access_type[v8::ACCESS_HAS] = false;
|
| +
|
| + // Enable both ACCESS_HAS and ACCESS_GET.
|
| + allowed_access_type[v8::ACCESS_HAS] = true;
|
| + allowed_access_type[v8::ACCESS_GET] = true;
|
| +
|
| + ExpectString("other.js_accessor_p", "getter");
|
| + ExpectObject(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
|
| +
|
| + allowed_access_type[v8::ACCESS_GET] = false;
|
| + allowed_access_type[v8::ACCESS_HAS] = false;
|
| +
|
| + // Enable both ACCESS_HAS and ACCESS_SET.
|
| + allowed_access_type[v8::ACCESS_HAS] = true;
|
| + allowed_access_type[v8::ACCESS_SET] = true;
|
| +
|
| + ExpectUndefined("other.js_accessor_p");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get");
|
| + ExpectObject(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
|
| +
|
| + allowed_access_type[v8::ACCESS_SET] = false;
|
| + allowed_access_type[v8::ACCESS_HAS] = false;
|
| +
|
| + // Enable both ACCESS_HAS, ACCESS_GET and ACCESS_SET.
|
| + allowed_access_type[v8::ACCESS_HAS] = true;
|
| + allowed_access_type[v8::ACCESS_GET] = true;
|
| + allowed_access_type[v8::ACCESS_SET] = true;
|
| +
|
| + ExpectString("other.js_accessor_p", "getter");
|
| + ExpectObject(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter);
|
| + ExpectObject(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter);
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value");
|
| +
|
| + allowed_access_type[v8::ACCESS_SET] = false;
|
| + allowed_access_type[v8::ACCESS_GET] = false;
|
| + allowed_access_type[v8::ACCESS_HAS] = false;
|
| +
|
| + v8::Handle<Value> value;
|
| +
|
| // Access accessible property
|
| - value = v8_compile("other.accessible_prop = 3")->Run();
|
| + value = CompileRun("other.accessible_prop = 3");
|
| CHECK(value->IsNumber());
|
| CHECK_EQ(3, value->Int32Value());
|
| CHECK_EQ(3, g_echo_value);
|
|
|
| - value = v8_compile("other.accessible_prop")->Run();
|
| + value = CompileRun("other.accessible_prop");
|
| CHECK(value->IsNumber());
|
| CHECK_EQ(3, value->Int32Value());
|
|
|
| - value =
|
| - v8_compile("propertyIsEnumerable.call(other, 'accessible_prop')")->Run();
|
| + value = CompileRun(
|
| + "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
|
| + CHECK(value->IsNumber());
|
| + CHECK_EQ(3, value->Int32Value());
|
| +
|
| + value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
|
| CHECK(value->IsTrue());
|
|
|
| // Enumeration doesn't enumerate accessors from inaccessible objects in
|
| // the prototype chain even if the accessors are in themselves accessible.
|
| - Local<Value> result =
|
| + value =
|
| CompileRun("(function(){var obj = {'__proto__':other};"
|
| "for (var p in obj)"
|
| " if (p == 'accessible_prop' || p == 'blocked_prop') {"
|
| " return false;"
|
| " }"
|
| "return true;})()");
|
| - CHECK(result->IsTrue());
|
| + CHECK(value->IsTrue());
|
|
|
| context1->Exit();
|
| context0->Exit();
|
| @@ -6245,7 +6353,7 @@
|
| " var str = String(e);"
|
| " if (str.indexOf('TypeError') == -1) return 1;"
|
| " if (str.indexOf('[object Fun]') != -1) return 2;"
|
| - " if (str.indexOf('#<a Fun>') == -1) return 3;"
|
| + " if (str.indexOf('#<Fun>') == -1) return 3;"
|
| " return 0;"
|
| " }"
|
| " return 4;"
|
|
|