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

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

Issue 1406293011: Re-ship @@toStringTag (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added API tests to answer my security question Created 5 years, 1 month 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
« no previous file with comments | « src/flag-definitions.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 22020 matching lines...) Expand 10 before | Expand all | Expand 10 after
22031 22031
22032 allowed_access = true; 22032 allowed_access = true;
22033 env->Global()->Set(v8_str("object"), object); 22033 env->Global()->Set(v8_str("object"), object);
22034 object->Set(v8::Symbol::GetToStringTag(isolate), v8_str("hello")); 22034 object->Set(v8::Symbol::GetToStringTag(isolate), v8_str("hello"));
22035 22035
22036 // Access check is allowed, and the toStringTag is read 22036 // Access check is allowed, and the toStringTag is read
22037 CompileRun("var result = Object.prototype.toString.call(object)"); 22037 CompileRun("var result = Object.prototype.toString.call(object)");
22038 ExpectString("result", "[object hello]"); 22038 ExpectString("result", "[object hello]");
22039 ExpectString("object[Symbol.toStringTag]", "hello"); 22039 ExpectString("object[Symbol.toStringTag]", "hello");
22040 22040
22041 // ToString through the API should succeed too.
22042 String::Utf8Value result_allowed(
22043 object->ObjectProtoToString(env.local()).ToLocalChecked());
22044 CHECK_EQ(0, strcmp(*result_allowed, "[object hello]"));
22045
22041 // If access check fails, the value of @@toStringTag is ignored 22046 // If access check fails, the value of @@toStringTag is ignored
22042 allowed_access = false; 22047 allowed_access = false;
22043 CompileRun("var result = Object.prototype.toString.call(object)"); 22048 CompileRun("var result = Object.prototype.toString.call(object)");
22044 ExpectString("result", "[object Object]"); 22049 ExpectString("result", "[object Object]");
22045 ExpectTrue("object[Symbol.toStringTag] === undefined"); 22050 ExpectTrue("object[Symbol.toStringTag] === undefined");
22051
22052 // ToString through the API should also fail.
22053 String::Utf8Value result_denied(
22054 object->ObjectProtoToString(env.local()).ToLocalChecked());
22055 CHECK_EQ(0, strcmp(*result_denied, "[object Object]"));
22046 } 22056 }
22047 22057
22048 22058
22049 TEST(ObjectTemplateIntrinsics) { 22059 TEST(ObjectTemplateIntrinsics) {
22050 v8::Isolate* isolate = CcTest::isolate(); 22060 v8::Isolate* isolate = CcTest::isolate();
22051 v8::HandleScope scope(isolate); 22061 v8::HandleScope scope(isolate);
22052 LocalContext env; 22062 LocalContext env;
22053 22063
22054 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); 22064 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate);
22055 object_template->SetIntrinsicDataProperty(v8_str("values"), 22065 object_template->SetIntrinsicDataProperty(v8_str("values"),
(...skipping 14 matching lines...) Expand all
22070 env2->Global()->Set(v8_str("obj2"), object2); 22080 env2->Global()->Set(v8_str("obj2"), object2);
22071 ExpectString("typeof obj2.values", "function"); 22081 ExpectString("typeof obj2.values", "function");
22072 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); 22082 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values")));
22073 22083
22074 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); 22084 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values")));
22075 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); 22085 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2));
22076 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); 22086 auto ctx2 = v8::Utils::OpenHandle(*env2.local());
22077 CHECK_EQ(fn2->GetCreationContext(), *ctx2); 22087 CHECK_EQ(fn2->GetCreationContext(), *ctx2);
22078 } 22088 }
22079 } 22089 }
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698