Commit cd9029a5 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Initial JS stub implementation of Object.observe. Adds support for...

Initial JS stub implementation of Object.observe. Adds support for .object/.unobserve/.notify/.deliverChangeRecords. No delivery mechanism is implemented for end-of-microtask.

Review URL: https://codereview.chromium.org/11225058
Patch from Rafael Weinstein <rafaelw@google.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12819 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8133d859
...@@ -1549,9 +1549,11 @@ function SetUpArray() { ...@@ -1549,9 +1549,11 @@ function SetUpArray() {
// exposed to user code. // exposed to user code.
// Adding only the functions that are actually used. // Adding only the functions that are actually used.
SetUpLockedPrototype(InternalArray, $Array(), $Array( SetUpLockedPrototype(InternalArray, $Array(), $Array(
"indexOf", getFunction("indexOf", ArrayIndexOf),
"join", getFunction("join", ArrayJoin), "join", getFunction("join", ArrayJoin),
"pop", getFunction("pop", ArrayPop), "pop", getFunction("pop", ArrayPop),
"push", getFunction("push", ArrayPush) "push", getFunction("push", ArrayPush),
"splice", getFunction("splice", ArraySplice)
)); ));
} }
......
...@@ -1828,6 +1828,11 @@ bool Genesis::InstallExperimentalNatives() { ...@@ -1828,6 +1828,11 @@ bool Genesis::InstallExperimentalNatives() {
"native collection.js") == 0) { "native collection.js") == 0) {
if (!CompileExperimentalBuiltin(isolate(), i)) return false; if (!CompileExperimentalBuiltin(isolate(), i)) return false;
} }
if (FLAG_harmony_object_observe &&
strcmp(ExperimentalNatives::GetScriptName(i).start(),
"native object-observe.js") == 0) {
if (!CompileExperimentalBuiltin(isolate(), i)) return false;
}
} }
InstallExperimentalNativeFunctions(); InstallExperimentalNativeFunctions();
......
...@@ -144,12 +144,16 @@ DEFINE_bool(harmony_modules, false, ...@@ -144,12 +144,16 @@ DEFINE_bool(harmony_modules, false,
DEFINE_bool(harmony_proxies, false, "enable harmony proxies") DEFINE_bool(harmony_proxies, false, "enable harmony proxies")
DEFINE_bool(harmony_collections, false, DEFINE_bool(harmony_collections, false,
"enable harmony collections (sets, maps, and weak maps)") "enable harmony collections (sets, maps, and weak maps)")
DEFINE_bool(harmony_object_observe, false,
"enable harmony object observation (implies harmony collections")
DEFINE_bool(harmony, false, "enable all harmony features (except typeof)") DEFINE_bool(harmony, false, "enable all harmony features (except typeof)")
DEFINE_implication(harmony, harmony_scoping) DEFINE_implication(harmony, harmony_scoping)
DEFINE_implication(harmony, harmony_modules) DEFINE_implication(harmony, harmony_modules)
DEFINE_implication(harmony, harmony_proxies) DEFINE_implication(harmony, harmony_proxies)
DEFINE_implication(harmony, harmony_collections) DEFINE_implication(harmony, harmony_collections)
DEFINE_implication(harmony, harmony_object_observe)
DEFINE_implication(harmony_modules, harmony_scoping) DEFINE_implication(harmony_modules, harmony_scoping)
DEFINE_implication(harmony_object_observe, harmony_collections)
// Flags for experimental implementation features. // Flags for experimental implementation features.
DEFINE_bool(packed_arrays, true, "optimizes arrays that have no holes") DEFINE_bool(packed_arrays, true, "optimizes arrays that have no holes")
......
...@@ -203,6 +203,10 @@ function FormatMessage(message) { ...@@ -203,6 +203,10 @@ function FormatMessage(message) {
"proxy_repeated_prop_name", ["Trap '", "%1", "' returned repeated property name '", "%2", "'"], "proxy_repeated_prop_name", ["Trap '", "%1", "' returned repeated property name '", "%2", "'"],
"invalid_weakmap_key", ["Invalid value used as weak map key"], "invalid_weakmap_key", ["Invalid value used as weak map key"],
"not_date_object", ["this is not a Date object."], "not_date_object", ["this is not a Date object."],
"observe_non_object", ["Object.", "%0", " cannot ", "%0", " non-object"],
"observe_non_function", ["Object.", "%0", " cannot deliver to non-function"],
"observe_callback_frozen", ["Object.observe cannot deliver to a frozen function object"],
"observe_type_non_string", ["Object.notify provided changeRecord with non-string 'type' property"],
// RangeError // RangeError
"invalid_array_length", ["Invalid array length"], "invalid_array_length", ["Invalid array length"],
"stack_overflow", ["Maximum call stack size exceeded"], "stack_overflow", ["Maximum call stack size exceeded"],
......
...@@ -31,7 +31,7 @@ global.Proxy = new $Object(); ...@@ -31,7 +31,7 @@ global.Proxy = new $Object();
var $Proxy = global.Proxy var $Proxy = global.Proxy
$Proxy.create = function(handler, proto) { function ProxyCreate(handler, proto) {
if (!IS_SPEC_OBJECT(handler)) if (!IS_SPEC_OBJECT(handler))
throw MakeTypeError("handler_non_object", ["create"]) throw MakeTypeError("handler_non_object", ["create"])
if (IS_UNDEFINED(proto)) if (IS_UNDEFINED(proto))
...@@ -41,7 +41,7 @@ $Proxy.create = function(handler, proto) { ...@@ -41,7 +41,7 @@ $Proxy.create = function(handler, proto) {
return %CreateJSProxy(handler, proto) return %CreateJSProxy(handler, proto)
} }
$Proxy.createFunction = function(handler, callTrap, constructTrap) { function ProxyCreateFunction(handler, callTrap, constructTrap) {
if (!IS_SPEC_OBJECT(handler)) if (!IS_SPEC_OBJECT(handler))
throw MakeTypeError("handler_non_object", ["create"]) throw MakeTypeError("handler_non_object", ["create"])
if (!IS_SPEC_FUNCTION(callTrap)) if (!IS_SPEC_FUNCTION(callTrap))
...@@ -62,6 +62,10 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) { ...@@ -62,6 +62,10 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) {
handler, callTrap, constructTrap, $Function.prototype) handler, callTrap, constructTrap, $Function.prototype)
} }
%InstallFunctions($Proxy, DONT_ENUM, [
"create", ProxyCreate,
"createFunction", ProxyCreateFunction
])
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -780,6 +780,7 @@ ...@@ -780,6 +780,7 @@
'../../src/macros.py', '../../src/macros.py',
'../../src/proxy.js', '../../src/proxy.js',
'../../src/collection.js', '../../src/collection.js',
'../../src/object-observe.js'
], ],
}, },
'actions': [ 'actions': [
......
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