Commit c6a36305 authored by yangguo's avatar yangguo Committed by Commit bot

Wrap object observe implementation in a function.

R=jkummerow@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27920}
parent 281d30d7
......@@ -407,12 +407,12 @@ function ObservedArrayPop(n) {
var value = this[n];
try {
BeginPerformSplice(this);
$observeBeginPerformSplice(this);
delete this[n];
this.length = n;
} finally {
EndPerformSplice(this);
EnqueueSpliceRecord(this, n, [value], 0);
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, n, [value], 0);
}
return value;
......@@ -446,15 +446,15 @@ function ObservedArrayPush() {
var m = %_ArgumentsLength();
try {
BeginPerformSplice(this);
$observeBeginPerformSplice(this);
for (var i = 0; i < m; i++) {
this[i+n] = %_Arguments(i);
}
var new_length = n + m;
this.length = new_length;
} finally {
EndPerformSplice(this);
EnqueueSpliceRecord(this, n, [], m);
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, n, [], m);
}
return new_length;
......@@ -584,12 +584,12 @@ function ObservedArrayShift(len) {
var first = this[0];
try {
BeginPerformSplice(this);
$observeBeginPerformSplice(this);
SimpleMove(this, 0, 1, len, 0);
this.length = len - 1;
} finally {
EndPerformSplice(this);
EnqueueSpliceRecord(this, 0, [first], 0);
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, 0, [first], 0);
}
return first;
......@@ -632,7 +632,7 @@ function ObservedArrayUnshift() {
var num_arguments = %_ArgumentsLength();
try {
BeginPerformSplice(this);
$observeBeginPerformSplice(this);
SimpleMove(this, 0, 0, len, num_arguments);
for (var i = 0; i < num_arguments; i++) {
this[i] = %_Arguments(i);
......@@ -640,8 +640,8 @@ function ObservedArrayUnshift() {
var new_length = len + num_arguments;
this.length = new_length;
} finally {
EndPerformSplice(this);
EnqueueSpliceRecord(this, 0, [], num_arguments);
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, 0, [], num_arguments);
}
return new_length;
......@@ -758,7 +758,7 @@ function ObservedArraySplice(start, delete_count) {
var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
try {
BeginPerformSplice(this);
$observeBeginPerformSplice(this);
SimpleSlice(this, start_i, del_count, len, deleted_elements);
SimpleMove(this, start_i, del_count, len, num_elements_to_add);
......@@ -774,12 +774,12 @@ function ObservedArraySplice(start, delete_count) {
this.length = len - del_count + num_elements_to_add;
} finally {
EndPerformSplice(this);
$observeEndPerformSplice(this);
if (deleted_elements.length || num_elements_to_add) {
EnqueueSpliceRecord(this,
start_i,
deleted_elements.slice(),
num_elements_to_add);
$observeEnqueueSpliceRecord(this,
start_i,
deleted_elements.slice(),
num_elements_to_add);
}
}
......
......@@ -1565,17 +1565,18 @@ void Genesis::InstallNativeFunctions() {
INSTALL_NATIVE(JSFunction, "PromiseCatch", promise_catch);
INSTALL_NATIVE(JSFunction, "PromiseThen", promise_then);
INSTALL_NATIVE(JSFunction, "NotifyChange", observers_notify_change);
INSTALL_NATIVE(JSFunction, "EnqueueSpliceRecord", observers_enqueue_splice);
INSTALL_NATIVE(JSFunction, "BeginPerformSplice",
INSTALL_NATIVE(JSFunction, "$observeNotifyChange", observers_notify_change);
INSTALL_NATIVE(JSFunction, "$observeEnqueueSpliceRecord",
observers_enqueue_splice);
INSTALL_NATIVE(JSFunction, "$observeBeginPerformSplice",
observers_begin_perform_splice);
INSTALL_NATIVE(JSFunction, "EndPerformSplice",
INSTALL_NATIVE(JSFunction, "$observeEndPerformSplice",
observers_end_perform_splice);
INSTALL_NATIVE(JSFunction, "NativeObjectObserve",
INSTALL_NATIVE(JSFunction, "$observeNativeObjectObserve",
native_object_observe);
INSTALL_NATIVE(JSFunction, "NativeObjectGetNotifier",
INSTALL_NATIVE(JSFunction, "$observeNativeObjectGetNotifier",
native_object_get_notifier);
INSTALL_NATIVE(JSFunction, "NativeObjectNotifierPerformChange",
INSTALL_NATIVE(JSFunction, "$observeNativeObjectNotifierPerformChange",
native_object_notifier_perform_change);
INSTALL_NATIVE(JSFunction, "$arrayValues", array_values_iterator);
}
......
This diff is collapsed.
......@@ -909,7 +909,7 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
var emit_splice = %IsObserved(obj) && new_length !== old_length;
var removed;
if (emit_splice) {
BeginPerformSplice(obj);
$observeBeginPerformSplice(obj);
removed = [];
if (new_length < old_length)
removed.length = old_length - new_length;
......@@ -930,8 +930,8 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
}
threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw;
if (emit_splice) {
EndPerformSplice(obj);
EnqueueSpliceRecord(obj,
$observeEndPerformSplice(obj);
$observeEnqueueSpliceRecord(obj,
new_length < old_length ? new_length : old_length,
removed,
new_length > old_length ? new_length - old_length : 0);
......@@ -954,14 +954,14 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
var length = obj.length;
if (index >= length && %IsObserved(obj)) {
emit_splice = true;
BeginPerformSplice(obj);
$observeBeginPerformSplice(obj);
}
var length_desc = GetOwnPropertyJS(obj, "length");
if ((index >= length && !length_desc.isWritable()) ||
!DefineObjectProperty(obj, p, desc, true)) {
if (emit_splice)
EndPerformSplice(obj);
$observeEndPerformSplice(obj);
if (should_throw) {
throw MakeTypeError("define_disallowed", [p]);
} else {
......@@ -972,8 +972,8 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
obj.length = index + 1;
}
if (emit_splice) {
EndPerformSplice(obj);
EnqueueSpliceRecord(obj, length, [], index + 1 - length);
$observeEndPerformSplice(obj);
$observeEnqueueSpliceRecord(obj, length, [], index + 1 - length);
}
return true;
}
......
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