Revert "Enable Object.observe by default"

TBR=rossberg
BUG=

Review URL: https://codereview.chromium.org/190853007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19735 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
rafaelw@chromium.org 2014-03-08 03:54:42 +00:00
parent dcf9842e07
commit 0cc44c14e5
13 changed files with 213 additions and 208 deletions

View File

@ -600,7 +600,10 @@ MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate,
}
Handle<Object> old_value;
bool is_observed = *function == *object && function->map()->is_observed();
bool is_observed =
FLAG_harmony_observation &&
*function == *object &&
function->map()->is_observed();
if (is_observed) {
if (function->has_prototype())
old_value = handle(function->prototype(), isolate);

View File

@ -1577,12 +1577,6 @@ void Genesis::InstallNativeFunctions() {
INSTALL_NATIVE(JSObject, "functionCache", function_cache);
INSTALL_NATIVE(JSFunction, "ToCompletePropertyDescriptor",
to_complete_property_descriptor);
INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change);
INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice);
INSTALL_NATIVE(JSFunction, "BeginPerformSplice",
observers_begin_perform_splice);
INSTALL_NATIVE(JSFunction, "EndPerformSplice",
observers_end_perform_splice);
}
@ -1597,6 +1591,14 @@ void Genesis::InstallExperimentalNativeFunctions() {
INSTALL_NATIVE(JSFunction, "DerivedSetTrap", derived_set_trap);
INSTALL_NATIVE(JSFunction, "ProxyEnumerate", proxy_enumerate);
}
if (FLAG_harmony_observation) {
INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change);
INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice);
INSTALL_NATIVE(JSFunction, "BeginPerformSplice",
observers_begin_perform_splice);
INSTALL_NATIVE(JSFunction, "EndPerformSplice",
observers_end_perform_splice);
}
}
#undef INSTALL_NATIVE
@ -2040,6 +2042,7 @@ bool Genesis::InstallExperimentalNatives() {
INSTALL_EXPERIMENTAL_NATIVE(i, symbols, "symbol.js")
INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js")
INSTALL_EXPERIMENTAL_NATIVE(i, collections, "collection.js")
INSTALL_EXPERIMENTAL_NATIVE(i, observation, "object-observe.js")
INSTALL_EXPERIMENTAL_NATIVE(i, promises, "promise.js")
INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js")
INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js")

View File

@ -179,6 +179,8 @@ DEFINE_bool(harmony_promises, false, "enable harmony promises")
DEFINE_bool(harmony_proxies, false, "enable harmony proxies")
DEFINE_bool(harmony_collections, false,
"enable harmony collections (sets, maps, and weak maps)")
DEFINE_bool(harmony_observation, false,
"enable harmony object observation (implies harmony collections")
DEFINE_bool(harmony_generators, false, "enable harmony generators")
DEFINE_bool(harmony_iteration, false, "enable harmony iteration (for-of)")
DEFINE_bool(harmony_numeric_literals, false,
@ -194,6 +196,7 @@ DEFINE_implication(harmony, harmony_symbols)
DEFINE_implication(harmony, harmony_promises)
DEFINE_implication(harmony, harmony_proxies)
DEFINE_implication(harmony, harmony_collections)
DEFINE_implication(harmony, harmony_observation)
DEFINE_implication(harmony, harmony_generators)
DEFINE_implication(harmony, harmony_iteration)
DEFINE_implication(harmony, harmony_numeric_literals)
@ -202,6 +205,7 @@ DEFINE_implication(harmony, harmony_arrays)
DEFINE_implication(harmony, harmony_maths)
DEFINE_implication(harmony_promises, harmony_collections)
DEFINE_implication(harmony_modules, harmony_scoping)
DEFINE_implication(harmony_observation, harmony_collections)
// Flags for experimental implementation features.
DEFINE_bool(packed_arrays, true, "optimizes arrays that have no holes")

View File

@ -1205,7 +1205,7 @@ MaybeObject* StoreIC::Store(Handle<Object> object,
}
// Observed objects are always modified through the runtime.
if (receiver->map()->is_observed()) {
if (FLAG_harmony_observation && receiver->map()->is_observed()) {
Handle<Object> result = JSReceiver::SetProperty(
receiver, name, value, NONE, strict_mode(), store_mode);
RETURN_IF_EMPTY_HANDLE(isolate(), result);
@ -1671,7 +1671,7 @@ MaybeObject* KeyedStoreIC::Store(Handle<Object> object,
if (maybe_object->IsFailure()) return maybe_object;
} else {
bool use_ic = FLAG_use_ic && !object->IsAccessCheckNeeded() &&
!(object->IsJSObject() &&
!(FLAG_harmony_observation && object->IsJSObject() &&
JSObject::cast(*object)->map()->is_observed());
if (use_ic && !object->IsSmi()) {
// Don't use ICs for maps of the objects in Array's prototype chain. We

View File

@ -56,86 +56,40 @@
// implementation of (1) and (2) have "optimized" states which represent
// common cases which can be handled more efficiently.
var observationState;
var observationState = %GetObservationState();
if (IS_UNDEFINED(observationState.callbackInfoMap)) {
observationState.callbackInfoMap = %ObservationWeakMapCreate();
observationState.objectInfoMap = %ObservationWeakMapCreate();
observationState.notifierObjectInfoMap = %ObservationWeakMapCreate();
observationState.pendingObservers = null;
observationState.nextCallbackPriority = 0;
}
function GetObservationState() {
if (IS_UNDEFINED(observationState))
observationState = %GetObservationState();
function ObservationWeakMap(map) {
this.map_ = map;
}
if (IS_UNDEFINED(observationState.callbackInfoMap)) {
observationState.callbackInfoMap = %ObservationWeakMapCreate();
observationState.objectInfoMap = %ObservationWeakMapCreate();
observationState.notifierObjectInfoMap = %ObservationWeakMapCreate();
observationState.pendingObservers = null;
observationState.nextCallbackPriority = 0;
ObservationWeakMap.prototype = {
get: function(key) {
key = %UnwrapGlobalProxy(key);
if (!IS_SPEC_OBJECT(key)) return UNDEFINED;
return %WeakCollectionGet(this.map_, key);
},
set: function(key, value) {
key = %UnwrapGlobalProxy(key);
if (!IS_SPEC_OBJECT(key)) return UNDEFINED;
%WeakCollectionSet(this.map_, key, value);
},
has: function(key) {
return !IS_UNDEFINED(this.get(key));
}
};
return observationState;
}
function GetWeakMapWrapper() {
function MapWrapper(map) {
this.map_ = map;
};
MapWrapper.prototype = {
get: function(key) {
key = %UnwrapGlobalProxy(key);
if (!IS_SPEC_OBJECT(key)) return UNDEFINED;
return %WeakCollectionGet(this.map_, key);
},
set: function(key, value) {
key = %UnwrapGlobalProxy(key);
if (!IS_SPEC_OBJECT(key)) return UNDEFINED;
%WeakCollectionSet(this.map_, key, value);
},
has: function(key) {
return !IS_UNDEFINED(this.get(key));
}
};
return MapWrapper;
}
var contextMaps;
function GetContextMaps() {
if (IS_UNDEFINED(contextMaps)) {
var map = GetWeakMapWrapper();
var observationState = GetObservationState();
contextMaps = {
callbackInfoMap: new map(observationState.callbackInfoMap),
objectInfoMap: new map(observationState.objectInfoMap),
notifierObjectInfoMap: new map(observationState.notifierObjectInfoMap)
};
}
return contextMaps;
}
function GetCallbackInfoMap() {
return GetContextMaps().callbackInfoMap;
}
function GetObjectInfoMap() {
return GetContextMaps().objectInfoMap;
}
function GetNotifierObjectInfoMap() {
return GetContextMaps().notifierObjectInfoMap;
}
function GetPendingObservers() {
return GetObservationState().pendingObservers;
}
function SetPendingObservers(pendingObservers) {
GetObservationState().pendingObservers = pendingObservers;
}
function GetNextCallbackPriority() {
return GetObservationState().nextCallbackPriority++;
}
var callbackInfoMap =
new ObservationWeakMap(observationState.callbackInfoMap);
var objectInfoMap = new ObservationWeakMap(observationState.objectInfoMap);
var notifierObjectInfoMap =
new ObservationWeakMap(observationState.notifierObjectInfoMap);
function nullProtoObject() {
return { __proto__: null };
@ -226,23 +180,23 @@ function ObjectInfoGetOrCreate(object) {
performing: null,
performingCount: 0,
};
GetObjectInfoMap().set(object, objectInfo);
objectInfoMap.set(object, objectInfo);
}
return objectInfo;
}
function ObjectInfoGet(object) {
return GetObjectInfoMap().get(object);
return objectInfoMap.get(object);
}
function ObjectInfoGetFromNotifier(notifier) {
return GetNotifierObjectInfoMap().get(notifier);
return notifierObjectInfoMap.get(notifier);
}
function ObjectInfoGetNotifier(objectInfo) {
if (IS_NULL(objectInfo.notifier)) {
objectInfo.notifier = { __proto__: notifierPrototype };
GetNotifierObjectInfoMap().set(objectInfo.notifier, objectInfo);
notifierObjectInfoMap.set(objectInfo.notifier, objectInfo);
}
return objectInfo.notifier;
@ -348,16 +302,16 @@ function AcceptArgIsValid(arg) {
// priority. When a change record must be enqueued for the callback, it
// normalizes. When delivery clears any pending change records, it re-optimizes.
function CallbackInfoGet(callback) {
return GetCallbackInfoMap().get(callback);
return callbackInfoMap.get(callback);
}
function CallbackInfoGetOrCreate(callback) {
var callbackInfo = GetCallbackInfoMap().get(callback);
var callbackInfo = callbackInfoMap.get(callback);
if (!IS_UNDEFINED(callbackInfo))
return callbackInfo;
var priority = GetNextCallbackPriority();
GetCallbackInfoMap().set(callback, priority);
var priority = observationState.nextCallbackPriority++
callbackInfoMap.set(callback, priority);
return priority;
}
@ -369,12 +323,12 @@ function CallbackInfoGetPriority(callbackInfo) {
}
function CallbackInfoNormalize(callback) {
var callbackInfo = GetCallbackInfoMap().get(callback);
var callbackInfo = callbackInfoMap.get(callback);
if (IS_NUMBER(callbackInfo)) {
var priority = callbackInfo;
callbackInfo = new InternalArray;
callbackInfo.priority = priority;
GetCallbackInfoMap().set(callback, callbackInfo);
callbackInfoMap.set(callback, callbackInfo);
}
return callbackInfo;
}
@ -436,12 +390,12 @@ function ObserverEnqueueIfActive(observer, objectInfo, changeRecord,
}
var callbackInfo = CallbackInfoNormalize(callback);
if (IS_NULL(GetPendingObservers())) {
SetPendingObservers(nullProtoObject())
if (IS_NULL(observationState.pendingObservers)) {
observationState.pendingObservers = nullProtoObject();
GetMicrotaskQueue().push(ObserveMicrotaskRunner);
%SetMicrotaskPending(true);
}
GetPendingObservers()[callbackInfo.priority] = callback;
observationState.pendingObservers[callbackInfo.priority] = callback;
callbackInfo.push(changeRecord);
}
@ -594,17 +548,17 @@ function ObjectGetNotifier(object) {
}
function CallbackDeliverPending(callback) {
var callbackInfo = GetCallbackInfoMap().get(callback);
var callbackInfo = callbackInfoMap.get(callback);
if (IS_UNDEFINED(callbackInfo) || IS_NUMBER(callbackInfo))
return false;
// Clear the pending change records from callback and return it to its
// "optimized" state.
var priority = callbackInfo.priority;
GetCallbackInfoMap().set(callback, priority);
callbackInfoMap.set(callback, priority);
if (GetPendingObservers())
delete GetPendingObservers()[priority];
if (observationState.pendingObservers)
delete observationState.pendingObservers[priority];
var delivered = [];
%MoveArrayContents(callbackInfo, delivered);
@ -623,9 +577,9 @@ function ObjectDeliverChangeRecords(callback) {
}
function ObserveMicrotaskRunner() {
var pendingObservers = GetPendingObservers();
var pendingObservers = observationState.pendingObservers;
if (pendingObservers) {
SetPendingObservers(null);
observationState.pendingObservers = null;
for (var i in pendingObservers) {
CallbackDeliverPending(pendingObservers[i]);
}

View File

@ -2199,7 +2199,8 @@ Handle<Object> JSObject::AddProperty(Handle<JSObject> object,
AddSlowProperty(object, name, value, attributes);
}
if (object->map()->is_observed() &&
if (FLAG_harmony_observation &&
object->map()->is_observed() &&
*name != isolate->heap()->hidden_string()) {
Handle<Object> old_value = isolate->factory()->the_hole_value();
EnqueueChangeRecord(object, "add", name, old_value);
@ -4089,7 +4090,8 @@ Handle<Object> JSObject::SetPropertyForResult(Handle<JSObject> object,
}
Handle<Object> old_value = isolate->factory()->the_hole_value();
bool is_observed = object->map()->is_observed() &&
bool is_observed = FLAG_harmony_observation &&
object->map()->is_observed() &&
*name != isolate->heap()->hidden_string();
if (is_observed && lookup->IsDataProperty()) {
old_value = Object::GetProperty(object, name);
@ -4211,7 +4213,8 @@ Handle<Object> JSObject::SetLocalPropertyIgnoreAttributes(
Handle<Object> old_value = isolate->factory()->the_hole_value();
PropertyAttributes old_attributes = ABSENT;
bool is_observed = object->map()->is_observed() &&
bool is_observed = FLAG_harmony_observation &&
object->map()->is_observed() &&
*name != isolate->heap()->hidden_string();
if (is_observed && lookup.IsProperty()) {
if (lookup.IsDataProperty()) old_value =
@ -5193,7 +5196,7 @@ Handle<Object> JSObject::DeleteElement(Handle<JSObject> object,
Handle<Object> old_value;
bool should_enqueue_change_record = false;
if (object->map()->is_observed()) {
if (FLAG_harmony_observation && object->map()->is_observed()) {
should_enqueue_change_record = HasLocalElement(object, index);
if (should_enqueue_change_record) {
old_value = object->GetLocalElementAccessorPair(index) != NULL
@ -5264,7 +5267,8 @@ Handle<Object> JSObject::DeleteProperty(Handle<JSObject> object,
}
Handle<Object> old_value = isolate->factory()->the_hole_value();
bool is_observed = object->map()->is_observed() &&
bool is_observed = FLAG_harmony_observation &&
object->map()->is_observed() &&
*name != isolate->heap()->hidden_string();
if (is_observed && lookup.IsDataProperty()) {
old_value = Object::GetProperty(object, name);
@ -5500,7 +5504,7 @@ Handle<Object> JSObject::PreventExtensions(Handle<JSObject> object) {
object->set_map(*new_map);
ASSERT(!object->map()->is_extensible());
if (object->map()->is_observed()) {
if (FLAG_harmony_observation && object->map()->is_observed()) {
EnqueueChangeRecord(object, "preventExtensions", Handle<Name>(),
isolate->factory()->the_hole_value());
}
@ -6357,7 +6361,8 @@ void JSObject::DefineAccessor(Handle<JSObject> object,
bool is_element = name->AsArrayIndex(&index);
Handle<Object> old_value = isolate->factory()->the_hole_value();
bool is_observed = object->map()->is_observed() &&
bool is_observed = FLAG_harmony_observation &&
object->map()->is_observed() &&
*name != isolate->heap()->hidden_string();
bool preexists = false;
if (is_observed) {
@ -11417,7 +11422,7 @@ static void EndPerformSplice(Handle<JSArray> object) {
MaybeObject* JSArray::SetElementsLength(Object* len) {
// We should never end in here with a pixel or external array.
ASSERT(AllowsSetElementsLength());
if (!map()->is_observed())
if (!(FLAG_harmony_observation && map()->is_observed()))
return GetElementsAccessor()->SetLength(this, len);
Isolate* isolate = GetIsolate();
@ -12548,7 +12553,7 @@ Handle<Object> JSObject::SetElement(Handle<JSObject> object,
dictionary->set_requires_slow_elements();
}
if (!object->map()->is_observed()) {
if (!(FLAG_harmony_observation && object->map()->is_observed())) {
return object->HasIndexedInterceptor()
? SetElementWithInterceptor(object, index, value, attributes, strict_mode,
check_prototype,
@ -13149,7 +13154,7 @@ bool JSObject::ShouldConvertToFastElements() {
if (IsAccessCheckNeeded()) return false;
// Observed objects may not go to fast mode because they rely on map checks,
// and for fast element accesses we sometimes check element kinds only.
if (map()->is_observed()) return false;
if (FLAG_harmony_observation && map()->is_observed()) return false;
FixedArray* elements = FixedArray::cast(this->elements());
SeededNumberDictionary* dictionary = NULL;

View File

@ -1648,7 +1648,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetPrototype) {
ASSERT(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
if (obj->map()->is_observed()) {
if (FLAG_harmony_observation && obj->map()->is_observed()) {
Handle<Object> old_value(
GetPrototypeSkipHiddenPrototypes(isolate, *obj), isolate);

View File

@ -2004,14 +2004,8 @@ TEST(PrototypeTransitionClearing) {
Factory* factory = isolate->factory();
v8::HandleScope scope(CcTest::isolate());
CompileRun("var base = {};");
Handle<JSObject> baseObject =
v8::Utils::OpenHandle(
*v8::Handle<v8::Object>::Cast(
CcTest::global()->Get(v8_str("base"))));
int initialTransitions = baseObject->map()->NumberOfProtoTransitions();
CompileRun(
"var base = {};"
"var live = [];"
"for (var i = 0; i < 10; i++) {"
" var object = {};"
@ -2020,22 +2014,25 @@ TEST(PrototypeTransitionClearing) {
" if (i >= 3) live.push(object, prototype);"
"}");
Handle<JSObject> baseObject =
v8::Utils::OpenHandle(
*v8::Handle<v8::Object>::Cast(
CcTest::global()->Get(v8_str("base"))));
// Verify that only dead prototype transitions are cleared.
CHECK_EQ(initialTransitions + 10,
baseObject->map()->NumberOfProtoTransitions());
CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions());
CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
const int transitions = 10 - 3;
CHECK_EQ(initialTransitions + transitions,
baseObject->map()->NumberOfProtoTransitions());
CHECK_EQ(transitions, baseObject->map()->NumberOfProtoTransitions());
// Verify that prototype transitions array was compacted.
FixedArray* trans = baseObject->map()->GetPrototypeTransitions();
for (int i = initialTransitions; i < initialTransitions + transitions; i++) {
for (int i = 0; i < transitions; i++) {
int j = Map::kProtoTransitionHeaderSize +
i * Map::kProtoTransitionElementsPerEntry;
CHECK(trans->get(j + Map::kProtoTransitionMapOffset)->IsMap());
Object* proto = trans->get(j + Map::kProtoTransitionPrototypeOffset);
CHECK(proto->IsJSObject());
CHECK(proto->IsTheHole() || proto->IsJSObject());
}
// Make sure next prototype is placed on an old-space evacuation candidate.

View File

@ -36,6 +36,7 @@ namespace {
class HarmonyIsolate {
public:
HarmonyIsolate() {
i::FLAG_harmony_observation = true;
i::FLAG_harmony_promises = true;
isolate_ = Isolate::New();
isolate_->Enter();

View File

@ -32,10 +32,33 @@
using namespace v8;
namespace i = v8::internal;
namespace {
// Need to create a new isolate when FLAG_harmony_observation is on.
class HarmonyIsolate {
public:
HarmonyIsolate() {
i::FLAG_harmony_observation = true;
isolate_ = Isolate::New();
isolate_->Enter();
}
~HarmonyIsolate() {
isolate_->Exit();
isolate_->Dispose();
}
Isolate* GetIsolate() const { return isolate_; }
private:
Isolate* isolate_;
};
}
TEST(PerIsolateState) {
HandleScope scope(CcTest::isolate());
LocalContext context1(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context1(isolate.GetIsolate());
CompileRun(
"var count = 0;"
"var calls = 0;"
@ -48,29 +71,29 @@ TEST(PerIsolateState) {
"(function() { obj.foo = 'bar'; })");
Handle<Value> notify_fun2;
{
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
obj);
notify_fun2 = CompileRun(
"(function() { obj.foo = 'baz'; })");
}
Handle<Value> notify_fun3;
{
LocalContext context3(CcTest::isolate());
context3->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context3(isolate.GetIsolate());
context3->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
obj);
notify_fun3 = CompileRun(
"(function() { obj.foo = 'bat'; })");
}
{
LocalContext context4(CcTest::isolate());
LocalContext context4(isolate.GetIsolate());
context4->Global()->Set(
String::NewFromUtf8(CcTest::isolate(), "observer"), observer);
context4->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "fun1"),
String::NewFromUtf8(isolate.GetIsolate(), "observer"), observer);
context4->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "fun1"),
notify_fun1);
context4->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "fun2"),
context4->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "fun2"),
notify_fun2);
context4->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "fun3"),
context4->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "fun3"),
notify_fun3);
CompileRun("fun1(); fun2(); fun3(); Object.deliverChangeRecords(observer)");
}
@ -80,8 +103,9 @@ TEST(PerIsolateState) {
TEST(EndOfMicrotaskDelivery) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"var count = 0;"
@ -93,8 +117,9 @@ TEST(EndOfMicrotaskDelivery) {
TEST(DeliveryOrdering) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj1 = {};"
"var obj2 = {};"
@ -124,8 +149,9 @@ TEST(DeliveryOrdering) {
TEST(DeliveryOrderingReentrant) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"var reentered = false;"
@ -155,8 +181,9 @@ TEST(DeliveryOrderingReentrant) {
TEST(DeliveryOrderingDeliverChangeRecords) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"var ordering = [];"
@ -179,20 +206,21 @@ TEST(DeliveryOrderingDeliverChangeRecords) {
TEST(ObjectHashTableGrowth) {
HandleScope scope(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
// Initializing this context sets up initial hash tables.
LocalContext context(CcTest::isolate());
LocalContext context(isolate.GetIsolate());
Handle<Value> obj = CompileRun("obj = {};");
Handle<Value> observer = CompileRun(
"var ran = false;"
"(function() { ran = true })");
{
// As does initializing this context.
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
obj);
context2->Global()->Set(
String::NewFromUtf8(CcTest::isolate(), "observer"), observer);
String::NewFromUtf8(isolate.GetIsolate(), "observer"), observer);
CompileRun(
"var objArr = [];"
// 100 objects should be enough to make the hash table grow
@ -210,8 +238,9 @@ TEST(ObjectHashTableGrowth) {
TEST(GlobalObjectObservation) {
LocalContext context(CcTest::isolate());
HandleScope scope(CcTest::isolate());
HarmonyIsolate isolate;
LocalContext context(isolate.GetIsolate());
HandleScope scope(isolate.GetIsolate());
Handle<Object> global_proxy = context->Global();
CompileRun(
"var records = [];"
@ -232,7 +261,7 @@ TEST(GlobalObjectObservation) {
// to the old context.
context->DetachGlobal();
{
LocalContext context2(CcTest::isolate());
LocalContext context2(isolate.GetIsolate());
CompileRun(
"var records2 = [];"
"var global = this;"
@ -250,7 +279,7 @@ TEST(GlobalObjectObservation) {
{
// Delegates to Context::New
LocalContext context3(
CcTest::isolate(), NULL, Handle<ObjectTemplate>(), global_proxy);
isolate.GetIsolate(), NULL, Handle<ObjectTemplate>(), global_proxy);
CompileRun(
"var records3 = [];"
"Object.observe(this, function(r) { [].push.apply(records3, r) });"
@ -298,11 +327,12 @@ static void ExpectRecords(v8::Isolate* isolate,
}
#define EXPECT_RECORDS(records, expectations) \
ExpectRecords(CcTest::isolate(), records, expectations, \
ExpectRecords(isolate.GetIsolate(), records, expectations, \
ARRAY_SIZE(expectations))
TEST(APITestBasicMutation) {
v8::Isolate* v8_isolate = CcTest::isolate();
HarmonyIsolate isolate;
v8::Isolate* v8_isolate = isolate.GetIsolate();
HandleScope scope(v8_isolate);
LocalContext context(v8_isolate);
Handle<Object> obj = Handle<Object>::Cast(CompileRun(
@ -349,7 +379,8 @@ TEST(APITestBasicMutation) {
TEST(HiddenPrototypeObservation) {
v8::Isolate* v8_isolate = CcTest::isolate();
HarmonyIsolate isolate;
v8::Isolate* v8_isolate = isolate.GetIsolate();
HandleScope scope(v8_isolate);
LocalContext context(v8_isolate);
Handle<FunctionTemplate> tmpl = FunctionTemplate::New(v8_isolate);
@ -400,14 +431,15 @@ static int NumberOfElements(i::Handle<i::JSWeakMap> map) {
TEST(ObservationWeakMap) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
CompileRun(
"var obj = {};"
"Object.observe(obj, function(){});"
"Object.getNotifier(obj);"
"obj = null;");
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(CcTest::isolate());
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate.GetIsolate());
i::Handle<i::JSObject> observation_state =
i_isolate->factory()->observation_state();
i::Handle<i::JSWeakMap> callbackInfoMap =
@ -496,16 +528,17 @@ static Handle<Object> CreateAccessCheckedObject(
TEST(NamedAccessCheck) {
HarmonyIsolate isolate;
const AccessType types[] = { ACCESS_GET, ACCESS_HAS };
for (size_t i = 0; i < ARRAY_SIZE(types); ++i) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
g_access_block_type = types[i];
Handle<Object> instance = CreateAccessCheckedObject(
CcTest::isolate(),
isolate.GetIsolate(),
NamedAccessAllowUnlessBlocked,
IndexedAccessAlwaysAllowed,
String::NewFromUtf8(CcTest::isolate(), "foo"));
String::NewFromUtf8(isolate.GetIsolate(), "foo"));
CompileRun("var records = null;"
"var objNoCheck = {};"
"var observer = function(r) { records = r };"
@ -513,11 +546,11 @@ TEST(NamedAccessCheck) {
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
instance);
context2->Global()->Set(
String::NewFromUtf8(CcTest::isolate(), "objNoCheck"),
String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"),
obj_no_check);
CompileRun("var records2 = null;"
"var observer2 = function(r) { records2 = r };"
@ -531,9 +564,9 @@ TEST(NamedAccessCheck) {
const RecordExpectation expected_records2[] = {
{ instance, "add", "foo", Handle<Value>() },
{ instance, "update", "foo",
String::NewFromUtf8(CcTest::isolate(), "bar") },
String::NewFromUtf8(isolate.GetIsolate(), "bar") },
{ instance, "reconfigure", "foo",
Number::New(CcTest::isolate(), 5) },
Number::New(isolate.GetIsolate(), 5) },
{ instance, "add", "bar", Handle<Value>() },
{ obj_no_check, "add", "baz", Handle<Value>() },
};
@ -549,14 +582,15 @@ TEST(NamedAccessCheck) {
TEST(IndexedAccessCheck) {
HarmonyIsolate isolate;
const AccessType types[] = { ACCESS_GET, ACCESS_HAS };
for (size_t i = 0; i < ARRAY_SIZE(types); ++i) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
g_access_block_type = types[i];
Handle<Object> instance = CreateAccessCheckedObject(
CcTest::isolate(), NamedAccessAlwaysAllowed,
IndexedAccessAllowUnlessBlocked, Number::New(CcTest::isolate(), 7));
isolate.GetIsolate(), NamedAccessAlwaysAllowed,
IndexedAccessAllowUnlessBlocked, Number::New(isolate.GetIsolate(), 7));
CompileRun("var records = null;"
"var objNoCheck = {};"
"var observer = function(r) { records = r };"
@ -564,11 +598,11 @@ TEST(IndexedAccessCheck) {
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
instance);
context2->Global()->Set(
String::NewFromUtf8(CcTest::isolate(), "objNoCheck"),
String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"),
obj_no_check);
CompileRun("var records2 = null;"
"var observer2 = function(r) { records2 = r };"
@ -582,8 +616,8 @@ TEST(IndexedAccessCheck) {
const RecordExpectation expected_records2[] = {
{ instance, "add", "7", Handle<Value>() },
{ instance, "update", "7",
String::NewFromUtf8(CcTest::isolate(), "foo") },
{ instance, "reconfigure", "7", Number::New(CcTest::isolate(), 5) },
String::NewFromUtf8(isolate.GetIsolate(), "foo") },
{ instance, "reconfigure", "7", Number::New(isolate.GetIsolate(), 5) },
{ instance, "add", "8", Handle<Value>() },
{ obj_no_check, "add", "42", Handle<Value>() }
};
@ -599,12 +633,13 @@ TEST(IndexedAccessCheck) {
TEST(SpliceAccessCheck) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
g_access_block_type = ACCESS_GET;
Handle<Object> instance = CreateAccessCheckedObject(
CcTest::isolate(), NamedAccessAlwaysAllowed,
IndexedAccessAllowUnlessBlocked, Number::New(CcTest::isolate(), 1));
isolate.GetIsolate(), NamedAccessAlwaysAllowed,
IndexedAccessAllowUnlessBlocked, Number::New(isolate.GetIsolate(), 1));
CompileRun("var records = null;"
"obj[1] = 'foo';"
"obj.length = 2;"
@ -614,11 +649,11 @@ TEST(SpliceAccessCheck) {
"Array.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
instance);
context2->Global()->Set(
String::NewFromUtf8(CcTest::isolate(), "objNoCheck"), obj_no_check);
String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"), obj_no_check);
CompileRun("var records2 = null;"
"var observer2 = function(r) { records2 = r };"
"Array.observe(obj, observer2);"
@ -645,10 +680,11 @@ TEST(SpliceAccessCheck) {
TEST(DisallowAllForAccessKeys) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
Handle<Object> instance = CreateAccessCheckedObject(
CcTest::isolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed);
isolate.GetIsolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed);
CompileRun("var records = null;"
"var objNoCheck = {};"
"var observer = function(r) { records = r };"
@ -656,11 +692,11 @@ TEST(DisallowAllForAccessKeys) {
"Object.observe(objNoCheck, observer);");
Handle<Value> obj_no_check = CompileRun("objNoCheck");
{
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
instance);
context2->Global()->Set(
String::NewFromUtf8(CcTest::isolate(), "objNoCheck"), obj_no_check);
String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"), obj_no_check);
CompileRun("var records2 = null;"
"var observer2 = function(r) { records2 = r };"
"Object.observe(obj, observer2);"
@ -683,23 +719,24 @@ TEST(DisallowAllForAccessKeys) {
TEST(AccessCheckDisallowApiModifications) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
Handle<Object> instance = CreateAccessCheckedObject(
CcTest::isolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed);
isolate.GetIsolate(), BlockAccessKeys, IndexedAccessAlwaysAllowed);
CompileRun("var records = null;"
"var observer = function(r) { records = r };"
"Object.observe(obj, observer);");
{
LocalContext context2(CcTest::isolate());
context2->Global()->Set(String::NewFromUtf8(CcTest::isolate(), "obj"),
LocalContext context2(isolate.GetIsolate());
context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"),
instance);
CompileRun("var records2 = null;"
"var observer2 = function(r) { records2 = r };"
"Object.observe(obj, observer2);");
instance->Set(5, String::NewFromUtf8(CcTest::isolate(), "bar"));
instance->Set(String::NewFromUtf8(CcTest::isolate(), "foo"),
String::NewFromUtf8(CcTest::isolate(), "bar"));
instance->Set(5, String::NewFromUtf8(isolate.GetIsolate(), "bar"));
instance->Set(String::NewFromUtf8(isolate.GetIsolate(), "foo"),
String::NewFromUtf8(isolate.GetIsolate(), "bar"));
CompileRun(""); // trigger delivery
const RecordExpectation expected_records2[] = {
{ instance, "add", "5", Handle<Value>() },
@ -712,17 +749,18 @@ TEST(AccessCheckDisallowApiModifications) {
TEST(HiddenPropertiesLeakage) {
HandleScope scope(CcTest::isolate());
LocalContext context(CcTest::isolate());
HarmonyIsolate isolate;
HandleScope scope(isolate.GetIsolate());
LocalContext context(isolate.GetIsolate());
CompileRun("var obj = {};"
"var records = null;"
"var observer = function(r) { records = r };"
"Object.observe(obj, observer);");
Handle<Value> obj =
context->Global()->Get(String::NewFromUtf8(CcTest::isolate(), "obj"));
context->Global()->Get(String::NewFromUtf8(isolate.GetIsolate(), "obj"));
Handle<Object>::Cast(obj)
->SetHiddenValue(String::NewFromUtf8(CcTest::isolate(), "foo"),
Null(CcTest::isolate()));
->SetHiddenValue(String::NewFromUtf8(isolate.GetIsolate(), "foo"),
Null(isolate.GetIsolate()));
CompileRun(""); // trigger delivery
CHECK(CompileRun("records")->IsNull());
}

View File

@ -59,7 +59,7 @@ for (i = 0; i < scripts.length; i++) {
}
// This has to be updated if the number of native scripts change.
assertTrue(named_native_count == 17 || named_native_count == 18);
assertTrue(named_native_count == 16 || named_native_count == 17);
// Only the 'gc' extension is loaded.
assertEquals(1, extension_count);
// This script and mjsunit.js has been loaded. If using d8, d8 loads

View File

@ -1062,7 +1062,6 @@
'../../src/regexp.js',
'../../src/arraybuffer.js',
'../../src/typedarray.js',
'../../src/object-observe.js',
'../../src/macros.py',
],
'experimental_library_files': [
@ -1070,6 +1069,7 @@
'../../src/symbol.js',
'../../src/proxy.js',
'../../src/collection.js',
'../../src/object-observe.js',
'../../src/promise.js',
'../../src/generator.js',
'../../src/array-iterator.js',