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

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: Style fixes 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
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/realm-property-access.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 9466ab7d3a727c2fe12d70ac977df0b0cac57f35..3b7863e543ef53ecb23e61a1a5fdd89714c53d67 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -523,9 +523,8 @@ void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global());
}
-
-// Realm.create() creates a new realm and returns its index.
-void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
+MaybeLocal<Context> Shell::CreateRealm(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
TryCatch try_catch(isolate);
PerIsolateData* data = PerIsolateData::Get(isolate);
@@ -542,12 +541,29 @@ void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (context.IsEmpty()) {
DCHECK(try_catch.HasCaught());
try_catch.ReThrow();
- return;
+ return MaybeLocal<Context>();
}
data->realms_[index].Reset(isolate, context);
args.GetReturnValue().Set(index);
+ return context;
}
+// Realm.create() creates a new realm with a distinct security token
+// and returns its index.
+void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CreateRealm(args);
+}
+
+// Realm.createAllowCrossRealmAccess() creates a new realm with the same
+// security token as the current realm.
+void Shell::RealmCreateAllowCrossRealmAccess(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Local<Context> context;
+ if (CreateRealm(args).ToLocal(&context)) {
+ context->SetSecurityToken(
+ args.GetIsolate()->GetEnteredContext()->GetSecurityToken());
+ }
+}
// Realm.dispose(i) disposes the reference to the realm i.
void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
@@ -1136,6 +1152,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));
« no previous file with comments | « src/d8.h ('k') | test/mjsunit/realm-property-access.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698