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

Unified Diff: src/d8.cc

Issue 1973363004: Expose a way to make a "same-origin" realm (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix typo Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 9466ab7d3a727c2fe12d70ac977df0b0cac57f35..460380594956eb1ccfff37278bc94e5de02d2d08 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -548,6 +548,32 @@ void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(index);
}
+// Realm.createAllowCrossRealmAccess(i) jreates a new realm with the same
adamk 2016/05/19 19:23:20 s/jreates/creates/
Dan Ehrenberg 2016/05/27 13:51:39 Done
+// security token as the current realm.
+void Shell::RealmCreateAllowCrossRealmAccess(
rossberg 2016/05/19 06:07:00 I wouldn't mind factoring out the commonalities be
adamk 2016/05/19 19:23:20 Agreed, the fewer places we have to write 'delete[
Dan Ehrenberg 2016/05/27 13:51:39 Done
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Isolate* isolate = args.GetIsolate();
+ TryCatch try_catch(isolate);
+ PerIsolateData* data = PerIsolateData::Get(isolate);
+ Global<Context>* old_realms = data->realms_;
+ int index = data->realm_count_;
+ data->realms_ = new Global<Context>[++data->realm_count_];
+ for (int i = 0; i < index; ++i) {
+ data->realms_[i].Reset(isolate, old_realms[i]);
+ old_realms[i].Reset();
+ }
+ delete[] old_realms;
+ Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
+ Local<Context> context = Context::New(isolate, NULL, global_template);
+ if (context.IsEmpty()) {
+ DCHECK(try_catch.HasCaught());
+ try_catch.ReThrow();
+ return;
+ }
+ context->SetSecurityToken(isolate->GetEnteredContext()->GetSecurityToken());
+ data->realms_[index].Reset(isolate, context);
+ args.GetReturnValue().Set(index);
+}
// Realm.dispose(i) disposes the reference to the realm i.
void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
@@ -1136,6 +1162,11 @@ Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmCreate));
realm_template->Set(
+ String::NewFromUtf8(isolate, "createAllowCrossRealmAccess",
+ NewStringType::kNormal)
+ .ToLocalChecked(),
+ FunctionTemplate::New(isolate, RealmCreateAllowCrossRealmAccess));
+ realm_template->Set(
String::NewFromUtf8(isolate, "dispose", NewStringType::kNormal)
.ToLocalChecked(),
FunctionTemplate::New(isolate, RealmDispose));

Powered by Google App Engine
This is Rietveld 408576698