Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: test/mjsunit/harmony/private.js

Issue 1182303004: All private symbols are own symbols (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Fix nits Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-symbol.cc ('k') | test/mjsunit/own-symbols.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 for (var i = 1; i < symbols.length; i += 2) { 234 for (var i = 1; i < symbols.length; i += 2) {
235 Object.defineProperty(obj, symbols[i], {value: i, configurable: true}) 235 Object.defineProperty(obj, symbols[i], {value: i, configurable: true})
236 } 236 }
237 } 237 }
238 238
239 239
240 function TestKeyGet(obj) { 240 function TestKeyGet(obj) {
241 var obj2 = Object.create(obj) 241 var obj2 = Object.create(obj)
242 for (var i in symbols) { 242 for (var i in symbols) {
243 assertEquals(i|0, obj[symbols[i]]) 243 assertEquals(i|0, obj[symbols[i]])
244 assertEquals(i|0, obj2[symbols[i]]) 244 // Private symbols key own-properties.
245 assertEquals(undefined, obj2[symbols[i]])
245 } 246 }
246 } 247 }
247 248
248 249
249 function TestKeyHas() { 250 function TestKeyHas() {
250 for (var i in symbols) { 251 for (var i in symbols) {
251 assertTrue(symbols[i] in obj) 252 assertTrue(symbols[i] in obj)
252 assertTrue(Object.hasOwnProperty.call(obj, symbols[i])) 253 assertTrue(Object.hasOwnProperty.call(obj, symbols[i]))
253 } 254 }
254 } 255 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 obj[sym] = 1 346 obj[sym] = 1
346 freeze(obj) 347 freeze(obj)
347 obj[sym] = 2 348 obj[sym] = 2
348 assertEquals(2, obj[sym]) 349 assertEquals(2, obj[sym])
349 assertTrue(delete obj[sym]) 350 assertTrue(delete obj[sym])
350 assertEquals(undefined, obj[sym]) 351 assertEquals(undefined, obj[sym])
351 } 352 }
352 TestSealAndFreeze(Object.seal) 353 TestSealAndFreeze(Object.seal)
353 TestSealAndFreeze(Object.freeze) 354 TestSealAndFreeze(Object.freeze)
354 TestSealAndFreeze(Object.preventExtensions) 355 TestSealAndFreeze(Object.preventExtensions)
356
357
358 var s = %CreatePrivateSymbol("s");
359 var s1 = %CreatePrivateSymbol("s1");
360
361 function TestSimple() {
362 var p = {}
363 p[s] = "moo";
364
365 var o = Object.create(p);
366
367 assertEquals(undefined, o[s]);
368 assertEquals("moo", p[s]);
369
370 o[s] = "bow-wow";
371 assertEquals("bow-wow", o[s]);
372 assertEquals("moo", p[s]);
373 }
374 TestSimple();
375
376
377 function TestICs() {
378 var p = {}
379 p[s] = "moo";
380
381
382 var o = Object.create(p);
383 o[s1] = "bow-wow";
384 function checkNonOwn(o) {
385 assertEquals(undefined, o[s]);
386 assertEquals("bow-wow", o[s1]);
387 }
388
389 checkNonOwn(o);
390
391 // Test monomorphic/optimized.
392 for (var i = 0; i < 1000; i++) {
393 checkNonOwn(o);
394 }
395
396 // Test non-monomorphic.
397 for (var i = 0; i < 1000; i++) {
398 var oNew = Object.create(p);
399 oNew["s" + i] = i;
400 oNew[s1] = "bow-wow";
401 checkNonOwn(oNew);
402 }
403 }
404 TestICs();
OLDNEW
« no previous file with comments | « src/runtime/runtime-symbol.cc ('k') | test/mjsunit/own-symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698