From 3cd9f6a40eb0480ad98faf3103af18145704087d Mon Sep 17 00:00:00 2001 From: "rossberg@chromium.org" Date: Mon, 22 Apr 2013 11:29:52 +0000 Subject: [PATCH] Add d8 functionality for switching between realms (a.k.a. contexts), 2nd try The only difference to the previous implementation (https://codereview.chromium.org/14295011/) is in patch set 2. R=yangguo@chromium.org BUG= Review URL: https://codereview.chromium.org/14404005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14373 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8.cc | 370 ++++++++++++++++++++++++++------- src/d8.h | 13 ++ src/debug.cc | 1 - src/objects.h | 2 +- test/mjsunit/bugs/bug-proto.js | 62 ++++++ 5 files changed, 370 insertions(+), 78 deletions(-) create mode 100644 test/mjsunit/bugs/bug-proto.js diff --git a/src/d8.cc b/src/d8.cc index 8f6e384c1a..fe9fdca550 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -83,7 +83,7 @@ const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; -#define FOR_EACH_SYMBOL(V) \ +#define FOR_EACH_STRING(V) \ V(ArrayBuffer, "ArrayBuffer") \ V(ArrayBufferMarkerPropName, kArrayBufferMarkerPropName) \ V(ArrayMarkerPropName, kArrayMarkerPropName) \ @@ -94,36 +94,58 @@ const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; V(length, "length") -class Symbols { +class PerIsolateData { public: - explicit Symbols(Isolate* isolate) : isolate_(isolate) { + explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { HandleScope scope(isolate); -#define INIT_SYMBOL(name, value) \ - name##_ = Persistent::New(isolate, String::NewSymbol(value)); - FOR_EACH_SYMBOL(INIT_SYMBOL) -#undef INIT_SYMBOL +#define INIT_STRING(name, value) \ + name##_string_ = Persistent::New(isolate, String::NewSymbol(value)); + FOR_EACH_STRING(INIT_STRING) +#undef INIT_STRING isolate->SetData(this); } - ~Symbols() { -#define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_); - FOR_EACH_SYMBOL(DISPOSE_SYMBOL) -#undef DISPOSE_SYMBOL + ~PerIsolateData() { +#define DISPOSE_STRING(name, value) name##_string_.Dispose(isolate_); + FOR_EACH_STRING(DISPOSE_STRING) +#undef DISPOSE_STRING isolate_->SetData(NULL); // Not really needed, just to be sure... } -#define DEFINE_SYMBOL_GETTER(name, value) \ - static Persistent name(Isolate* isolate) { \ - return reinterpret_cast(isolate->GetData())->name##_; \ + inline static PerIsolateData* Get(Isolate* isolate) { + return reinterpret_cast(isolate->GetData()); } - FOR_EACH_SYMBOL(DEFINE_SYMBOL_GETTER) -#undef DEFINE_SYMBOL_GETTER + +#define DEFINE_STRING_GETTER(name, value) \ + static Persistent name##_string(Isolate* isolate) { \ + return Get(isolate)->name##_string_; \ + } + FOR_EACH_STRING(DEFINE_STRING_GETTER) +#undef DEFINE_STRING_GETTER + + class RealmScope { + public: + explicit RealmScope(PerIsolateData* data); + ~RealmScope(); + private: + PerIsolateData* data_; + }; private: + friend class Shell; + friend class RealmScope; Isolate* isolate_; -#define DEFINE_MEMBER(name, value) Persistent name##_; - FOR_EACH_SYMBOL(DEFINE_MEMBER) + int realm_count_; + int realm_current_; + int realm_switch_; + Persistent* realms_; + Persistent realm_shared_; + +#define DEFINE_MEMBER(name, value) Persistent name##_string_; + FOR_EACH_STRING(DEFINE_MEMBER) #undef DEFINE_MEMBER + + int RealmFind(Handle context); }; @@ -207,14 +229,20 @@ bool Shell::ExecuteString(Isolate* isolate, // When debugging make exceptions appear to be uncaught. try_catch.SetVerbose(true); } - Handle