Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: test/cctest/test-api.cc

Issue 18225006: Fall back to generic on access checks in JSON.stringify. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/json-stringifier.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 19697 matching lines...) Expand 10 before | Expand all | Expand 10 after
19708 19708
19709 i::Semaphore* sem_; 19709 i::Semaphore* sem_;
19710 volatile int sem_value_; 19710 volatile int sem_value_;
19711 }; 19711 };
19712 19712
19713 19713
19714 THREADED_TEST(SemaphoreInterruption) { 19714 THREADED_TEST(SemaphoreInterruption) {
19715 ThreadInterruptTest().RunTest(); 19715 ThreadInterruptTest().RunTest();
19716 } 19716 }
19717 19717
19718
19719 static bool NamedAccessAlwaysBlocked(Local<v8::Object> global,
19720 Local<Value> name,
19721 v8::AccessType type,
19722 Local<Value> data) {
19723 i::PrintF("Named access blocked.\n");
19724 return false;
19725 }
19726
19727
19728 static bool IndexAccessAlwaysBlocked(Local<v8::Object> global,
19729 uint32_t key,
19730 v8::AccessType type,
19731 Local<Value> data) {
19732 i::PrintF("Indexed access blocked.\n");
19733 return false;
19734 }
19735
19736
19737 void UnreachableCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
19738 CHECK(false);
19739 }
19740
19741
19742 TEST(JSONStringifyAccessCheck) {
19743 v8::V8::Initialize();
19744 v8::HandleScope scope(v8::Isolate::GetCurrent());
19745
19746 // Create an ObjectTemplate for global objects and install access
19747 // check callbacks that will block access.
19748 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
19749 global_template->SetAccessCheckCallbacks(NamedAccessAlwaysBlocked,
19750 IndexAccessAlwaysBlocked);
19751
19752 // Create a context and set an x property on it's global object.
19753 LocalContext context0(NULL, global_template);
19754 v8::Handle<v8::Object> global0 = context0->Global();
19755 global0->Set(v8_str("x"), v8_num(42));
19756 ExpectString("JSON.stringify(this)", "{\"x\":42}");
19757
19758 for (int i = 0; i < 2; i++) {
19759 if (i == 1) {
19760 // Install a toJSON function on the second run.
19761 v8::Handle<v8::FunctionTemplate> toJSON =
19762 v8::FunctionTemplate::New(UnreachableCallback);
19763
19764 global0->Set(v8_str("toJSON"), toJSON->GetFunction());
19765 }
19766 // Create a context with a different security token so that the
19767 // failed access check callback will be called on each access.
19768 LocalContext context1(NULL, global_template);
19769 context1->Global()->Set(v8_str("other"), global0);
19770
19771 ExpectString("JSON.stringify(other)", "{}");
19772 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })",
19773 "{\"a\":{},\"b\":[\"c\"]}");
19774 ExpectString("JSON.stringify([other, 'b', 'c'])",
19775 "[{},\"b\",\"c\"]");
19776
19777 v8::Handle<v8::Array> array = v8::Array::New(2);
19778 array->Set(0, v8_str("a"));
19779 array->Set(1, v8_str("b"));
19780 context1->Global()->Set(v8_str("array"), array);
19781 ExpectString("JSON.stringify(array)", "[\"a\",\"b\"]");
19782 array->TurnOnAccessCheck();
19783 ExpectString("JSON.stringify(array)", "[]");
19784 ExpectString("JSON.stringify([array])", "[[]]");
19785 ExpectString("JSON.stringify({'a' : array})", "{\"a\":[]}");
19786 }
19787 }
19788
19789
19718 #endif // WIN32 19790 #endif // WIN32
OLDNEW
« no previous file with comments | « src/json-stringifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698