33 namespace i = v8::internal;
42 "var observer = function(records) { count = records.length; calls++ };"
44 "Object.observe(obj, observer);");
48 "(function() { obj.foo = 'bar'; })");
54 notify_fun2 = CompileRun(
55 "(function() { obj.foo = 'baz'; })");
62 notify_fun3 = CompileRun(
63 "(function() { obj.foo = 'bat'; })");
75 CompileRun(
"fun1(); fun2(); fun3(); Object.deliverChangeRecords(observer)");
77 CHECK_EQ(1, CompileRun(
"calls")->Int32Value());
78 CHECK_EQ(3, CompileRun(
"count")->Int32Value());
82 TEST(EndOfMicrotaskDelivery) {
88 "var observer = function(records) { count = records.length };"
89 "Object.observe(obj, observer);"
91 CHECK_EQ(1, CompileRun(
"count")->Int32Value());
102 "function observer2() { ordering.push(2); };"
103 "function observer1() { ordering.push(1); };"
104 "function observer3() { ordering.push(3); };"
105 "Object.observe(obj1, observer1);"
106 "Object.observe(obj1, observer2);"
107 "Object.observe(obj1, observer3);"
108 "obj1.foo = 'bar';");
109 CHECK_EQ(3, CompileRun(
"ordering.length")->Int32Value());
110 CHECK_EQ(1, CompileRun(
"ordering[0]")->Int32Value());
111 CHECK_EQ(2, CompileRun(
"ordering[1]")->Int32Value());
112 CHECK_EQ(3, CompileRun(
"ordering[2]")->Int32Value());
115 "Object.observe(obj2, observer3);"
116 "Object.observe(obj2, observer2);"
117 "Object.observe(obj2, observer1);"
119 CHECK_EQ(3, CompileRun(
"ordering.length")->Int32Value());
120 CHECK_EQ(1, CompileRun(
"ordering[0]")->Int32Value());
121 CHECK_EQ(2, CompileRun(
"ordering[1]")->Int32Value());
122 CHECK_EQ(3, CompileRun(
"ordering[2]")->Int32Value());
126 TEST(DeliveryOrderingReentrant) {
131 "var reentered = false;"
133 "function observer1() { ordering.push(1); };"
134 "function observer2() {"
141 "function observer3() { ordering.push(3); };"
142 "Object.observe(obj, observer1);"
143 "Object.observe(obj, observer2);"
144 "Object.observe(obj, observer3);"
146 CHECK_EQ(5, CompileRun(
"ordering.length")->Int32Value());
147 CHECK_EQ(1, CompileRun(
"ordering[0]")->Int32Value());
148 CHECK_EQ(2, CompileRun(
"ordering[1]")->Int32Value());
149 CHECK_EQ(3, CompileRun(
"ordering[2]")->Int32Value());
152 CHECK_EQ(1, CompileRun(
"ordering[3]")->Int32Value());
153 CHECK_EQ(2, CompileRun(
"ordering[1]")->Int32Value());
157 TEST(DeliveryOrderingDeliverChangeRecords) {
163 "function observer1() { ordering.push(1); if (!obj.b) obj.b = true };"
164 "function observer2() { ordering.push(2); };"
165 "Object.observe(obj, observer1);"
166 "Object.observe(obj, observer2);"
168 "Object.deliverChangeRecords(observer2);");
169 CHECK_EQ(4, CompileRun(
"ordering.length")->Int32Value());
171 CHECK_EQ(2, CompileRun(
"ordering[0]")->Int32Value());
173 CHECK_EQ(1, CompileRun(
"ordering[1]")->Int32Value());
176 CHECK_EQ(1, CompileRun(
"ordering[2]")->Int32Value());
177 CHECK_EQ(2, CompileRun(
"ordering[3]")->Int32Value());
188 "(function() { ran = true })");
200 "for (var i = 0; i < 100; ++i) {"
202 " Object.observe(objArr[objArr.length-1], function(){});"
204 "Object.observe(obj, observer);");
207 CompileRun(
"obj.foo = 'bar'");
208 CHECK(CompileRun(
"ran")->BooleanValue());
212 TEST(GlobalObjectObservation) {
219 "Object.observe(global, function(r) { [].push.apply(records, r) });"
220 "global.foo = 'hello';");
221 CHECK_EQ(1, CompileRun(
"records.length")->Int32Value());
226 CompileRun(
"global.bar = 'goodbye';");
227 CHECK_EQ(1, CompileRun(
"records.length")->Int32Value());
228 CompileRun(
"this.baz = 'goodbye';");
229 CHECK_EQ(1, CompileRun(
"records.length")->Int32Value());
239 "Object.observe(this, function(r) { [].push.apply(records2, r) });"
240 "this.v1 = 'context2';");
243 "global.v2 = 'context2';"
244 "this.v3 = 'context2';");
245 CHECK_EQ(1, CompileRun(
"records2.length")->Int32Value());
247 CHECK_EQ(1, CompileRun(
"records.length")->Int32Value());
256 "Object.observe(this, function(r) { [].push.apply(records3, r) });"
257 "this.qux = 'context3';");
258 CHECK_EQ(1, CompileRun(
"records3.length")->Int32Value());
261 CHECK_EQ(1, CompileRun(
"records.length")->Int32Value());
280 CHECK_EQ(num, static_cast<int>(recordArray->Length()));
281 for (
int i = 0; i < num; ++i) {
285 CHECK(expectations[i].object->StrictEquals(
289 if (strcmp(
"splice", expectations[i].type) != 0) {
292 if (!expectations[i].old_value.IsEmpty()) {
293 CHECK(expectations[i].old_value->Equals(
300 #define EXPECT_RECORDS(records, expectations) \
301 ExpectRecords(CcTest::isolate(), records, expectations, \
302 ARRAY_SIZE(expectations))
311 "function observer(r) { [].push.apply(records, r); };"
312 "Object.observe(obj, observer);"
332 CompileRun(
"void 0");
333 CHECK_EQ(9, CompileRun(
"records.length")->Int32Value());
351 TEST(HiddenPrototypeObservation) {
367 "function observer(r) { records = r; };"
368 "Object.observe(obj, observer);"
376 CompileRun(
"obj.foo = 43");
383 "Object.observe(proto, observer);"
385 "Object.unobserve(obj, observer);"
407 "Object.observe(obj, function(){});"
408 "Object.getNotifier(obj);"
412 i_isolate->
factory()->observation_state();
422 CHECK_EQ(1, NumberOfElements(callbackInfoMap));
423 CHECK_EQ(1, NumberOfElements(objectInfoMap));
424 CHECK_EQ(1, NumberOfElements(notifierObjectInfoMap));
426 CHECK_EQ(0, NumberOfElements(callbackInfoMap));
427 CHECK_EQ(0, NumberOfElements(objectInfoMap));
428 CHECK_EQ(0, NumberOfElements(notifierObjectInfoMap));
445 static const uint32_t kBlockedContextIndex = 1337;
448 static bool NamedAccessAllowUnlessBlocked(
Local<Object> host,
452 if (type != g_access_block_type)
return true;
456 if (!global->
Has(kBlockedContextIndex))
return true;
461 static bool IndexedAccessAllowUnlessBlocked(
Local<Object> host,
465 if (type != g_access_block_type)
return true;
469 if (!global->
Has(kBlockedContextIndex))
return true;
493 global->
Set(kBlockedContextIndex,
v8::True(isolate));
500 for (
size_t i = 0; i <
ARRAY_SIZE(types); ++i) {
503 g_access_block_type = types[i];
506 NamedAccessAllowUnlessBlocked,
507 IndexedAccessAlwaysAllowed,
509 CompileRun(
"var records = null;"
510 "var objNoCheck = {};"
511 "var observer = function(r) { records = r };"
512 "Object.observe(obj, observer);"
513 "Object.observe(objNoCheck, observer);");
522 CompileRun(
"var records2 = null;"
523 "var observer2 = function(r) { records2 = r };"
524 "Object.observe(obj, observer2);"
525 "Object.observe(objNoCheck, observer2);"
527 "Object.defineProperty(obj, 'foo', {value: 5});"
528 "Object.defineProperty(obj, 'foo', {get: function(){}});"
530 "objNoCheck.baz = 'quux'");
533 { instance,
"update",
"foo",
535 { instance,
"reconfigure",
"foo",
553 for (
size_t i = 0; i <
ARRAY_SIZE(types); ++i) {
556 g_access_block_type = types[i];
560 CompileRun(
"var records = null;"
561 "var objNoCheck = {};"
562 "var observer = function(r) { records = r };"
563 "Object.observe(obj, observer);"
564 "Object.observe(objNoCheck, observer);");
573 CompileRun(
"var records2 = null;"
574 "var observer2 = function(r) { records2 = r };"
575 "Object.observe(obj, observer2);"
576 "Object.observe(objNoCheck, observer2);"
578 "Object.defineProperty(obj, '7', {value: 5});"
579 "Object.defineProperty(obj, '7', {get: function(){}});"
581 "objNoCheck[42] = 'quux'");
584 { instance,
"update",
"7",
608 CompileRun(
"var records = null;"
611 "var objNoCheck = {1: 'bar', length: 2};"
612 "observer = function(r) { records = r };"
613 "Array.observe(obj, observer);"
614 "Array.observe(objNoCheck, observer);");
622 CompileRun(
"var records2 = null;"
623 "var observer2 = function(r) { records2 = r };"
624 "Array.observe(obj, observer2);"
625 "Array.observe(objNoCheck, observer2);"
628 "[].push.call(obj, 5);"
629 "[].splice.call(obj, 1, 1);"
631 "[].pop.call(objNoCheck);");
647 TEST(DisallowAllForAccessKeys) {
652 CompileRun(
"var records = null;"
653 "var objNoCheck = {};"
654 "var observer = function(r) { records = r };"
655 "Object.observe(obj, observer);"
656 "Object.observe(objNoCheck, observer);");
664 CompileRun(
"var records2 = null;"
665 "var observer2 = function(r) { records2 = r };"
666 "Object.observe(obj, observer2);"
667 "Object.observe(objNoCheck, observer2);"
670 "objNoCheck.baz = 'quux'");
685 TEST(AccessCheckDisallowApiModifications) {
690 CompileRun(
"var records = null;"
691 "var observer = function(r) { records = r };"
692 "Object.observe(obj, observer);");
697 CompileRun(
"var records2 = null;"
698 "var observer2 = function(r) { records2 = r };"
699 "Object.observe(obj, observer2);");
710 CHECK(CompileRun(
"records")->IsNull());
714 TEST(HiddenPropertiesLeakage) {
717 CompileRun(
"var obj = {};"
718 "var records = null;"
719 "var observer = function(r) { records = r };"
720 "Object.observe(obj, observer);");
727 CHECK(CompileRun(
"records")->IsNull());
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
#define CHECK_EQ(expected, value)
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
bool StrictEquals(Handle< Value > that) const
Local< Object > NewInstance()
static Handle< T > cast(Handle< S > that)
bool(* IndexedSecurityCallback)(Local< Object > host, uint32_t index, AccessType type, Local< Value > data)
Local< ObjectTemplate > InstanceTemplate()
Local< Context > CreationContext()
Local< Context > GetCurrentContext()
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
bool Equals(Handle< Value > that) const
V8_INLINE Handle< Boolean > True(Isolate *isolate)
static Local< ObjectTemplate > New()
bool ForceDelete(Handle< Value > key)
Handle< Value > old_value
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
static V8_INLINE Handle< T > Cast(Handle< S > that)
static Local< Number > New(Isolate *isolate, double value)
bool SetPrototype(Handle< Value > prototype)
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
void SetHiddenPrototype(bool value)
static const int kAbortIncrementalMarkingMask
static Local< Object > New(Isolate *isolate)
V8_INLINE bool IsString() const
uint32_t Uint32Value() const
static ObjectHashTable * cast(Object *obj)
Local< Function > GetFunction()
bool ForceSet(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
bool(* NamedSecurityCallback)(Local< Object > host, Local< Value > key, AccessType type, Local< Value > data)
bool Has(Handle< Value > key)
V8_INLINE Handle< S > As()
bool Delete(Handle< Value > key)
#define EXPECT_RECORDS(records, expectations)
V8_INLINE Handle< Primitive > Null(Isolate *isolate)
void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, Handle< Value > data=Handle< Value >(), bool turned_on_by_default=true)
bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
static v8::Isolate * isolate()
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)