Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 LocalContext context3(NULL, Handle<ObjectTemplate>(), global_proxy); | 271 LocalContext context3(NULL, Handle<ObjectTemplate>(), global_proxy); |
| 272 CompileRun( | 272 CompileRun( |
| 273 "var records3 = [];" | 273 "var records3 = [];" |
| 274 "Object.observe(this, function(r) { [].push.apply(records3, r) });" | 274 "Object.observe(this, function(r) { [].push.apply(records3, r) });" |
| 275 "this.qux = 'context3';"); | 275 "this.qux = 'context3';"); |
| 276 CHECK_EQ(1, CompileRun("records3.length")->Int32Value()); | 276 CHECK_EQ(1, CompileRun("records3.length")->Int32Value()); |
| 277 CHECK(global_proxy->StrictEquals(CompileRun("records3[0].object"))); | 277 CHECK(global_proxy->StrictEquals(CompileRun("records3[0].object"))); |
| 278 } | 278 } |
| 279 CHECK_EQ(3, CompileRun("records.length")->Int32Value()); | 279 CHECK_EQ(3, CompileRun("records.length")->Int32Value()); |
| 280 } | 280 } |
| 281 | |
| 282 TEST(APITestBasicMutation) { | |
| 283 HarmonyIsolate isolate; | |
| 284 HandleScope scope; | |
| 285 LocalContext context; | |
| 286 Handle<Object> obj = Handle<Object>::Cast(CompileRun( | |
| 287 "var records = [];" | |
| 288 "var obj = {};" | |
| 289 "function observer(r) { [].push.apply(records, r); };" | |
| 290 "Object.observe(obj, observer);" | |
| 291 "obj")); | |
| 292 obj->Set(String::New("foo"), Number::New(1)); | |
| 293 obj->Set(1, Number::New(2)); | |
| 294 // ForceSet should work just as well as Set | |
| 295 obj->ForceSet(String::New("foo"), Number::New(3)); | |
| 296 obj->ForceSet(Number::New(1), Number::New(4)); | |
| 297 // Setting an indexed element via the property setting method | |
| 298 obj->Set(Number::New(1), Number::New(5)); | |
| 299 // Setting with a non-String, non-uint32 key | |
| 300 obj->Set(Number::New(1.1), Number::New(6), DontDelete); | |
| 301 obj->Delete(String::New("foo")); | |
| 302 obj->Delete(1); | |
| 303 obj->ForceDelete(Number::New(1.1)); | |
| 304 | |
| 305 // Force delivery | |
| 306 // TODO(adamk): Should the above set methods trigger delivery themselves? | |
| 307 CompileRun("void 0"); | |
| 308 CHECK_EQ(9, CompileRun("records.length")->Int32Value()); | |
| 309 ExpectString("records[0].type", "new"); | |
|
rossberg
2012/12/18 13:35:58
Can you check object and oldValue as well? Perhaps
adamk
2012/12/18 17:26:10
Added a helper. Will do a cleanup in a future chan
| |
| 310 ExpectString("records[0].name", "foo"); | |
| 311 ExpectString("records[1].type", "new"); | |
| 312 ExpectString("records[1].name", "1"); | |
| 313 ExpectString("records[2].type", "updated"); | |
| 314 ExpectString("records[2].name", "foo"); | |
| 315 ExpectString("records[3].type", "updated"); | |
| 316 ExpectString("records[3].name", "1"); | |
| 317 ExpectString("records[4].type", "updated"); | |
| 318 ExpectString("records[4].name", "1"); | |
| 319 ExpectString("records[5].type", "new"); | |
| 320 ExpectString("records[5].name", "1.1"); | |
| 321 ExpectString("records[6].type", "deleted"); | |
| 322 ExpectString("records[6].name", "foo"); | |
| 323 ExpectString("records[7].type", "deleted"); | |
| 324 ExpectString("records[7].name", "1"); | |
| 325 ExpectString("records[8].type", "deleted"); | |
| 326 ExpectString("records[8].name", "1.1"); | |
| 327 } | |
| OLD | NEW |