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

Unified Diff: src/objects.cc

Issue 12183018: Create pre-frozen change records for Object.observe (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 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/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 46539311de9625d9c7ffccc54bd476ab5510a47b..1ca7cc7790735709fea979a1d6f7300302ca6be1 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1750,15 +1750,40 @@ void JSObject::EnqueueChangeRecord(Handle<JSObject> object,
Isolate* isolate = object->GetIsolate();
HandleScope scope;
Handle<String> type = isolate->factory()->LookupUtf8Symbol(type_str);
- if (object->IsJSGlobalObject()) {
+ EnqueueChangeRecord(object, type, name, old_value);
+}
+
+void JSObject::EnqueueChangeRecord(Handle<JSObject> object,
+ Handle<String> type,
+ Handle<String> name,
+ Handle<Object> old_value) {
+ Isolate* isolate = object->GetIsolate();
+ HandleScope scope;
+ if (object->IsJSGlobalObject())
object = handle(JSGlobalObject::cast(*object)->global_receiver(), isolate);
+ Handle<JSObject> change_record = isolate->factory()->NewJSObjectFromMap(
+ old_value->IsTheHole()
+ ? isolate->change_record_map()
+ : isolate->change_record_oldvalue_map());
+
+ // Make sure both properties and elements are frozen.
+ ASSERT(!change_record->map()->is_extensible());
+ Handle<SeededNumberDictionary> elements = NormalizeElements(change_record);
+ elements->set_requires_slow_elements();
+
+ change_record->InObjectPropertyAtPut(JSChangeRecord::kTypeIndex, *type);
+ change_record->InObjectPropertyAtPut(JSChangeRecord::kObjectIndex, *object);
+ change_record->InObjectPropertyAtPut(JSChangeRecord::kNameIndex, *name);
+ if (!old_value->IsTheHole()) {
+ change_record->InObjectPropertyAtPut(
+ JSChangeRecord::kOldValueIndex, *old_value);
}
- Handle<Object> args[] = { type, object, name, old_value };
+
+ Handle<Object> args[] = { change_record };
bool threw;
- Execution::Call(Handle<JSFunction>(isolate->observers_notify_change()),
- Handle<Object>(isolate->heap()->undefined_value()),
- old_value->IsTheHole() ? 3 : 4, args,
- &threw);
+ Execution::Call(isolate->observers_notify_change(),
+ isolate->factory()->undefined_value(),
+ 1, args, &threw);
ASSERT(!threw);
}
@@ -9414,12 +9439,10 @@ MaybeObject* JSArray::SetElementsLength(Object* len) {
CHECK(self->length()->ToArrayIndex(&new_length));
if (old_length != new_length) {
for (int i = 0; i < indices.length(); ++i) {
- JSObject::EnqueueChangeRecord(
- self, "deleted", indices[i], old_values[i]);
+ EnqueueChangeRecord(self, "deleted", indices[i], old_values[i]);
}
- JSObject::EnqueueChangeRecord(
- self, "updated", isolate->factory()->length_symbol(),
- old_length_handle);
+ EnqueueChangeRecord(self, "updated", isolate->factory()->length_symbol(),
+ old_length_handle);
}
return *hresult;
}
« no previous file with comments | « src/objects.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698