Commit 72a05845 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Revert r14310 due to isolate tests failure.

R=mstarzinger@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/14021004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14334 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ecbbf528
...@@ -83,7 +83,7 @@ const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_"; ...@@ -83,7 +83,7 @@ const char kArrayBufferMarkerPropName[] = "d8::_is_array_buffer_";
const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; const char kArrayMarkerPropName[] = "d8::_is_typed_array_";
#define FOR_EACH_STRING(V) \ #define FOR_EACH_SYMBOL(V) \
V(ArrayBuffer, "ArrayBuffer") \ V(ArrayBuffer, "ArrayBuffer") \
V(ArrayBufferMarkerPropName, kArrayBufferMarkerPropName) \ V(ArrayBufferMarkerPropName, kArrayBufferMarkerPropName) \
V(ArrayMarkerPropName, kArrayMarkerPropName) \ V(ArrayMarkerPropName, kArrayMarkerPropName) \
...@@ -94,50 +94,36 @@ const char kArrayMarkerPropName[] = "d8::_is_typed_array_"; ...@@ -94,50 +94,36 @@ const char kArrayMarkerPropName[] = "d8::_is_typed_array_";
V(length, "length") V(length, "length")
class PerIsolateData { class Symbols {
public: public:
explicit PerIsolateData(Isolate* isolate) : isolate_(isolate), realms_(NULL) { explicit Symbols(Isolate* isolate) : isolate_(isolate) {
HandleScope scope(isolate); HandleScope scope(isolate);
#define INIT_STRING(name, value) \ #define INIT_SYMBOL(name, value) \
name##_string_ = Persistent<String>::New(isolate, String::NewSymbol(value)); name##_ = Persistent<String>::New(isolate, String::NewSymbol(value));
FOR_EACH_STRING(INIT_STRING) FOR_EACH_SYMBOL(INIT_SYMBOL)
#undef INIT_STRING #undef INIT_SYMBOL
isolate->SetData(this); isolate->SetData(this);
} }
~PerIsolateData() { ~Symbols() {
#define DISPOSE_STRING(name, value) name##_string_.Dispose(isolate_); #define DISPOSE_SYMBOL(name, value) name##_.Dispose(isolate_);
FOR_EACH_STRING(DISPOSE_STRING) FOR_EACH_SYMBOL(DISPOSE_SYMBOL)
#undef DISPOSE_STRING #undef DISPOSE_SYMBOL
isolate_->SetData(NULL); // Not really needed, just to be sure... isolate_->SetData(NULL); // Not really needed, just to be sure...
} }
inline static PerIsolateData* Get(Isolate* isolate) { #define DEFINE_SYMBOL_GETTER(name, value) \
return reinterpret_cast<PerIsolateData*>(isolate->GetData()); static Persistent<String> name(Isolate* isolate) { \
return reinterpret_cast<Symbols*>(isolate->GetData())->name##_; \
} }
FOR_EACH_SYMBOL(DEFINE_SYMBOL_GETTER)
#define DEFINE_STRING_GETTER(name, value) \ #undef DEFINE_SYMBOL_GETTER
static Persistent<String> name##_string(Isolate* isolate) { \
return Get(isolate)->name##_string_; \
}
FOR_EACH_STRING(DEFINE_STRING_GETTER)
#undef DEFINE_STRING_GETTER
private: private:
friend class Shell;
Isolate* isolate_; Isolate* isolate_;
int realm_count_; #define DEFINE_MEMBER(name, value) Persistent<String> name##_;
int realm_current_; FOR_EACH_SYMBOL(DEFINE_MEMBER)
int realm_switch_;
Persistent<Context>* realms_;
Persistent<Value> realm_shared_;
#define DEFINE_MEMBER(name, value) Persistent<String> name##_string_;
FOR_EACH_STRING(DEFINE_MEMBER)
#undef DEFINE_MEMBER #undef DEFINE_MEMBER
void RealmInit();
int RealmFind(Handle<Context> context);
}; };
...@@ -221,20 +207,14 @@ bool Shell::ExecuteString(Isolate* isolate, ...@@ -221,20 +207,14 @@ bool Shell::ExecuteString(Isolate* isolate,
// When debugging make exceptions appear to be uncaught. // When debugging make exceptions appear to be uncaught.
try_catch.SetVerbose(true); try_catch.SetVerbose(true);
} }
Handle<Script> script = Script::New(source, name); Handle<Script> script = Script::Compile(source, name);
if (script.IsEmpty()) { if (script.IsEmpty()) {
// Print errors that happened during compilation. // Print errors that happened during compilation.
if (report_exceptions && !FLAG_debugger) if (report_exceptions && !FLAG_debugger)
ReportException(isolate, &try_catch); ReportException(isolate, &try_catch);
return false; return false;
} else { } else {
PerIsolateData* data = PerIsolateData::Get(isolate);
Local<Context> realm =
Local<Context>::New(data->realms_[data->realm_current_]);
realm->Enter();
Handle<Value> result = script->Run(); Handle<Value> result = script->Run();
realm->Exit();
data->realm_current_ = data->realm_switch_;
if (result.IsEmpty()) { if (result.IsEmpty()) {
ASSERT(try_catch.HasCaught()); ASSERT(try_catch.HasCaught());
// Print errors that happened during execution. // Print errors that happened during execution.
...@@ -275,159 +255,6 @@ bool Shell::ExecuteString(Isolate* isolate, ...@@ -275,159 +255,6 @@ bool Shell::ExecuteString(Isolate* isolate,
} }
void PerIsolateData::RealmInit() {
if (realms_ != NULL) {
// Drop realms from previous run.
for (int i = 0; i < realm_count_; ++i) realms_[i].Dispose(isolate_);
delete[] realms_;
if (!realm_shared_.IsEmpty()) realm_shared_.Dispose(isolate_);
}
realm_count_ = 1;
realm_current_ = 0;
realm_switch_ = 0;
realms_ = new Persistent<Context>[1];
realms_[0] = Persistent<Context>::New(isolate_, Context::GetEntered());
realm_shared_.Clear();
}
int PerIsolateData::RealmFind(Handle<Context> context) {
for (int i = 0; i < realm_count_; ++i) {
if (realms_[i] == context) return i;
}
return -1;
}
// Realm.current() returns the index of the currently active realm.
Handle<Value> Shell::RealmCurrent(const Arguments& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
int index = data->RealmFind(Context::GetEntered());
if (index == -1) return Undefined(isolate);
return Number::New(index);
}
// Realm.owner(o) returns the index of the realm that created o.
Handle<Value> Shell::RealmOwner(const Arguments& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (args.Length() < 1 || !args[0]->IsObject()) {
return Throw("Invalid argument");
}
int index = data->RealmFind(args[0]->ToObject()->CreationContext());
if (index == -1) return Undefined(isolate);
return Number::New(index);
}
// Realm.global(i) returns the global object of realm i.
// (Note that properties of global objects cannot be read/written cross-realm.)
Handle<Value> Shell::RealmGlobal(const Arguments& args) {
PerIsolateData* data = PerIsolateData::Get(args.GetIsolate());
if (args.Length() < 1 || !args[0]->IsNumber()) {
return Throw("Invalid argument");
}
int index = args[0]->Uint32Value();
if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
return Throw("Invalid realm index");
}
return data->realms_[index]->Global();
}
// Realm.create() creates a new realm and returns its index.
Handle<Value> Shell::RealmCreate(const Arguments& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
Persistent<Context>* old_realms = data->realms_;
int index = data->realm_count_;
data->realms_ = new Persistent<Context>[++data->realm_count_];
for (int i = 0; i < index; ++i) data->realms_[i] = old_realms[i];
delete[] old_realms;
Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
data->realms_[index] = Persistent<Context>::New(
isolate, Context::New(isolate, NULL, global_template));
return Number::New(index);
}
// Realm.dispose(i) disposes the reference to the realm i.
Handle<Value> Shell::RealmDispose(const Arguments& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (args.Length() < 1 || !args[0]->IsNumber()) {
return Throw("Invalid argument");
}
int index = args[0]->Uint32Value();
if (index >= data->realm_count_ || data->realms_[index].IsEmpty() ||
index == 0 ||
index == data->realm_current_ || index == data->realm_switch_) {
return Throw("Invalid realm index");
}
data->realms_[index].Dispose(isolate);
data->realms_[index].Clear();
return Undefined(isolate);
}
// Realm.switch(i) switches to the realm i for consecutive interactive inputs.
Handle<Value> Shell::RealmSwitch(const Arguments& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (args.Length() < 1 || !args[0]->IsNumber()) {
return Throw("Invalid argument");
}
int index = args[0]->Uint32Value();
if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
return Throw("Invalid realm index");
}
data->realm_switch_ = index;
return Undefined(isolate);
}
// Realm.eval(i, s) evaluates s in realm i and returns the result.
Handle<Value> Shell::RealmEval(const Arguments& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsString()) {
return Throw("Invalid argument");
}
int index = args[0]->Uint32Value();
if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
return Throw("Invalid realm index");
}
Handle<Script> script = Script::New(args[1]->ToString());
if (script.IsEmpty()) return Undefined(isolate);
Local<Context> realm = Local<Context>::New(data->realms_[index]);
realm->Enter();
Handle<Value> result = script->Run();
realm->Exit();
return result;
}
// Realm.shared is an accessor for a single shared value across realms.
Handle<Value> Shell::RealmSharedGet(Local<String> property,
const AccessorInfo& info) {
Isolate* isolate = info.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (data->realm_shared_.IsEmpty()) return Undefined(isolate);
return data->realm_shared_;
}
void Shell::RealmSharedSet(Local<String> property,
Local<Value> value,
const AccessorInfo& info) {
Isolate* isolate = info.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
if (!data->realm_shared_.IsEmpty()) data->realm_shared_.Dispose(isolate);
data->realm_shared_ = Persistent<Value>::New(isolate, value);
}
Handle<Value> Shell::Print(const Arguments& args) { Handle<Value> Shell::Print(const Arguments& args) {
Handle<Value> val = Write(args); Handle<Value> val = Write(args);
printf("\n"); printf("\n");
...@@ -589,8 +416,7 @@ Handle<Value> Shell::CreateExternalArrayBuffer(Isolate* isolate, ...@@ -589,8 +416,7 @@ Handle<Value> Shell::CreateExternalArrayBuffer(Isolate* isolate,
} }
memset(data, 0, length); memset(data, 0, length);
buffer->SetHiddenValue( buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True());
PerIsolateData::ArrayBufferMarkerPropName_string(isolate), True());
Persistent<Object> persistent_array = Persistent<Object> persistent_array =
Persistent<Object>::New(isolate, buffer); Persistent<Object>::New(isolate, buffer);
persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback); persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback);
...@@ -599,7 +425,7 @@ Handle<Value> Shell::CreateExternalArrayBuffer(Isolate* isolate, ...@@ -599,7 +425,7 @@ Handle<Value> Shell::CreateExternalArrayBuffer(Isolate* isolate,
buffer->SetIndexedPropertiesToExternalArrayData( buffer->SetIndexedPropertiesToExternalArrayData(
data, v8::kExternalByteArray, length); data, v8::kExternalByteArray, length);
buffer->Set(PerIsolateData::byteLength_string(isolate), buffer->Set(Symbols::byteLength(isolate),
Int32::New(length, isolate), Int32::New(length, isolate),
ReadOnly); ReadOnly);
...@@ -644,20 +470,20 @@ Handle<Object> Shell::CreateExternalArray(Isolate* isolate, ...@@ -644,20 +470,20 @@ Handle<Object> Shell::CreateExternalArray(Isolate* isolate,
array->SetIndexedPropertiesToExternalArrayData( array->SetIndexedPropertiesToExternalArrayData(
static_cast<uint8_t*>(data) + byteOffset, type, length); static_cast<uint8_t*>(data) + byteOffset, type, length);
array->SetHiddenValue(PerIsolateData::ArrayMarkerPropName_string(isolate), array->SetHiddenValue(Symbols::ArrayMarkerPropName(isolate),
Int32::New(type, isolate)); Int32::New(type, isolate));
array->Set(PerIsolateData::byteLength_string(isolate), array->Set(Symbols::byteLength(isolate),
Int32::New(byteLength, isolate), Int32::New(byteLength, isolate),
ReadOnly); ReadOnly);
array->Set(PerIsolateData::byteOffset_string(isolate), array->Set(Symbols::byteOffset(isolate),
Int32::New(byteOffset, isolate), Int32::New(byteOffset, isolate),
ReadOnly); ReadOnly);
array->Set(PerIsolateData::length_string(isolate), array->Set(Symbols::length(isolate),
Int32::New(length, isolate), Int32::New(length, isolate),
ReadOnly); ReadOnly);
array->Set(PerIsolateData::BYTES_PER_ELEMENT_string(isolate), array->Set(Symbols::BYTES_PER_ELEMENT(isolate),
Int32::New(element_size, isolate)); Int32::New(element_size, isolate));
array->Set(PerIsolateData::buffer_string(isolate), array->Set(Symbols::buffer(isolate),
buffer, buffer,
ReadOnly); ReadOnly);
...@@ -698,11 +524,11 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args, ...@@ -698,11 +524,11 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args,
} }
if (args[0]->IsObject() && if (args[0]->IsObject() &&
!args[0]->ToObject()->GetHiddenValue( !args[0]->ToObject()->GetHiddenValue(
PerIsolateData::ArrayBufferMarkerPropName_string(isolate)).IsEmpty()) { Symbols::ArrayBufferMarkerPropName(isolate)).IsEmpty()) {
// Construct from ArrayBuffer. // Construct from ArrayBuffer.
buffer = args[0]->ToObject(); buffer = args[0]->ToObject();
int32_t bufferLength = convertToUint( int32_t bufferLength =
buffer->Get(PerIsolateData::byteLength_string(isolate)), &try_catch); convertToUint(buffer->Get(Symbols::byteLength(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
if (args.Length() < 2 || args[1]->IsUndefined()) { if (args.Length() < 2 || args[1]->IsUndefined()) {
...@@ -734,10 +560,9 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args, ...@@ -734,10 +560,9 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args,
} }
} else { } else {
if (args[0]->IsObject() && if (args[0]->IsObject() &&
args[0]->ToObject()->Has(PerIsolateData::length_string(isolate))) { args[0]->ToObject()->Has(Symbols::length(isolate))) {
// Construct from array. // Construct from array.
Local<Value> value = Local<Value> value = args[0]->ToObject()->Get(Symbols::length(isolate));
args[0]->ToObject()->Get(PerIsolateData::length_string(isolate));
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
length = convertToUint(value, &try_catch); length = convertToUint(value, &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
...@@ -751,8 +576,7 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args, ...@@ -751,8 +576,7 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args,
byteOffset = 0; byteOffset = 0;
Handle<Object> global = Context::GetCurrent()->Global(); Handle<Object> global = Context::GetCurrent()->Global();
Handle<Value> array_buffer = Handle<Value> array_buffer = global->Get(Symbols::ArrayBuffer(isolate));
global->Get(PerIsolateData::ArrayBuffer_string(isolate));
ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction());
Handle<Value> buffer_args[] = { Uint32::New(byteLength, isolate) }; Handle<Value> buffer_args[] = { Uint32::New(byteLength, isolate) };
Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance(
...@@ -787,14 +611,14 @@ Handle<Value> Shell::ArrayBufferSlice(const Arguments& args) { ...@@ -787,14 +611,14 @@ Handle<Value> Shell::ArrayBufferSlice(const Arguments& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
Local<Object> self = args.This(); Local<Object> self = args.This();
Local<Value> marker = self->GetHiddenValue( Local<Value> marker =
PerIsolateData::ArrayBufferMarkerPropName_string(isolate)); self->GetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate));
if (marker.IsEmpty()) { if (marker.IsEmpty()) {
return Throw("'slice' invoked on wrong receiver type"); return Throw("'slice' invoked on wrong receiver type");
} }
int32_t length = convertToUint( int32_t length =
self->Get(PerIsolateData::byteLength_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::byteLength(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
if (args.Length() == 0) { if (args.Length() == 0) {
...@@ -843,22 +667,21 @@ Handle<Value> Shell::ArraySubArray(const Arguments& args) { ...@@ -843,22 +667,21 @@ Handle<Value> Shell::ArraySubArray(const Arguments& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
Local<Object> self = args.This(); Local<Object> self = args.This();
Local<Value> marker = Local<Value> marker =
self->GetHiddenValue(PerIsolateData::ArrayMarkerPropName_string(isolate)); self->GetHiddenValue(Symbols::ArrayMarkerPropName(isolate));
if (marker.IsEmpty()) { if (marker.IsEmpty()) {
return Throw("'subarray' invoked on wrong receiver type"); return Throw("'subarray' invoked on wrong receiver type");
} }
Handle<Object> buffer = Handle<Object> buffer = self->Get(Symbols::buffer(isolate))->ToObject();
self->Get(PerIsolateData::buffer_string(isolate))->ToObject();
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t length = convertToUint( int32_t length =
self->Get(PerIsolateData::length_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::length(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t byteOffset = convertToUint( int32_t byteOffset =
self->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::byteOffset(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t element_size = convertToUint( int32_t element_size =
self->Get(PerIsolateData::BYTES_PER_ELEMENT_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::BYTES_PER_ELEMENT(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
if (args.Length() == 0) { if (args.Length() == 0) {
...@@ -903,27 +726,27 @@ Handle<Value> Shell::ArraySet(const Arguments& args) { ...@@ -903,27 +726,27 @@ Handle<Value> Shell::ArraySet(const Arguments& args) {
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
Local<Object> self = args.This(); Local<Object> self = args.This();
Local<Value> marker = Local<Value> marker =
self->GetHiddenValue(PerIsolateData::ArrayMarkerPropName_string(isolate)); self->GetHiddenValue(Symbols::ArrayMarkerPropName(isolate));
if (marker.IsEmpty()) { if (marker.IsEmpty()) {
return Throw("'set' invoked on wrong receiver type"); return Throw("'set' invoked on wrong receiver type");
} }
int32_t length = convertToUint( int32_t length =
self->Get(PerIsolateData::length_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::length(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t element_size = convertToUint( int32_t element_size =
self->Get(PerIsolateData::BYTES_PER_ELEMENT_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::BYTES_PER_ELEMENT(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
if (args.Length() == 0) { if (args.Length() == 0) {
return Throw("'set' must have at least one argument"); return Throw("'set' must have at least one argument");
} }
if (!args[0]->IsObject() || if (!args[0]->IsObject() ||
!args[0]->ToObject()->Has(PerIsolateData::length_string(isolate))) { !args[0]->ToObject()->Has(Symbols::length(isolate))) {
return Throw("'set' invoked with non-array argument"); return Throw("'set' invoked with non-array argument");
} }
Handle<Object> source = args[0]->ToObject(); Handle<Object> source = args[0]->ToObject();
int32_t source_length = convertToUint( int32_t source_length =
source->Get(PerIsolateData::length_string(isolate)), &try_catch); convertToUint(source->Get(Symbols::length(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t offset; int32_t offset;
...@@ -938,30 +761,28 @@ Handle<Value> Shell::ArraySet(const Arguments& args) { ...@@ -938,30 +761,28 @@ Handle<Value> Shell::ArraySet(const Arguments& args) {
} }
int32_t source_element_size; int32_t source_element_size;
if (source->GetHiddenValue( if (source->GetHiddenValue(Symbols::ArrayMarkerPropName(isolate)).IsEmpty()) {
PerIsolateData::ArrayMarkerPropName_string(isolate)).IsEmpty()) {
source_element_size = 0; source_element_size = 0;
} else { } else {
source_element_size = convertToUint( source_element_size =
source->Get(PerIsolateData::BYTES_PER_ELEMENT_string(isolate)), convertToUint(source->Get(Symbols::BYTES_PER_ELEMENT(isolate)),
&try_catch); &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
} }
if (element_size == source_element_size && if (element_size == source_element_size &&
self->GetConstructor()->StrictEquals(source->GetConstructor())) { self->GetConstructor()->StrictEquals(source->GetConstructor())) {
// Use memmove on the array buffers. // Use memmove on the array buffers.
Handle<Object> buffer = Handle<Object> buffer = self->Get(Symbols::buffer(isolate))->ToObject();
self->Get(PerIsolateData::buffer_string(isolate))->ToObject();
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
Handle<Object> source_buffer = Handle<Object> source_buffer =
source->Get(PerIsolateData::buffer_string(isolate))->ToObject(); source->Get(Symbols::buffer(isolate))->ToObject();
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t byteOffset = convertToUint( int32_t byteOffset =
self->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::byteOffset(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t source_byteOffset = convertToUint( int32_t source_byteOffset =
source->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); convertToUint(source->Get(Symbols::byteOffset(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
uint8_t* dest = byteOffset + offset * element_size + static_cast<uint8_t*>( uint8_t* dest = byteOffset + offset * element_size + static_cast<uint8_t*>(
...@@ -977,22 +798,21 @@ Handle<Value> Shell::ArraySet(const Arguments& args) { ...@@ -977,22 +798,21 @@ Handle<Value> Shell::ArraySet(const Arguments& args) {
} }
} else { } else {
// Need to copy element-wise to make the right conversions. // Need to copy element-wise to make the right conversions.
Handle<Object> buffer = Handle<Object> buffer = self->Get(Symbols::buffer(isolate))->ToObject();
self->Get(PerIsolateData::buffer_string(isolate))->ToObject();
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
Handle<Object> source_buffer = Handle<Object> source_buffer =
source->Get(PerIsolateData::buffer_string(isolate))->ToObject(); source->Get(Symbols::buffer(isolate))->ToObject();
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
if (buffer->StrictEquals(source_buffer)) { if (buffer->StrictEquals(source_buffer)) {
// Same backing store, need to handle overlap correctly. // Same backing store, need to handle overlap correctly.
// This gets a bit tricky in the case of different element sizes // This gets a bit tricky in the case of different element sizes
// (which, of course, is extremely unlikely to ever occur in practice). // (which, of course, is extremely unlikely to ever occur in practice).
int32_t byteOffset = convertToUint( int32_t byteOffset =
self->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); convertToUint(self->Get(Symbols::byteOffset(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
int32_t source_byteOffset = convertToUint( int32_t source_byteOffset =
source->Get(PerIsolateData::byteOffset_string(isolate)), &try_catch); convertToUint(source->Get(Symbols::byteOffset(isolate)), &try_catch);
if (try_catch.HasCaught()) return try_catch.ReThrow(); if (try_catch.HasCaught()) return try_catch.ReThrow();
// Copy as much as we can from left to right. // Copy as much as we can from left to right.
...@@ -1040,8 +860,8 @@ void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, ...@@ -1040,8 +860,8 @@ void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate,
Persistent<Value> object, Persistent<Value> object,
void* data) { void* data) {
HandleScope scope(isolate); HandleScope scope(isolate);
int32_t length = object->ToObject()->Get( int32_t length =
PerIsolateData::byteLength_string(isolate))->Uint32Value(); object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value();
isolate->AdjustAmountOfExternalAllocatedMemory(-length); isolate->AdjustAmountOfExternalAllocatedMemory(-length);
delete[] static_cast<uint8_t*>(data); delete[] static_cast<uint8_t*>(data);
object.Dispose(isolate); object.Dispose(isolate);
...@@ -1418,30 +1238,10 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) { ...@@ -1418,30 +1238,10 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
global_template->Set(String::New("disableProfiler"), global_template->Set(String::New("disableProfiler"),
FunctionTemplate::New(DisableProfiler)); FunctionTemplate::New(DisableProfiler));
// Bind the Realm object.
Handle<ObjectTemplate> realm_template = ObjectTemplate::New();
realm_template->Set(String::New("current"),
FunctionTemplate::New(RealmCurrent));
realm_template->Set(String::New("owner"),
FunctionTemplate::New(RealmOwner));
realm_template->Set(String::New("global"),
FunctionTemplate::New(RealmGlobal));
realm_template->Set(String::New("create"),
FunctionTemplate::New(RealmCreate));
realm_template->Set(String::New("dispose"),
FunctionTemplate::New(RealmDispose));
realm_template->Set(String::New("switch"),
FunctionTemplate::New(RealmSwitch));
realm_template->Set(String::New("eval"),
FunctionTemplate::New(RealmEval));
realm_template->SetAccessor(String::New("shared"),
RealmSharedGet, RealmSharedSet);
global_template->Set(String::New("Realm"), realm_template);
// Bind the handlers for external arrays. // Bind the handlers for external arrays.
PropertyAttribute attr = PropertyAttribute attr =
static_cast<PropertyAttribute>(ReadOnly | DontDelete); static_cast<PropertyAttribute>(ReadOnly | DontDelete);
global_template->Set(PerIsolateData::ArrayBuffer_string(isolate), global_template->Set(Symbols::ArrayBuffer(isolate),
CreateArrayBufferTemplate(ArrayBuffer), attr); CreateArrayBufferTemplate(ArrayBuffer), attr);
global_template->Set(String::New("Int8Array"), global_template->Set(String::New("Int8Array"),
CreateArrayTemplate(Int8Array), attr); CreateArrayTemplate(Int8Array), attr);
...@@ -1525,7 +1325,6 @@ Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) { ...@@ -1525,7 +1325,6 @@ Persistent<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
Persistent<Context> context = Context::New(NULL, global_template); Persistent<Context> context = Context::New(NULL, global_template);
ASSERT(!context.IsEmpty()); ASSERT(!context.IsEmpty());
Context::Scope scope(context); Context::Scope scope(context);
PerIsolateData::Get(isolate)->RealmInit();
#ifndef V8_SHARED #ifndef V8_SHARED
i::JSArguments js_args = i::FLAG_js_arguments; i::JSArguments js_args = i::FLAG_js_arguments;
...@@ -1670,8 +1469,7 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) { ...@@ -1670,8 +1469,7 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) {
} }
Isolate* isolate = args.GetIsolate(); Isolate* isolate = args.GetIsolate();
Handle<Object> buffer = Object::New(); Handle<Object> buffer = Object::New();
buffer->SetHiddenValue( buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True());
PerIsolateData::ArrayBufferMarkerPropName_string(isolate), True());
Persistent<Object> persistent_buffer = Persistent<Object> persistent_buffer =
Persistent<Object>::New(isolate, buffer); Persistent<Object>::New(isolate, buffer);
persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback);
...@@ -1680,7 +1478,7 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) { ...@@ -1680,7 +1478,7 @@ Handle<Value> Shell::ReadBuffer(const Arguments& args) {
buffer->SetIndexedPropertiesToExternalArrayData( buffer->SetIndexedPropertiesToExternalArrayData(
data, kExternalUnsignedByteArray, length); data, kExternalUnsignedByteArray, length);
buffer->Set(PerIsolateData::byteLength_string(isolate), buffer->Set(Symbols::byteLength(isolate),
Int32::New(static_cast<int32_t>(length), isolate), ReadOnly); Int32::New(static_cast<int32_t>(length), isolate), ReadOnly);
return buffer; return buffer;
} }
...@@ -1873,7 +1671,7 @@ void SourceGroup::ExecuteInThread() { ...@@ -1873,7 +1671,7 @@ void SourceGroup::ExecuteInThread() {
Isolate::Scope iscope(isolate); Isolate::Scope iscope(isolate);
Locker lock(isolate); Locker lock(isolate);
HandleScope scope(isolate); HandleScope scope(isolate);
PerIsolateData data(isolate); Symbols symbols(isolate);
Persistent<Context> context = Shell::CreateEvaluationContext(isolate); Persistent<Context> context = Shell::CreateEvaluationContext(isolate);
{ {
Context::Scope cscope(context); Context::Scope cscope(context);
...@@ -2135,7 +1933,7 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -2135,7 +1933,7 @@ int Shell::Main(int argc, char* argv[]) {
#ifdef ENABLE_VTUNE_JIT_INTERFACE #ifdef ENABLE_VTUNE_JIT_INTERFACE
vTune::InitilizeVtuneForV8(); vTune::InitilizeVtuneForV8();
#endif #endif
PerIsolateData data(isolate); Symbols symbols(isolate);
InitializeDebugger(isolate); InitializeDebugger(isolate);
if (options.stress_opt || options.stress_deopt) { if (options.stress_opt || options.stress_deopt) {
......
...@@ -298,19 +298,6 @@ class Shell : public i::AllStatic { ...@@ -298,19 +298,6 @@ class Shell : public i::AllStatic {
#endif // ENABLE_DEBUGGER_SUPPORT #endif // ENABLE_DEBUGGER_SUPPORT
#endif // V8_SHARED #endif // V8_SHARED
static Handle<Value> RealmCurrent(const Arguments& args);
static Handle<Value> RealmOwner(const Arguments& args);
static Handle<Value> RealmGlobal(const Arguments& args);
static Handle<Value> RealmCreate(const Arguments& args);
static Handle<Value> RealmDispose(const Arguments& args);
static Handle<Value> RealmSwitch(const Arguments& args);
static Handle<Value> RealmEval(const Arguments& args);
static Handle<Value> RealmSharedGet(Local<String> property,
const AccessorInfo& info);
static void RealmSharedSet(Local<String> property,
Local<Value> value,
const AccessorInfo& info);
static Handle<Value> Print(const Arguments& args); static Handle<Value> Print(const Arguments& args);
static Handle<Value> Write(const Arguments& args); static Handle<Value> Write(const Arguments& args);
static Handle<Value> Quit(const Arguments& args); static Handle<Value> Quit(const Arguments& args);
......
...@@ -612,6 +612,7 @@ void ScriptCache::Add(Handle<Script> script) { ...@@ -612,6 +612,7 @@ void ScriptCache::Add(Handle<Script> script) {
ASSERT(*script == *reinterpret_cast<Script**>(entry->value)); ASSERT(*script == *reinterpret_cast<Script**>(entry->value));
return; return;
} }
// Globalize the script object, make it weak and use the location of the // Globalize the script object, make it weak and use the location of the
// global handle as the value in the hash map. // global handle as the value in the hash map.
Handle<Script> script_ = Handle<Script> script_ =
......
...@@ -8554,7 +8554,7 @@ class JSWeakMap: public JSObject { ...@@ -8554,7 +8554,7 @@ class JSWeakMap: public JSObject {
class JSArrayBuffer: public JSObject { class JSArrayBuffer: public JSObject {
public: public:
// [backing_store]: backing memory for this array // [backing_store]: backing memory for thsi array
DECL_ACCESSORS(backing_store, void) DECL_ACCESSORS(backing_store, void)
// [byte_length]: length in bytes // [byte_length]: length in bytes
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var realmA = Realm.current();
var realmB = Realm.create();
assertEquals(0, realmA);
assertEquals(1, realmB);
// The global objects match the realms' this binding.
assertSame(this, Realm.global(realmA));
assertSame(Realm.eval(realmB, "this"), Realm.global(realmB));
assertFalse(this === Realm.global(realmB));
// The global object is not accessible cross-realm.
var x = 3;
Realm.shared = this;
assertThrows("Realm.eval(realmB, 'x')");
assertSame(undefined, Realm.eval(realmB, "this.x"));
assertSame(undefined, Realm.eval(realmB, "Realm.shared.x"));
Realm.eval(realmB, "Realm.global(0).y = 1");
assertThrows("y");
assertSame(undefined, this.y);
// Can get or set other objects' properties cross-realm.
var p = {a: 1};
var o = {__proto__: p, b: 2};
Realm.shared = o;
assertSame(1, Realm.eval(realmB, "Realm.shared.a"));
assertSame(2, Realm.eval(realmB, "Realm.shared.b"));
// Cannot get or set a prototype cross-realm.
assertSame(undefined, Realm.eval(realmB, "Realm.shared.__proto__"));
Realm.eval(realmB, "Realm.shared.__proto__ = {c: 3}");
assertSame(1, o.a);
assertSame(undefined, o.c);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment