2020-11-16 09:51:46 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
Added support for assignments to global variables in the toplevel code
generator. We use the normal store IC mechanism with the global
object as the receiver. The following code is generated for 'x=true'
at toplevel.
======== IA32:
27 mov eax,0xf5d06161 ;; object: 0xf5d06161 <true>
32 mov ecx,0xf5d09c35 ;; object: 0xf5d09c35 <String[1]: x>
37 push [esi+0x17]
40 call StoreIC_Initialize (0xf5ce75c0) ;; code: STORE_IC, UNINITIALIZED
45 mov [esp],eax
======== X64:
25 movq rax,0x7f867a7b6199 ;; object: 0x7f867a7b6199 <true>
35 movq rcx,0x7f867a7bae71 ;; object: 0x7f867a7bae71 <String[1]: x>
45 push [rsi+0x2f]
49 call StoreIC_Initialize (0x7f8655929ac0) ;; code: STORE_IC, UNINITIALIZED
54 movq [rsp],rax
======== ARM:
32 e59f0054 ldr r0, [pc, #+84] ;; object: 0xf5b78161 <true>
36 e59f2054 ldr r2, [pc, #+84] ;; object: 0xf5b7bc35 <String[1]: x>
40 e598c017 ldr ip, [r8, #+23]
44 e52dc004 str ip, [sp, #-4]!
48 e1a0e00f mov lr, pc
52 e59ff048 ldr pc, [pc, #+72] ;; debug: statement 0
;; code: STORE_IC, UNINITIALIZED
56 e58d0000 str r0, [sp, #+0]
Review URL: http://codereview.chromium.org/305005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3095 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-20 13:37:26 +00:00
|
|
|
|
2020-11-13 15:34:59 +00:00
|
|
|
// Flags: --allow-natives-syntax --opt --no-always-opt
|
|
|
|
|
|
|
|
|
|
|
|
// Test Constant cell value going from writable to read-only.
|
|
|
|
{
|
|
|
|
glo4 = 4;
|
|
|
|
|
|
|
|
function write_glo4(x) { glo4 = x }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(write_glo4);
|
|
|
|
write_glo4(4);
|
|
|
|
assertEquals(4, glo4);
|
|
|
|
|
|
|
|
// At this point, glo4 has cell type Constant.
|
|
|
|
|
|
|
|
%OptimizeFunctionOnNextCall(write_glo4);
|
|
|
|
write_glo4(4);
|
|
|
|
assertEquals(4, glo4);
|
|
|
|
assertOptimized(write_glo4);
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'glo4', {writable: false});
|
|
|
|
assertUnoptimized(write_glo4);
|
|
|
|
write_glo4(2);
|
|
|
|
assertEquals(4, glo4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test ConstantType cell value going from writable to read-only.
|
|
|
|
{
|
|
|
|
glo5 = 5;
|
|
|
|
|
|
|
|
function write_glo5(x) { glo5 = x }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(write_glo5);
|
|
|
|
write_glo5(0);
|
|
|
|
assertEquals(0, glo5);
|
|
|
|
|
|
|
|
// At this point, glo5 has cell type ConstantType.
|
|
|
|
|
|
|
|
%OptimizeFunctionOnNextCall(write_glo5);
|
|
|
|
write_glo5(5);
|
|
|
|
assertEquals(5, glo5);
|
|
|
|
assertOptimized(write_glo5);
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'glo5', {writable: false});
|
|
|
|
assertUnoptimized(write_glo5);
|
|
|
|
write_glo5(2);
|
|
|
|
assertEquals(5, glo5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test Mutable cell value going from writable to read-only.
|
|
|
|
{
|
|
|
|
glo6 = 6;
|
|
|
|
|
|
|
|
function write_glo6(x) { glo6 = x }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(write_glo6);
|
|
|
|
write_glo6({});
|
|
|
|
write_glo6(3);
|
|
|
|
assertEquals(3, glo6);
|
|
|
|
|
|
|
|
// At this point, glo6 has cell type Mutable.
|
|
|
|
|
|
|
|
%OptimizeFunctionOnNextCall(write_glo6);
|
|
|
|
write_glo6(6);
|
|
|
|
assertEquals(6, glo6);
|
|
|
|
assertOptimized(write_glo6);
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'glo6', {writable: false});
|
|
|
|
assertUnoptimized(write_glo6);
|
|
|
|
write_glo6(2);
|
|
|
|
assertEquals(6, glo6);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test Constant cell value going from read-only to writable.
|
|
|
|
{
|
|
|
|
glo7 = 7;
|
|
|
|
Object.defineProperty(this, 'glo7', {writable: false});
|
|
|
|
|
|
|
|
function read_glo7() { return glo7 }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(read_glo7);
|
|
|
|
assertEquals(7, read_glo7());
|
|
|
|
|
|
|
|
// At this point, glo7 has cell type Constant.
|
|
|
|
|
|
|
|
%OptimizeFunctionOnNextCall(read_glo7);
|
|
|
|
assertEquals(7, read_glo7());
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'glo7', {writable: true});
|
|
|
|
assertEquals(7, read_glo7());
|
|
|
|
assertOptimized(read_glo7);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test ConstantType cell value going from read-only to writable.
|
|
|
|
{
|
|
|
|
glo8 = 0;
|
|
|
|
glo8 = 8;
|
|
|
|
Object.defineProperty(this, 'glo8', {writable: false});
|
|
|
|
|
|
|
|
function read_glo8() { return glo8 }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(read_glo8);
|
|
|
|
assertEquals(8, read_glo8());
|
|
|
|
|
|
|
|
// At this point, glo8 has cell type ConstantType.
|
|
|
|
|
|
|
|
%OptimizeFunctionOnNextCall(read_glo8);
|
|
|
|
assertEquals(8, read_glo8());
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'glo8', {writable: true});
|
|
|
|
assertEquals(8, read_glo8());
|
|
|
|
assertOptimized(read_glo8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test Mutable cell value going from read-only to writable.
|
|
|
|
{
|
|
|
|
glo9 = {};
|
|
|
|
glo9 = 9;
|
|
|
|
Object.defineProperty(this, 'glo9', {writable: false});
|
|
|
|
|
|
|
|
function read_glo9() { return glo9 }
|
|
|
|
|
|
|
|
%PrepareFunctionForOptimization(read_glo9);
|
|
|
|
assertEquals(9, read_glo9());
|
|
|
|
|
|
|
|
// At this point, glo9 has cell type Mutable.
|
|
|
|
|
|
|
|
%OptimizeFunctionOnNextCall(read_glo9);
|
|
|
|
assertEquals(9, read_glo9());
|
|
|
|
|
|
|
|
Object.defineProperty(this, 'glo9', {writable: true});
|
|
|
|
assertEquals(9, read_glo9());
|
|
|
|
assertOptimized(read_glo9);
|
|
|
|
}
|