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

Native context: use import/export for Object observe related functions.

R=adamk@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#31279}
parent dd24cc33
......@@ -20,6 +20,9 @@ var ObjectHasOwnProperty;
var ObjectIsFrozen;
var ObjectIsSealed;
var ObjectToString;
var ObserveBeginPerformSplice;
var ObserveEndPerformSplice;
var ObserveEnqueueSpliceRecord;
var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
utils.Import(function(from) {
......@@ -29,6 +32,9 @@ utils.Import(function(from) {
ObjectIsFrozen = from.ObjectIsFrozen;
ObjectIsSealed = from.ObjectIsSealed;
ObjectToString = from.ObjectToString;
ObserveBeginPerformSplice = from.ObserveBeginPerformSplice;
ObserveEndPerformSplice = from.ObserveEndPerformSplice;
ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord;
});
// -------------------------------------------------------------------
......@@ -437,12 +443,12 @@ function ObservedArrayPop(n) {
var value = this[n];
try {
$observeBeginPerformSplice(this);
ObserveBeginPerformSplice(this);
delete this[n];
this.length = n;
} finally {
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, n, [value], 0);
ObserveEndPerformSplice(this);
ObserveEnqueueSpliceRecord(this, n, [value], 0);
}
return value;
......@@ -477,15 +483,15 @@ function ObservedArrayPush() {
var m = %_ArgumentsLength();
try {
$observeBeginPerformSplice(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 {
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, n, [], m);
ObserveEndPerformSplice(this);
ObserveEnqueueSpliceRecord(this, n, [], m);
}
return new_length;
......@@ -617,12 +623,12 @@ function ObservedArrayShift(len) {
var first = this[0];
try {
$observeBeginPerformSplice(this);
ObserveBeginPerformSplice(this);
SimpleMove(this, 0, 1, len, 0);
this.length = len - 1;
} finally {
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, 0, [first], 0);
ObserveEndPerformSplice(this);
ObserveEnqueueSpliceRecord(this, 0, [first], 0);
}
return first;
......@@ -664,7 +670,7 @@ function ObservedArrayUnshift() {
var num_arguments = %_ArgumentsLength();
try {
$observeBeginPerformSplice(this);
ObserveBeginPerformSplice(this);
SimpleMove(this, 0, 0, len, num_arguments);
for (var i = 0; i < num_arguments; i++) {
this[i] = %_Arguments(i);
......@@ -672,8 +678,8 @@ function ObservedArrayUnshift() {
var new_length = len + num_arguments;
this.length = new_length;
} finally {
$observeEndPerformSplice(this);
$observeEnqueueSpliceRecord(this, 0, [], num_arguments);
ObserveEndPerformSplice(this);
ObserveEnqueueSpliceRecord(this, 0, [], num_arguments);
}
return new_length;
......@@ -791,7 +797,7 @@ function ObservedArraySplice(start, delete_count) {
var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
try {
$observeBeginPerformSplice(this);
ObserveBeginPerformSplice(this);
SimpleSlice(this, start_i, del_count, len, deleted_elements);
SimpleMove(this, start_i, del_count, len, num_elements_to_add);
......@@ -807,9 +813,9 @@ function ObservedArraySplice(start, delete_count) {
this.length = len - del_count + num_elements_to_add;
} finally {
$observeEndPerformSplice(this);
ObserveEndPerformSplice(this);
if (deleted_elements.length || num_elements_to_add) {
$observeEnqueueSpliceRecord(this,
ObserveEnqueueSpliceRecord(this,
start_i,
deleted_elements.slice(),
num_elements_to_add);
......
......@@ -8,7 +8,10 @@
%CheckIsBootstrapping();
utils.InstallFunctions(global.Object, DONT_ENUM, $observeObjectMethods);
utils.InstallFunctions(global.Array, DONT_ENUM, $observeArrayMethods);
var ObserveArrayMethods = utils.ImportNow("ObserveArrayMethods");
var ObserveObjectMethods = utils.ImportNow("ObserveObjectMethods");;
utils.InstallFunctions(global.Object, DONT_ENUM, ObserveObjectMethods);
utils.InstallFunctions(global.Array, DONT_ENUM, ObserveArrayMethods);
})
......@@ -2,13 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var $observeEnqueueSpliceRecord;
var $observeBeginPerformSplice;
var $observeEndPerformSplice;
var $observeObjectMethods;
var $observeArrayMethods;
(function(global, utils) {
"use strict";
......@@ -684,13 +677,14 @@ utils.InstallFunctions(notifierPrototype, DONT_ENUM, [
"performChange", ObjectNotifierPerformChange
]);
$observeObjectMethods = [
var ObserveObjectMethods = [
"deliverChangeRecords", ObjectDeliverChangeRecords,
"getNotifier", ObjectGetNotifier,
"observe", ObjectObserve,
"unobserve", ObjectUnobserve
];
$observeArrayMethods = [
var ObserveArrayMethods = [
"observe", ArrayObserve,
"unobserve", ArrayUnobserve
];
......@@ -700,12 +694,8 @@ $observeArrayMethods = [
var removePrototypeFn = function(f, i) {
if (i % 2 === 1) %FunctionRemovePrototype(f);
};
$observeObjectMethods.forEach(removePrototypeFn);
$observeArrayMethods.forEach(removePrototypeFn);
$observeEnqueueSpliceRecord = EnqueueSpliceRecord;
$observeBeginPerformSplice = BeginPerformSplice;
$observeEndPerformSplice = EndPerformSplice;
ObserveObjectMethods.forEach(removePrototypeFn);
ObserveArrayMethods.forEach(removePrototypeFn);
%InstallToContext([
"native_object_get_notifier", NativeObjectGetNotifier,
......@@ -717,4 +707,12 @@ $observeEndPerformSplice = EndPerformSplice;
"observers_notify_change", NotifyChange,
]);
utils.Export(function(to) {
to.ObserveArrayMethods = ObserveArrayMethods;
to.ObserveBeginPerformSplice = BeginPerformSplice;
to.ObserveEndPerformSplice = EndPerformSplice;
to.ObserveEnqueueSpliceRecord = EnqueueSpliceRecord;
to.ObserveObjectMethods = ObserveObjectMethods;
});
})
......@@ -184,6 +184,8 @@ function PostNatives(utils) {
"MathMin",
"ObjectIsFrozen",
"ObjectDefineProperty",
"ObserveArrayMethods",
"ObserveObjectMethods",
"OwnPropertyKeys",
"SymbolToString",
"ToNameArray",
......
......@@ -18,6 +18,9 @@ var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var iteratorSymbol = utils.ImportNow("iterator_symbol");
var MathAbs;
var ObserveBeginPerformSplice;
var ObserveEndPerformSplice;
var ObserveEnqueueSpliceRecord;
var ProxyDelegateCallAndConstruct;
var ProxyDerivedHasOwnTrap;
var ProxyDerivedKeysTrap;
......@@ -26,6 +29,9 @@ var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
MathAbs = from.MathAbs;
ObserveBeginPerformSplice = from.ObserveBeginPerformSplice;
ObserveEndPerformSplice = from.ObserveEndPerformSplice;
ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord;
StringIndexOf = from.StringIndexOf;
});
......@@ -806,14 +812,14 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
var length = obj.length;
if (index >= length && %IsObserved(obj)) {
emit_splice = true;
$observeBeginPerformSplice(obj);
ObserveBeginPerformSplice(obj);
}
var length_desc = GetOwnPropertyJS(obj, "length");
if ((index >= length && !length_desc.isWritable()) ||
!DefineObjectProperty(obj, p, desc, true)) {
if (emit_splice)
$observeEndPerformSplice(obj);
ObserveEndPerformSplice(obj);
if (should_throw) {
throw MakeTypeError(kDefineDisallowed, p);
} else {
......@@ -824,8 +830,8 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
obj.length = index + 1;
}
if (emit_splice) {
$observeEndPerformSplice(obj);
$observeEnqueueSpliceRecord(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