From 49233c9972e6d938391ad379b00e11122cf82750 Mon Sep 17 00:00:00 2001 From: "jkummerow@chromium.org" Date: Wed, 30 Jul 2014 09:31:06 +0000 Subject: [PATCH] Throw an exception when an access check fails and no external callback is installed R=yangguo@chromium.org Review URL: https://codereview.chromium.org/428733007 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22698 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/isolate.cc | 6 +- src/mirror-debugger.js | 22 ++- test/cctest/test-api.cc | 231 +++++++++++++++++--------------- tools/generate-runtime-tests.py | 2 +- 4 files changed, 144 insertions(+), 117 deletions(-) diff --git a/src/isolate.cc b/src/isolate.cc index 39dcc2647d..6405115b9f 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -638,7 +638,11 @@ static inline AccessCheckInfo* GetAccessCheckInfo(Isolate* isolate, void Isolate::ReportFailedAccessCheck(Handle receiver, v8::AccessType type) { - if (!thread_local_top()->failed_access_check_callback_) return; + if (!thread_local_top()->failed_access_check_callback_) { + Handle message = factory()->InternalizeUtf8String("no access"); + ScheduleThrow(*factory()->NewTypeError(message)); + return; + } ASSERT(receiver->IsAccessCheckNeeded()); ASSERT(context()); diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js index 35f34a91d4..932294157b 100644 --- a/src/mirror-debugger.js +++ b/src/mirror-debugger.js @@ -171,7 +171,7 @@ PropertyKind.Named = 1; PropertyKind.Indexed = 2; -// A copy of the PropertyType enum from global.h +// A copy of the PropertyType enum from property-details.h var PropertyType = {}; PropertyType.Normal = 0; PropertyType.Field = 1; @@ -179,8 +179,7 @@ PropertyType.Constant = 2; PropertyType.Callbacks = 3; PropertyType.Handler = 4; PropertyType.Interceptor = 5; -PropertyType.Transition = 6; -PropertyType.Nonexistent = 7; +PropertyType.Nonexistent = 6; // Different attributes for a property. @@ -684,6 +683,19 @@ ObjectMirror.prototype.hasIndexedInterceptor = function() { }; +// Get all own property names except for private symbols. +function TryGetPropertyNames(object) { + try { + // TODO(yangguo): Should there be a special debugger implementation of + // %GetOwnPropertyNames that doesn't perform access checks? + return %GetOwnPropertyNames(object, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL); + } catch (e) { + // Might have hit a failed access check. + return []; + } +} + + /** * Return the property names for this object. * @param {number} kind Indicate whether named, indexed or both kinds of @@ -702,9 +714,7 @@ ObjectMirror.prototype.propertyNames = function(kind, limit) { // Find all the named properties. if (kind & PropertyKind.Named) { - // Get all own property names except for private symbols. - propertyNames = - %GetOwnPropertyNames(this.value_, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL); + propertyNames = TryGetPropertyNames(this.value_); total += propertyNames.length; // Get names for named interceptor properties if any. diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index d174b307cb..7bde4cbe81 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -6178,15 +6178,17 @@ THREADED_TEST(IndexedInterceptorWithAccessorCheck) { context->Global()->Set(v8_str("obj"), obj); const char* code = - "try {" - " for (var i = 0; i < 100; i++) {" + "var result = 'PASSED';" + "for (var i = 0; i < 100; i++) {" + " try {" " var v = obj[0];" - " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" + " result = 'Wrong value ' + v + ' at iteration ' + i;" + " break;" + " } catch (e) {" + " /* pass */" " }" - " 'PASSED'" - "} catch(e) {" - " e" - "}"; + "}" + "result"; ExpectString(code, "PASSED"); } @@ -6203,21 +6205,29 @@ THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { context->Global()->Set(v8_str("obj"), obj); const char* code = - "try {" - " for (var i = 0; i < 100; i++) {" - " var expected = i;" - " if (i == 5) {" - " %EnableAccessChecks(obj);" - " expected = undefined;" - " }" - " var v = obj[i];" - " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" - " if (i == 5) %DisableAccessChecks(obj);" + "var result = 'PASSED';" + "for (var i = 0; i < 100; i++) {" + " var expected = i;" + " if (i == 5) {" + " %EnableAccessChecks(obj);" " }" - " 'PASSED'" - "} catch(e) {" - " e" - "}"; + " try {" + " var v = obj[i];" + " if (i == 5) {" + " result = 'Should not have reached this!';" + " break;" + " } else if (v != expected) {" + " result = 'Wrong value ' + v + ' at iteration ' + i;" + " break;" + " }" + " } catch (e) {" + " if (i != 5) {" + " result = e;" + " }" + " }" + " if (i == 5) %DisableAccessChecks(obj);" + "}" + "result"; ExpectString(code, "PASSED"); } @@ -8628,10 +8638,8 @@ THREADED_TEST(SecurityChecksForPrototypeChain) { v8::Local