PageRenderTime 483ms CodeModel.GetById 26ms app.highlight 348ms RepoModel.GetById 1ms app.codeStats 2ms

/demos/d8-3404-d8-8424.html

http://github.com/yinwang0/ydiff
HTML | 1798 lines | 1501 code | 297 blank | 0 comment | 0 complexity | 2f99bfb94284f45dea25cb651f7a3e78 MD5 | raw file
   1<html>
   2<head>
   3<META http-equiv="Content-Type" content="text/html; charset=utf-8">
   4<LINK href="diff-s.css" rel="stylesheet" type="text/css">
   5<script type="text/javascript" src="nav-div.js"></script>
   6</head>
   7<body>
   8<div id="left" class="src">
   9<pre>
  10<a id='leftstart' tid='rightstart'></a>
  11// Copyright 2009 the V8 project authors. All rights reserved.
  12// Redistribution and use in source and binary forms, with or without
  13// modification, are permitted provided that the following conditions are
  14// met:
  15//
  16//     * Redistributions of source code must retain the above copyright
  17//       notice, this list of conditions and the following disclaimer.
  18//     * Redistributions in binary form must reproduce the above
  19//       copyright notice, this list of conditions and the following
  20//       disclaimer in the documentation and/or other materials provided
  21//       with the distribution.
  22//     * Neither the name of Google Inc. nor the names of its
  23//       contributors may be used to endorse or promote products derived
  24//       from this software without specific prior written permission.
  25//
  26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27// &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37
  38
  39#<a id='4275' tid='4276', class="m">include</a> <a id='4277' tid='4278', class="m">&lt;</a><a id='4279' tid='4280', class="m">stdlib</a><a id='4281' tid='4282', class="m">.</a><a id='4283' tid='4284', class="m">h</a><a id='4285' tid='4286', class="m">&gt;</a>
  40#<a id='4287' tid='4288', class="m">include</a> <a id='4289' tid='4290', class="m">&lt;</a><a id='4291' tid='4292', class="m">errno</a><a id='4293' tid='4294', class="m">.</a><a id='4295' tid='4296', class="m">h</a><a id='4297' tid='4298', class="m">&gt;</a>
  41
  42<span class="d">#include &quot;d8.h&quot;</span>
  43<span class="d">#include &quot;d8-debug.h&quot;</span>
  44<span class="d">#include &quot;debug.h&quot;</span>
  45<span class="d">#include &quot;api.h&quot;</span>
  46<span class="d">#include &quot;natives.h&quot;</span>
  47<span class="d">#include &quot;platform.h&quot;</span>
  48
  49
  50namespace <span class="d">v8</span> {
  51
  52
  53<a id='4261' tid='4262', class="m">const</a> <a id='4263' tid='4264', class="m">char</a><a id='4265' tid='4266', class="m">*</a> <a id='4267' tid='4268', class="m">Shell</a><a id='4269' tid='4270', class="m">::</a><a id='4271' tid='4272', class="m">kHistoryFileName</a> = <a id='4273' tid='4274', class="m">&quot;.d8_history&quot;</a>;
  54<a id='4247' tid='4248', class="m">const</a> <a id='4249' tid='4250', class="m">char</a><a id='4251' tid='4252', class="m">*</a> <a id='4253' tid='4254', class="m">Shell</a><a id='4255' tid='4256', class="m">::</a><a id='4257' tid='4258', class="m">kPrompt</a> = <a id='4259' tid='4260', class="m">&quot;d8&gt; &quot;</a>;
  55
  56
  57<a id='4205' tid='4206', class="m">LineEditor</a> <a id='4207' tid='4208', class="m">*</a><a id='4209' tid='4210', class="m">LineEditor</a><a id='4211' tid='4212', class="m">::</a><a id='4213' tid='4214', class="m">first_</a> = <a id='4215' tid='4216', class="m">NULL</a>;
  58
  59
  60<a id='4169' tid='4170', class="m">LineEditor</a><a id='4171' tid='4172', class="m">::</a><a id='4173' tid='4174', class="m">LineEditor</a>(<a id='4175' tid='4176', class="m">Type</a> <a id='4177' tid='4178', class="m">type</a>, <a id='4179' tid='4180', class="m">const</a> <a id='4181' tid='4182', class="m">char</a><a id='4183' tid='4184', class="m">*</a> <a id='4185' tid='4186', class="m">name</a>)
  61    : <a id='4187' tid='4188', class="m">type_</a>(<a id='4189' tid='4190', class="m">type</a>),
  62      <a id='4191' tid='4192', class="m">name_</a>(<a id='4193' tid='4194', class="m">name</a>),
  63      <a id='4195' tid='4196', class="m">next_</a>(<a id='4197' tid='4198', class="m">first_</a>) {
  64  <a id='4199' tid='4200', class="m">first_</a> <a id='4201' tid='4202', class="m">=</a> <a id='4203' tid='4204', class="m">this</a>;
  65}
  66
  67
  68<a id='4105' tid='4106', class="m">LineEditor</a><a id='4107' tid='4108', class="m">*</a> <a id='4109' tid='4110', class="m">LineEditor</a><a id='4111' tid='4112', class="m">::</a><a id='4113' tid='4114', class="m">Get</a>() {
  69  <a id='4115' tid='4116', class="m">LineEditor</a><a id='4117' tid='4118', class="m">*</a> <a id='4119' tid='4120', class="m">current</a> = <a id='4121' tid='4122', class="m">first_</a>;
  70  <a id='4123' tid='4124', class="m">LineEditor</a><a id='4125' tid='4126', class="m">*</a> <a id='4127' tid='4128', class="m">best</a> = <a id='4129' tid='4130', class="m">current</a>;
  71  <a id='4131' tid='4132', class="m">while</a> (<a id='4133' tid='4134', class="m">current</a> <a id='4135' tid='4136', class="m">!=</a> <a id='4137' tid='4138', class="m">NULL</a>) {
  72    <a id='4139' tid='4140', class="m">if</a> (<a id='4141' tid='4142', class="m">current</a>-&gt;<a id='4143' tid='4144', class="m">type_</a> <a id='4145' tid='4146', class="m">&gt;</a> <a id='4147' tid='4148', class="m">best</a>-&gt;<a id='4149' tid='4150', class="m">type_</a>)
  73      <a id='4151' tid='4152', class="m">best</a> <a id='4153' tid='4154', class="m">=</a> <a id='4155' tid='4156', class="m">current</a>;
  74    <a id='4157' tid='4158', class="m">current</a> <a id='4159' tid='4160', class="m">=</a> <a id='4161' tid='4162', class="m">current</a>-&gt;<a id='4163' tid='4164', class="m">next_</a>;
  75  }
  76  <a id='4165' tid='4166', class="m">return</a> <a id='4167' tid='4168', class="m">best</a>;
  77}
  78
  79
  80<a id='4063' tid='4064', class="m">class</a> <a id='4065' tid='4066', class="m">DumbLineEditor</a>: <a id='4067' tid='4068', class="m">public</a> <a id='4069' tid='4070', class="m">LineEditor</a> {
  81 <a id='4103' tid='4104', class="m">public</a>:
  82  <a id='4071' tid='4072', class="m">DumbLineEditor</a>() : <a id='4073' tid='4074', class="m">LineEditor</a>(<a id='4075' tid='4076', class="m">LineEditor</a><a id='4077' tid='4078', class="m">::</a><a id='4079' tid='4080', class="m">DUMB</a>, <a id='4081' tid='4082', class="m">&quot;dumb&quot;</a>) { }
  83  <a id='4083' tid='4084', class="m">virtual</a> <a id='4085' tid='4086', class="m">i</a><a id='4087' tid='4088', class="m">::</a><a id='4089' tid='4090', class="m">SmartPointer</a>&lt;<a id='4091' tid='4092', class="m">char</a>&gt; <a id='4093' tid='4094', class="m">Prompt</a>(<a id='4095' tid='4096', class="m">const</a> <a id='4097' tid='4098', class="m">char</a><a id='4099' tid='4100', class="m">*</a> <a id='4101' tid='4102', class="m">prompt</a>);
  84};
  85
  86
  87<span class="d">static DumbLineEditor dumb_line_editor;</span>
  88
  89
  90<a id='3983' tid='3984', class="m">i</a><a id='3985' tid='3986', class="m">::</a><a id='3987' tid='3988', class="m">SmartPointer</a>&lt;<a id='3989' tid='3990', class="m">char</a>&gt; <a id='3991' tid='3992', class="m">DumbLineEditor</a><a id='3993' tid='3994', class="m">::</a><a id='3995' tid='3996', class="m">Prompt</a>(<a id='3997' tid='3998', class="m">const</a> <a id='3999' tid='4000', class="m">char</a><a id='4001' tid='4002', class="m">*</a> <a id='4003' tid='4004', class="m">prompt</a>) {
  91  <a id='4005' tid='4006', class="m">static</a> <a id='4007' tid='4008', class="m">const</a> <a id='4009' tid='4010', class="m">int</a> <a id='4011' tid='4012', class="m">kBufferSize</a> = <a id='4013' tid='4014', class="m">256</a>;
  92  <a id='4015' tid='4016', class="m">char</a> <a id='4017' tid='4018', class="m">buffer</a>[<a id='4019' tid='4020', class="m">kBufferSize</a>];
  93  <a id='4021' tid='4022', class="m">printf</a>(<a id='4023' tid='4024', class="m">&quot;%s&quot;</a>, <a id='4025' tid='4026', class="m">prompt</a>);
  94  <a id='4027' tid='4028', class="m">char</a><a id='4029' tid='4030', class="m">*</a> <a id='4031' tid='4032', class="m">str</a> = <a id='4033' tid='4034', class="m">fgets</a>(<a id='4035' tid='4036', class="m">buffer</a>, <a id='4037' tid='4038', class="m">kBufferSize</a>, <a id='4039' tid='4040', class="m">stdin</a>);
  95  <a id='4041' tid='4042', class="m">return</a> <a id='4043' tid='4044', class="m">i</a><a id='4045' tid='4046', class="m">::</a><a id='4047' tid='4048', class="m">SmartPointer</a>&lt;<a id='4049' tid='4050', class="m">char</a>&gt;(<a id='4051' tid='4052', class="m">str</a> ? <a id='4053' tid='4054', class="m">i</a><a id='4055' tid='4056', class="m">::</a><a id='4057' tid='4058', class="m">StrDup</a>(<a id='4059' tid='4060', class="m">str</a>) : <a id='4061' tid='4062', class="m">str</a>);
  96}
  97
  98
  99<a id='3973' tid='3974', class="m">CounterMap</a><a id='3975' tid='3976', class="m">*</a> <a id='3977' tid='3978', class="m">Shell</a><a id='3979' tid='3980', class="m">::</a><a id='3981' tid='3982', class="m">counter_map_</a>;
 100<a id='3953' tid='3954', class="m">i</a><a id='3955' tid='3956', class="m">::</a><a id='3957' tid='3958', class="m">OS</a><a id='3959' tid='3960', class="m">::</a><a id='3961' tid='3962', class="m">MemoryMappedFile</a><a id='3963' tid='3964', class="m">*</a> <a id='3965' tid='3966', class="m">Shell</a><a id='3967' tid='3968', class="m">::</a><a id='3969' tid='3970', class="m">counters_file_</a> = <a id='3971' tid='3972', class="m">NULL</a>;
 101<span class="d">CounterCollection Shell::local_counters_;</span>
 102<a id='3939' tid='3940', class="m">CounterCollection</a><a id='3941' tid='3942', class="m">*</a> <a id='3943' tid='3944', class="m">Shell</a><a id='3945' tid='3946', class="m">::</a><a id='3947' tid='3948', class="m">counters_</a> = <a id='3949' tid='3950', class="m">&</a><a id='3951' tid='3952', class="m">local_counters_</a>;
 103<a id='3929' tid='3930', class="m">Persistent</a>&lt;<a id='3931' tid='3932', class="m">Context</a>&gt; <a id='3933' tid='3934', class="m">Shell</a><a id='3935' tid='3936', class="m">::</a><a id='3937' tid='3938', class="m">utility_context_</a>;
 104<a id='3919' tid='3920', class="m">Persistent</a>&lt;<a id='3921' tid='3922', class="m">Context</a>&gt; <a id='3923' tid='3924', class="m">Shell</a><a id='3925' tid='3926', class="m">::</a><a id='3927' tid='3928', class="m">evaluation_context_</a>;
 105
 106
 107<a id='3851' tid='3852', class="m">bool</a> <a id='3853' tid='3854', class="m">CounterMap</a><a id='3855' tid='3856', class="m">::</a><a id='3857' tid='3858', class="m">Match</a>(<a id='3859' tid='3860', class="m">void</a><a id='3861' tid='3862', class="m">*</a> <a id='3863' tid='3864', class="m">key1</a>, <a id='3865' tid='3866', class="m">void</a><a id='3867' tid='3868', class="m">*</a> <a id='3869' tid='3870', class="m">key2</a>) {
 108  <a id='3871' tid='3872', class="m">const</a> <a id='3873' tid='3874', class="m">char</a><a id='3875' tid='3876', class="m">*</a> <a id='3877' tid='3878', class="m">name1</a> = <a id='3879' tid='3880', class="m">reinterpret_cast</a>&lt;<a id='3881' tid='3882', class="m">const</a> <a id='3883' tid='3884', class="m">char</a><a id='3885' tid='3886', class="m">*</a>&gt;(<a id='3887' tid='3888', class="m">key1</a>);
 109  <a id='3889' tid='3890', class="m">const</a> <a id='3891' tid='3892', class="m">char</a><a id='3893' tid='3894', class="m">*</a> <a id='3895' tid='3896', class="m">name2</a> = <a id='3897' tid='3898', class="m">reinterpret_cast</a>&lt;<a id='3899' tid='3900', class="m">const</a> <a id='3901' tid='3902', class="m">char</a><a id='3903' tid='3904', class="m">*</a>&gt;(<a id='3905' tid='3906', class="m">key2</a>);
 110  <a id='3907' tid='3908', class="m">return</a> <a id='3909' tid='3910', class="m">strcmp</a>(<a id='3911' tid='3912', class="m">name1</a>, <a id='3913' tid='3914', class="m">name2</a>) <a id='3915' tid='3916', class="m">==</a> <a id='3917' tid='3918', class="m">0</a>;
 111}
 112
 113
 114// Converts a V8 value to a C string.
 115<span class="d">const</span> <span class="d">char*</span> <span class="d">ToCString</span>(<a id='3835' tid='3836', class="m">const</a> <a id='3837' tid='3838', class="m">v8</a><a id='3839' tid='3840', class="m">::</a><a id='3841' tid='3842', class="m">String</a><a id='3843' tid='3844', class="m">::</a><a id='3845' tid='3846', class="m">Utf8Value</a><a id='3847' tid='3848', class="m">&</a> <a id='3849' tid='3850', class="m">value</a>) {
 116  <a id='3643' tid='3644', class="m">return</a> <a id='3645' tid='3646', class="m">*</a><a id='3647' tid='3648', class="m">value</a> ? <a id='3649' tid='3650', class="m">*</a><a id='3651' tid='3652', class="m">value</a> : <a id='3653' tid='3654', class="m">&quot;&lt;string conversion failed&gt;&quot;</a>;
 117}
 118
 119
 120// Executes a string within the current v8 context.
 121<a id='3655' tid='3656', class="m">bool</a> <a id='3657' tid='3658', class="m">Shell</a><a id='3659' tid='3660', class="m">::</a><a id='3661' tid='3662', class="m">ExecuteString</a>(<a id='3663' tid='3664', class="m">Handle</a>&lt;<a id='3665' tid='3666', class="m">String</a>&gt; <a id='3667' tid='3668', class="m">source</a>,
 122                          <a id='3669' tid='3670', class="m">Handle</a>&lt;<a id='3671' tid='3672', class="m">Value</a>&gt; <a id='3673' tid='3674', class="m">name</a>,
 123                          <a id='3675' tid='3676', class="m">bool</a> <a id='3677' tid='3678', class="m">print_result</a>,
 124                          <a id='3679' tid='3680', class="m">bool</a> <a id='3681' tid='3682', class="m">report_exceptions</a>) {
 125  <a id='3683' tid='3684', class="m">HandleScope</a> <a id='3685' tid='3686', class="m">handle_scope</a>;
 126  <a id='3687' tid='3688', class="m">TryCatch</a> <a id='3689' tid='3690', class="m">try_catch</a>;
 127  <a id='3691' tid='3692', class="m">if</a> (<a id='3693' tid='3694', class="m">i</a><a id='3695' tid='3696', class="m">::</a><a id='3697' tid='3698', class="m">FLAG_debugger</a>) {
 128    // When debugging make exceptions appear to be uncaught.
 129    <a id='3699' tid='3700', class="m">try_catch</a>.<a id='3701' tid='3702', class="m">SetVerbose</a>(<a id='3703' tid='3704', class="m">true</a>);
 130  }
 131  <a id='3705' tid='3706', class="m">Handle</a>&lt;<a id='3707' tid='3708', class="m">Script</a>&gt; <a id='3709' tid='3710', class="m">script</a> = <a id='3711' tid='3712', class="m">Script</a><a id='3713' tid='3714', class="m">::</a><a id='3715' tid='3716', class="m">Compile</a>(<a id='3717' tid='3718', class="m">source</a>, <a id='3719' tid='3720', class="m">name</a>);
 132  <a id='3721' tid='3722', class="m">if</a> (<a id='3723' tid='3724', class="m">script</a>.<a id='3725' tid='3726', class="m">IsEmpty</a>()) {
 133    // Print errors that happened during compilation.
 134    <a id='3727' tid='3728', class="m">if</a> (<a id='3729' tid='3730', class="m">report_exceptions</a> <a id='3731' tid='3732', class="m">&&</a> <a id='3733' tid='3734', class="m">!</a><a id='3735' tid='3736', class="m">i</a><a id='3737' tid='3738', class="m">::</a><a id='3739' tid='3740', class="m">FLAG_debugger</a>)
 135      <a id='3741' tid='3742', class="m">ReportException</a>(<a id='3743' tid='3744', class="m">&</a><a id='3745' tid='3746', class="m">try_catch</a>);
 136    <a id='3747' tid='3748', class="m">return</a> <a id='3749' tid='3750', class="m">false</a>;
 137  } <a id='3751' tid='3752', class="m">else</a> {
 138    <a id='3753' tid='3754', class="m">Handle</a>&lt;<a id='3755' tid='3756', class="m">Value</a>&gt; <a id='3757' tid='3758', class="m">result</a> = <a id='3759' tid='3760', class="m">script</a>-&gt;<a id='3761' tid='3762', class="m">Run</a>();
 139    <a id='3763' tid='3764', class="m">if</a> (<a id='3765' tid='3766', class="m">result</a>.<a id='3767' tid='3768', class="m">IsEmpty</a>()) {
 140      // Print errors that happened during execution.
 141      <a id='3769' tid='3770', class="m">if</a> (<a id='3771' tid='3772', class="m">report_exceptions</a> <a id='3773' tid='3774', class="m">&&</a> <a id='3775' tid='3776', class="m">!</a><a id='3777' tid='3778', class="m">i</a><a id='3779' tid='3780', class="m">::</a><a id='3781' tid='3782', class="m">FLAG_debugger</a>)
 142        <a id='3783' tid='3784', class="m">ReportException</a>(<a id='3785' tid='3786', class="m">&</a><a id='3787' tid='3788', class="m">try_catch</a>);
 143      <span class="d">return false;</span>
 144    } <a id='3789' tid='3790', class="m">else</a> {
 145      <a id='3791' tid='3792', class="m">if</a> (<a id='3793' tid='3794', class="m">print_result</a> <a id='3795' tid='3796', class="m">&&</a> <a id='3797' tid='3798', class="m">!</a><a id='3799' tid='3800', class="m">result</a>-&gt;<a id='3801' tid='3802', class="m">IsUndefined</a>()) {
 146        // If all went well and the result wasn&#39;t undefined then print
 147        // the returned value.
 148        <a id='3803' tid='3804', class="m">v8</a><a id='3805' tid='3806', class="m">::</a><a id='3807' tid='3808', class="m">String</a><a id='3809' tid='3810', class="m">::</a><a id='3811' tid='3812', class="m">Utf8Value</a> <a id='3813' tid='3814', class="m">str</a>(<a id='3815' tid='3816', class="m">result</a>);
 149        <a id='3817' tid='3818', class="m">const</a> <a id='3819' tid='3820', class="m">char</a><a id='3821' tid='3822', class="m">*</a> <a id='3823' tid='3824', class="m">cstr</a> = <a id='3825' tid='3826', class="m">ToCString</a>(<a id='3827' tid='3828', class="m">str</a>);
 150        <a id='3829' tid='3830', class="m">printf</a>(<a id='3831' tid='3832', class="m">&quot;%s\n&quot;</a>, <a id='3833' tid='3834', class="m">cstr</a>);
 151      }
 152      <span class="d">return true;</span>
 153    }
 154  }
 155}
 156
 157
 158<a id='3607' tid='3608', class="m">Handle</a>&lt;<a id='3609' tid='3610', class="m">Value</a>&gt; <a id='3611' tid='3612', class="m">Shell</a><a id='3613' tid='3614', class="m">::</a><a id='3615' tid='3616', class="m">Print</a>(<a id='3617' tid='3618', class="m">const</a> <a id='3619' tid='3620', class="m">Arguments</a><a id='3621' tid='3622', class="m">&</a> <a id='3623' tid='3624', class="m">args</a>) {
 159  <a id='3625' tid='3626', class="m">Handle</a>&lt;<a id='3627' tid='3628', class="m">Value</a>&gt; <a id='3629' tid='3630', class="m">val</a> = <a id='3631' tid='3632', class="m">Write</a>(<a id='3633' tid='3634', class="m">args</a>);
 160  <a id='3635' tid='3636', class="m">printf</a>(<a id='3637' tid='3638', class="m">&quot;\n&quot;</a>);
 161  <a id='3639' tid='3640', class="m">return</a> <a id='3641' tid='3642', class="m">val</a>;
 162}
 163
 164
 165<a id='3491' tid='3492', class="m">Handle</a>&lt;<a id='3493' tid='3494', class="m">Value</a>&gt; <a id='3495' tid='3496', class="m">Shell</a><a id='3497' tid='3498', class="m">::</a><a id='3499' tid='3500', class="m">Write</a>(<a id='3501' tid='3502', class="m">const</a> <a id='3503' tid='3504', class="m">Arguments</a><a id='3505' tid='3506', class="m">&</a> <a id='3507' tid='3508', class="m">args</a>) {
 166  <a id='3509' tid='3510', class="m">for</a> (<a id='3511' tid='3512', class="m">int</a> <a id='3513' tid='3514', class="m">i</a> = <a id='3515' tid='3516', class="m">0</a>; <a id='3517' tid='3518', class="m">i</a> <a id='3519' tid='3520', class="m">&lt;</a> <a id='3521' tid='3522', class="m">args</a>.<a id='3523' tid='3524', class="m">Length</a>(); <a id='3525' tid='3526', class="m">i</a><a id='3527' tid='3528', class="m">++</a>) {
 167    <a id='3529' tid='3530', class="m">HandleScope</a> <a id='3531' tid='3532', class="m">handle_scope</a>;
 168    <a id='3533' tid='3534', class="m">if</a> (<a id='3535' tid='3536', class="m">i</a> <a id='3537' tid='3538', class="m">!=</a> <a id='3539' tid='3540', class="m">0</a>) {
 169      <a id='3541' tid='3542', class="m">printf</a>(<a id='3543' tid='3544', class="m">&quot; &quot;</a>);
 170    }
 171    <a id='3545' tid='3546', class="m">v8</a><a id='3547' tid='3548', class="m">::</a><a id='3549' tid='3550', class="m">String</a><a id='3551' tid='3552', class="m">::</a><a id='3553' tid='3554', class="m">Utf8Value</a> <a id='3555' tid='3556', class="m">str</a>(<a id='3557' tid='3558', class="m">args</a>[<a id='3559' tid='3560', class="m">i</a>]);
 172    <a id='3561' tid='3562', class="m">int</a> <a id='3563' tid='3564', class="m">n</a> = <a id='3565' tid='3566', class="m">fwrite</a>(<a id='3567' tid='3568', class="m">*</a><a id='3569' tid='3570', class="m">str</a>, <a id='3571' tid='3572', class="m">sizeof</a>(<a id='3573' tid='3574', class="m">*</a><a id='3575' tid='3576', class="m">*</a><a id='3577' tid='3578', class="m">str</a>), <a id='3579' tid='3580', class="m">str</a>.<a id='3581' tid='3582', class="m">length</a>(), <a id='3583' tid='3584', class="m">stdout</a>);
 173    <a id='3585' tid='3586', class="m">if</a> (<a id='3587' tid='3588', class="m">n</a> <a id='3589' tid='3590', class="m">!=</a> <a id='3591' tid='3592', class="m">str</a>.<a id='3593' tid='3594', class="m">length</a>()) {
 174      <a id='3595' tid='3596', class="m">printf</a>(<a id='3597' tid='3598', class="m">&quot;Error in fwrite\n&quot;</a>);
 175      <a id='3599' tid='3600', class="m">exit</a>(<a id='3601' tid='3602', class="m">1</a>);
 176    }
 177  }
 178  <a id='3603' tid='3604', class="m">return</a> <a id='3605' tid='3606', class="m">Undefined</a>();
 179}
 180
 181
 182<a id='3405' tid='3406', class="m">Handle</a>&lt;<a id='3407' tid='3408', class="m">Value</a>&gt; <a id='3409' tid='3410', class="m">Shell</a><a id='3411' tid='3412', class="m">::</a><a id='3413' tid='3414', class="m">Read</a>(<a id='3415' tid='3416', class="m">const</a> <a id='3417' tid='3418', class="m">Arguments</a><a id='3419' tid='3420', class="m">&</a> <a id='3421' tid='3422', class="m">args</a>) {
 183  <a id='3423' tid='3424', class="m">String</a><a id='3425' tid='3426', class="m">::</a><a id='3427' tid='3428', class="m">Utf8Value</a> <a id='3429' tid='3430', class="m">file</a>(<a id='3431' tid='3432', class="m">args</a>[<a id='3433' tid='3434', class="m">0</a>]);
 184  <a id='3435' tid='3436', class="m">if</a> (<a id='3437' tid='3438', class="m">*</a><a id='3439' tid='3440', class="m">file</a> <a id='3441' tid='3442', class="m">==</a> <a id='3443' tid='3444', class="m">NULL</a>) {
 185    <a id='3445' tid='3446', class="m">return</a> <a id='3447' tid='3448', class="m">ThrowException</a>(<a id='3449' tid='3450', class="m">String</a><a id='3451' tid='3452', class="m">::</a><a id='3453' tid='3454', class="m">New</a>(<a id='3455' tid='3456', class="m">&quot;Error loading file&quot;</a>));
 186  }
 187  <a id='3457' tid='3458', class="m">Handle</a>&lt;<a id='3459' tid='3460', class="m">String</a>&gt; <a id='3461' tid='3462', class="m">source</a> = <a id='3463' tid='3464', class="m">ReadFile</a>(<a id='3465' tid='3466', class="m">*</a><a id='3467' tid='3468', class="m">file</a>);
 188  <a id='3469' tid='3470', class="m">if</a> (<a id='3471' tid='3472', class="m">source</a>.<a id='3473' tid='3474', class="m">IsEmpty</a>()) {
 189    <a id='3475' tid='3476', class="m">return</a> <a id='3477' tid='3478', class="m">ThrowException</a>(<a id='3479' tid='3480', class="m">String</a><a id='3481' tid='3482', class="m">::</a><a id='3483' tid='3484', class="m">New</a>(<a id='3485' tid='3486', class="m">&quot;Error loading file&quot;</a>));
 190  }
 191  <a id='3487' tid='3488', class="m">return</a> <a id='3489' tid='3490', class="m">source</a>;
 192}
 193
 194
 195<a id='3305' tid='3306', class="m">Handle</a>&lt;<a id='3307' tid='3308', class="m">Value</a>&gt; <a id='3309' tid='3310', class="m">Shell</a><a id='3311' tid='3312', class="m">::</a><a id='3313' tid='3314', class="m">ReadLine</a>(<a id='3315' tid='3316', class="m">const</a> <a id='3317' tid='3318', class="m">Arguments</a><a id='3319' tid='3320', class="m">&</a> <a id='3321' tid='3322', class="m">args</a>) {
 196  <a id='3323' tid='3324', class="m">i</a><a id='3325' tid='3326', class="m">::</a><a id='3327' tid='3328', class="m">SmartPointer</a>&lt;<a id='3329' tid='3330', class="m">char</a>&gt; <a id='3331' tid='3332', class="m">line</a>(<a id='3333' tid='3334', class="m">i</a><a id='3335' tid='3336', class="m">::</a><a id='3337' tid='3338', class="m">ReadLine</a>(<a id='3339' tid='3340', class="m">&quot;&quot;</a>));
 197  <a id='3341' tid='3342', class="m">if</a> (<a id='3343' tid='3344', class="m">*</a><a id='3345' tid='3346', class="m">line</a> <a id='3347' tid='3348', class="m">==</a> <a id='3349' tid='3350', class="m">NULL</a>) {
 198    <a id='3351' tid='3352', class="m">return</a> <a id='3353' tid='3354', class="m">Null</a>();
 199  }
 200  <a id='3355' tid='3356', class="m">size_t</a> <a id='3357' tid='3358', class="m">len</a> = <a id='3359' tid='3360', class="m">strlen</a>(<a id='3361' tid='3362', class="m">*</a><a id='3363' tid='3364', class="m">line</a>);
 201  <a id='3365' tid='3366', class="m">if</a> (<a id='3367' tid='3368', class="m">len</a> <a id='3369' tid='3370', class="m">&gt;</a> <a id='3371' tid='3372', class="m">0</a> <a id='3373' tid='3374', class="m">&&</a> <a id='3375' tid='3376', class="m">line</a>[<a id='3377' tid='3378', class="m">len</a> <a id='3379' tid='3380', class="m">-</a> <a id='3381' tid='3382', class="m">1</a>] <a id='3383' tid='3384', class="m">==</a> <a id='3385' tid='3386', class="m">&#39;\n&#39;</a>) {
 202    <a id='3387' tid='3388', class="m">--</a><a id='3389' tid='3390', class="m">len</a>;
 203  }
 204  <a id='3391' tid='3392', class="m">return</a> <a id='3393' tid='3394', class="m">String</a><a id='3395' tid='3396', class="m">::</a><a id='3397' tid='3398', class="m">New</a>(<a id='3399' tid='3400', class="m">*</a><a id='3401' tid='3402', class="m">line</a>, <a id='3403' tid='3404', class="m">len</a>);
 205}
 206
 207
 208<a id='3161' tid='3162', class="m">Handle</a>&lt;<a id='3163' tid='3164', class="m">Value</a>&gt; <a id='3165' tid='3166', class="m">Shell</a><a id='3167' tid='3168', class="m">::</a><a id='3169' tid='3170', class="m">Load</a>(<a id='3171' tid='3172', class="m">const</a> <a id='3173' tid='3174', class="m">Arguments</a><a id='3175' tid='3176', class="m">&</a> <a id='3177' tid='3178', class="m">args</a>) {
 209  <a id='3179' tid='3180', class="m">for</a> (<a id='3181' tid='3182', class="m">int</a> <a id='3183' tid='3184', class="m">i</a> = <a id='3185' tid='3186', class="m">0</a>; <a id='3187' tid='3188', class="m">i</a> <a id='3189' tid='3190', class="m">&lt;</a> <a id='3191' tid='3192', class="m">args</a>.<a id='3193' tid='3194', class="m">Length</a>(); <a id='3195' tid='3196', class="m">i</a><a id='3197' tid='3198', class="m">++</a>) {
 210    <a id='3199' tid='3200', class="m">HandleScope</a> <a id='3201' tid='3202', class="m">handle_scope</a>;
 211    <a id='3203' tid='3204', class="m">String</a><a id='3205' tid='3206', class="m">::</a><a id='3207' tid='3208', class="m">Utf8Value</a> <a id='3209' tid='3210', class="m">file</a>(<a id='3211' tid='3212', class="m">args</a>[<a id='3213' tid='3214', class="m">i</a>]);
 212    <a id='3215' tid='3216', class="m">if</a> (<a id='3217' tid='3218', class="m">*</a><a id='3219' tid='3220', class="m">file</a> <a id='3221' tid='3222', class="m">==</a> <a id='3223' tid='3224', class="m">NULL</a>) {
 213      <a id='3225' tid='3226', class="m">return</a> <a id='3227' tid='3228', class="m">ThrowException</a>(<a id='3229' tid='3230', class="m">String</a><a id='3231' tid='3232', class="m">::</a><a id='3233' tid='3234', class="m">New</a>(<a id='3235' tid='3236', class="m">&quot;Error loading file&quot;</a>));
 214    }
 215    <a id='3237' tid='3238', class="m">Handle</a>&lt;<a id='3239' tid='3240', class="m">String</a>&gt; <a id='3241' tid='3242', class="m">source</a> = <a id='3243' tid='3244', class="m">ReadFile</a>(<a id='3245' tid='3246', class="m">*</a><a id='3247' tid='3248', class="m">file</a>);
 216    <a id='3249' tid='3250', class="m">if</a> (<a id='3251' tid='3252', class="m">source</a>.<a id='3253' tid='3254', class="m">IsEmpty</a>()) {
 217      <a id='3255' tid='3256', class="m">return</a> <a id='3257' tid='3258', class="m">ThrowException</a>(<a id='3259' tid='3260', class="m">String</a><a id='3261' tid='3262', class="m">::</a><a id='3263' tid='3264', class="m">New</a>(<a id='3265' tid='3266', class="m">&quot;Error loading file&quot;</a>));
 218    }
 219    <a id='3267' tid='3268', class="m">if</a> (<a id='3269' tid='3270', class="m">!</a><a id='3271' tid='3272', class="m">ExecuteString</a>(<a id='3273' tid='3274', class="m">source</a>, <a id='3275' tid='3276', class="m">String</a><a id='3277' tid='3278', class="m">::</a><a id='3279' tid='3280', class="m">New</a>(<a id='3281' tid='3282', class="m">*</a><a id='3283' tid='3284', class="m">file</a>), <a id='3285' tid='3286', class="m">false</a>, <a id='3287' tid='3288', class="m">false</a>)) {
 220      <a id='3289' tid='3290', class="m">return</a> <a id='3291' tid='3292', class="m">ThrowException</a>(<a id='3293' tid='3294', class="m">String</a><a id='3295' tid='3296', class="m">::</a><a id='3297' tid='3298', class="m">New</a>(<a id='3299' tid='3300', class="m">&quot;Error executing file&quot;</a>));
 221    }
 222  }
 223  <a id='3301' tid='3302', class="m">return</a> <a id='3303' tid='3304', class="m">Undefined</a>();
 224}
 225
 226
 227<a id='3131' tid='3132', class="m">Handle</a>&lt;<a id='3133' tid='3134', class="m">Value</a>&gt; <a id='3135' tid='3136', class="m">Shell</a><a id='3137' tid='3138', class="m">::</a><a id='3139' tid='3140', class="m">Yield</a>(<a id='3141' tid='3142', class="m">const</a> <a id='3143' tid='3144', class="m">Arguments</a><a id='3145' tid='3146', class="m">&</a> <a id='3147' tid='3148', class="m">args</a>) {
 228  <a id='3149' tid='3150', class="m">v8</a><a id='3151' tid='3152', class="m">::</a><a id='3153' tid='3154', class="m">Unlocker</a> <a id='3155' tid='3156', class="m">unlocker</a>;
 229  <a id='3157' tid='3158', class="m">return</a> <a id='3159' tid='3160', class="m">Undefined</a>();
 230}
 231
 232
 233<a id='3093' tid='3094', class="m">Handle</a>&lt;<a id='3095' tid='3096', class="m">Value</a>&gt; <a id='3097' tid='3098', class="m">Shell</a><a id='3099' tid='3100', class="m">::</a><a id='3101' tid='3102', class="m">Quit</a>(<a id='3103' tid='3104', class="m">const</a> <a id='3105' tid='3106', class="m">Arguments</a><a id='3107' tid='3108', class="m">&</a> <a id='3109' tid='3110', class="m">args</a>) {
 234  <a id='3111' tid='3112', class="m">int</a> <a id='3113' tid='3114', class="m">exit_code</a> = <a id='3115' tid='3116', class="m">args</a>[<a id='3117' tid='3118', class="m">0</a>]-&gt;<a id='3119' tid='3120', class="m">Int32Value</a>();
 235  <a id='3121' tid='3122', class="m">OnExit</a>();
 236  <a id='3123' tid='3124', class="m">exit</a>(<a id='3125' tid='3126', class="m">exit_code</a>);
 237  <a id='3127' tid='3128', class="m">return</a> <a id='3129' tid='3130', class="m">Undefined</a>();
 238}
 239
 240
 241<a id='3061' tid='3062', class="m">Handle</a>&lt;<a id='3063' tid='3064', class="m">Value</a>&gt; <a id='3065' tid='3066', class="m">Shell</a><a id='3067' tid='3068', class="m">::</a><a id='3069' tid='3070', class="m">Version</a>(<a id='3071' tid='3072', class="m">const</a> <a id='3073' tid='3074', class="m">Arguments</a><a id='3075' tid='3076', class="m">&</a> <a id='3077' tid='3078', class="m">args</a>) {
 242  <a id='3079' tid='3080', class="m">return</a> <a id='3081' tid='3082', class="m">String</a><a id='3083' tid='3084', class="m">::</a><a id='3085' tid='3086', class="m">New</a>(<a id='3087' tid='3088', class="m">V8</a><a id='3089' tid='3090', class="m">::</a><a id='3091' tid='3092', class="m">GetVersion</a>());
 243}
 244
 245
 246<a id='2971' tid='2972', class="m">void</a> <a id='2973' tid='2974', class="m">Shell</a><a id='2975' tid='2976', class="m">::</a><a id='2977' tid='2978', class="m">ReportException</a>(<a id='2979' tid='2980', class="m">v8</a><a id='2981' tid='2982', class="m">::</a><a id='2983' tid='2984', class="m">TryCatch</a><a id='2985' tid='2986', class="m">*</a> <a id='2987' tid='2988', class="m">try_catch</a>) {
 247  <a id='2989' tid='2990', class="m">HandleScope</a> <a id='2991' tid='2992', class="m">handle_scope</a>;
 248  <a id='2993' tid='2994', class="m">v8</a><a id='2995' tid='2996', class="m">::</a><a id='2997' tid='2998', class="m">String</a><a id='2999' tid='3000', class="m">::</a><a id='3001' tid='3002', class="m">Utf8Value</a> <a id='3003' tid='3004', class="m">exception</a>(<a id='3005' tid='3006', class="m">try_catch</a>-&gt;<a id='3007' tid='3008', class="m">Exception</a>());
 249  <a id='3009' tid='3010', class="m">const</a> <a id='3011' tid='3012', class="m">char</a><a id='3013' tid='3014', class="m">*</a> <a id='3015' tid='3016', class="m">exception_string</a> = <a id='3017' tid='3018', class="m">ToCString</a>(<a id='3019' tid='3020', class="m">exception</a>);
 250  <a id='3021' tid='3022', class="m">Handle</a>&lt;<a id='3023' tid='3024', class="m">Message</a>&gt; <a id='3025' tid='3026', class="m">message</a> = <a id='3027' tid='3028', class="m">try_catch</a>-&gt;<a id='3029' tid='3030', class="m">Message</a>();
 251  <a id='3031' tid='3032', class="m">if</a> (<a id='3033' tid='3034', class="m">message</a>.<a id='3035' tid='3036', class="m">IsEmpty</a>()) {
 252    // V8 didn&#39;t provide any extra information about this error; just
 253    // print the exception.
 254    <a id='3037' tid='3038', class="m">printf</a>(<a id='3039' tid='3040', class="m">&quot;%s\n&quot;</a>, <a id='3041' tid='3042', class="m">exception_string</a>);
 255  } <a id='3043' tid='3044', class="m">else</a> {
 256    // Print (filename):(line number): (message).
 257    <a id='3045' tid='3046', class="m">v8</a><a id='3047' tid='3048', class="m">::</a><a id='3049' tid='3050', class="m">String</a><a id='3051' tid='3052', class="m">::</a><a id='3053' tid='3054', class="m">Utf8Value</a> <a id='3055' tid='3056', class="m">filename</a>(<a id='3057' tid='3058', class="m">message</a>-&gt;<a id='3059' tid='3060', class="m">GetScriptResourceName</a>());
 258    <a id='2959' tid='2960', class="m">const</a> <a id='2961' tid='2962', class="m">char</a><a id='2963' tid='2964', class="m">*</a> <a id='2965' tid='2966', class="m">filename_string</a> = <a id='2967' tid='2968', class="m">ToCString</a>(<a id='2969' tid='2970', class="m">filename</a>);
 259    <span class="d">int linenum = message-&gt;GetLineNumber();</span>
 260    <a id='2819' tid='2820', class="m">printf</a>(<a id='2821' tid='2822', class="m">&quot;%s:%i: %s\n&quot;</a>, <a id='2823' tid='2824', class="m">filename_string</a>, <a id='2825' tid='2826', class="m">linenum</a>, <a id='2827' tid='2828', class="m">exception_string</a>);
 261    // Print line of source code.
 262    <a id='2693' tid='2694', class="m">v8</a><a id='2695' tid='2696', class="m">::</a><a id='2697' tid='2698', class="m">String</a><a id='2699' tid='2700', class="m">::</a><a id='2701' tid='2702', class="m">Utf8Value</a> <a id='2703' tid='2704', class="m">sourceline</a>(<a id='2705' tid='2706', class="m">message</a>-&gt;<a id='2707' tid='2708', class="m">GetSourceLine</a>());
 263    <a id='2579' tid='2580', class="m">const</a> <a id='2581' tid='2582', class="m">char</a><a id='2583' tid='2584', class="m">*</a> <a id='2585' tid='2586', class="m">sourceline_string</a> = <a id='2587' tid='2588', class="m">ToCString</a>(<a id='2589' tid='2590', class="m">sourceline</a>);
 264    <span class="d">printf(&quot;%s\n&quot;, sourceline_string);</span>
 265    // Print wavy underline (GetUnderline is deprecated).
 266    <span class="d">int start = message-&gt;GetStartColumn();</span>
 267    <a id='2471' tid='2472', class="m">for</a> (<a id='2473' tid='2474', class="m">int</a> <a id='2475' tid='2476', class="m">i</a> = <a id='2477' tid='2478', class="m">0</a>; <a id='2479' tid='2480', class="m">i</a> <a id='2481' tid='2482', class="m">&lt;</a> <a id='2483' tid='2484', class="m">start</a>; <a id='2485' tid='2486', class="m">i</a><a id='2487' tid='2488', class="m">++</a>) {
 268      <a id='2489' tid='2490', class="m">printf</a>(<a id='2491' tid='2492', class="m">&quot; &quot;</a>);
 269    }
 270    <span class="d">int end = message-&gt;GetEndColumn();</span>
 271    <a id='2427' tid='2428', class="m">for</a> (<a id='2429' tid='2430', class="m">int</a> <a id='2431' tid='2432', class="m">i</a> = <a id='2433' tid='2434', class="m">start</a>; <a id='2435' tid='2436', class="m">i</a> <a id='2437' tid='2438', class="m">&lt;</a> <a id='2439' tid='2440', class="m">end</a>; <a id='2441' tid='2442', class="m">i</a><a id='2443' tid='2444', class="m">++</a>) {
 272      <a id='2445' tid='2446', class="m">printf</a>(<a id='2447' tid='2448', class="m">&quot;^&quot;</a>);
 273    }
 274    <span class="d">printf(&quot;\n&quot;);</span>
 275  }
 276}
 277
 278
 279<a id='2829' tid='2830', class="m">Handle</a>&lt;<a id='2831' tid='2832', class="m">Array</a>&gt; <a id='2833' tid='2834', class="m">Shell</a><a id='2835' tid='2836', class="m">::</a><a id='2837' tid='2838', class="m">GetCompletions</a>(<a id='2839' tid='2840', class="m">Handle</a>&lt;<a id='2841' tid='2842', class="m">String</a>&gt; <a id='2843' tid='2844', class="m">text</a>, <a id='2845' tid='2846', class="m">Handle</a>&lt;<a id='2847' tid='2848', class="m">String</a>&gt; <a id='2849' tid='2850', class="m">full</a>) {
 280  <a id='2861' tid='2862', class="m">HandleScope</a> <a id='2863' tid='2864', class="m">handle_scope</a>;
 281  <a id='2851' tid='2852', class="m">Context</a><a id='2853' tid='2854', class="m">::</a><a id='2855' tid='2856', class="m">Scope</a> <a id='2857' tid='2858', class="m">context_scope</a>(<a id='2859' tid='2860', class="m">utility_context_</a>);
 282  <a id='2865' tid='2866', class="m">Handle</a>&lt;<a id='2867' tid='2868', class="m">Object</a>&gt; <a id='2869' tid='2870', class="m">global</a> = <a id='2871' tid='2872', class="m">utility_context_</a>-&gt;<a id='2873' tid='2874', class="m">Global</a>();
 283  <a id='2875' tid='2876', class="m">Handle</a>&lt;<a id='2877' tid='2878', class="m">Value</a>&gt; <a id='2879' tid='2880', class="m">fun</a> = <a id='2881' tid='2882', class="m">global</a>-&gt;<a id='2883' tid='2884', class="m">Get</a>(<a id='2885' tid='2886', class="m">String</a><a id='2887' tid='2888', class="m">::</a><a id='2889' tid='2890', class="m">New</a>(<a id='2891' tid='2892', class="m">&quot;GetCompletions&quot;</a>));
 284  <a id='2893' tid='2894', class="m">static</a> <a id='2895' tid='2896', class="m">const</a> <a id='2897' tid='2898', class="m">int</a> <a id='2899' tid='2900', class="m">kArgc</a> = <a id='2901' tid='2902', class="m">3</a>;
 285  <a id='2903' tid='2904', class="m">Handle</a>&lt;<a id='2905' tid='2906', class="m">Value</a>&gt; <a id='2907' tid='2908', class="m">argv</a>[<a id='2909' tid='2910', class="m">kArgc</a>] = { <a id='2911' tid='2912', class="m">evaluation_context_</a>-&gt;<a id='2913' tid='2914', class="m">Global</a>(), <a id='2915' tid='2916', class="m">text</a>, <a id='2917' tid='2918', class="m">full</a> };
 286  <a id='2919' tid='2920', class="m">Handle</a>&lt;<a id='2921' tid='2922', class="m">Value</a>&gt; <a id='2923' tid='2924', class="m">val</a> = <a id='2925' tid='2926', class="m">Handle</a>&lt;<a id='2927' tid='2928', class="m">Function</a>&gt;<a id='2929' tid='2930', class="m">::</a><a id='2931' tid='2932', class="m">Cast</a>(<a id='2933' tid='2934', class="m">fun</a>)-&gt;<a id='2935' tid='2936', class="m">Call</a>(<a id='2937' tid='2938', class="m">global</a>, <a id='2939' tid='2940', class="m">kArgc</a>, <a id='2941' tid='2942', class="m">argv</a>);
 287  <a id='2943' tid='2944', class="m">return</a> <a id='2945' tid='2946', class="m">handle_scope</a>.<a id='2947' tid='2948', class="m">Close</a>(<a id='2949' tid='2950', class="m">Handle</a>&lt;<a id='2951' tid='2952', class="m">Array</a>&gt;<a id='2953' tid='2954', class="m">::</a><a id='2955' tid='2956', class="m">Cast</a>(<a id='2957' tid='2958', class="m">val</a>));
 288}
 289
 290
 291<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
 292<a id='2709' tid='2710', class="m">Handle</a>&lt;<a id='2711' tid='2712', class="m">Object</a>&gt; <a id='2713' tid='2714', class="m">Shell</a><a id='2715' tid='2716', class="m">::</a><a id='2717' tid='2718', class="m">DebugMessageDetails</a>(<a id='2719' tid='2720', class="m">Handle</a>&lt;<a id='2721' tid='2722', class="m">String</a>&gt; <a id='2723' tid='2724', class="m">message</a>) {
 293  <a id='2725' tid='2726', class="m">Context</a><a id='2727' tid='2728', class="m">::</a><a id='2729' tid='2730', class="m">Scope</a> <a id='2731' tid='2732', class="m">context_scope</a>(<a id='2733' tid='2734', class="m">utility_context_</a>);
 294  <a id='2735' tid='2736', class="m">Handle</a>&lt;<a id='2737' tid='2738', class="m">Object</a>&gt; <a id='2739' tid='2740', class="m">global</a> = <a id='2741' tid='2742', class="m">utility_context_</a>-&gt;<a id='2743' tid='2744', class="m">Global</a>();
 295  <a id='2745' tid='2746', class="m">Handle</a>&lt;<a id='2747' tid='2748', class="m">Value</a>&gt; <a id='2749' tid='2750', class="m">fun</a> = <a id='2751' tid='2752', class="m">global</a>-&gt;<a id='2753' tid='2754', class="m">Get</a>(<a id='2755' tid='2756', class="m">String</a><a id='2757' tid='2758', class="m">::</a><a id='2759' tid='2760', class="m">New</a>(<a id='2761' tid='2762', class="m">&quot;DebugMessageDetails&quot;</a>));
 296  <a id='2763' tid='2764', class="m">static</a> <a id='2765' tid='2766', class="m">const</a> <a id='2767' tid='2768', class="m">int</a> <a id='2769' tid='2770', class="m">kArgc</a> = <a id='2771' tid='2772', class="m">1</a>;
 297  <a id='2773' tid='2774', class="m">Handle</a>&lt;<a id='2775' tid='2776', class="m">Value</a>&gt; <a id='2777' tid='2778', class="m">argv</a>[<a id='2779' tid='2780', class="m">kArgc</a>] = { <a id='2781' tid='2782', class="m">message</a> };
 298  <a id='2783' tid='2784', class="m">Handle</a>&lt;<a id='2785' tid='2786', class="m">Value</a>&gt; <a id='2787' tid='2788', class="m">val</a> = <a id='2789' tid='2790', class="m">Handle</a>&lt;<a id='2791' tid='2792', class="m">Function</a>&gt;<a id='2793' tid='2794', class="m">::</a><a id='2795' tid='2796', class="m">Cast</a>(<a id='2797' tid='2798', class="m">fun</a>)-&gt;<a id='2799' tid='2800', class="m">Call</a>(<a id='2801' tid='2802', class="m">global</a>, <a id='2803' tid='2804', class="m">kArgc</a>, <a id='2805' tid='2806', class="m">argv</a>);
 299  <a id='2807' tid='2808', class="m">return</a> <a id='2809' tid='2810', class="m">Handle</a>&lt;<a id='2811' tid='2812', class="m">Object</a>&gt;<a id='2813' tid='2814', class="m">::</a><a id='2815' tid='2816', class="m">Cast</a>(<a id='2817' tid='2818', class="m">val</a>);
 300}
 301
 302
 303<a id='2591' tid='2592', class="m">Handle</a>&lt;<a id='2593' tid='2594', class="m">Value</a>&gt; <a id='2595' tid='2596', class="m">Shell</a><a id='2597' tid='2598', class="m">::</a><a id='2599' tid='2600', class="m">DebugCommandToJSONRequest</a>(<a id='2601' tid='2602', class="m">Handle</a>&lt;<a id='2603' tid='2604', class="m">String</a>&gt; <a id='2605' tid='2606', class="m">command</a>) {
 304  <a id='2607' tid='2608', class="m">Context</a><a id='2609' tid='2610', class="m">::</a><a id='2611' tid='2612', class="m">Scope</a> <a id='2613' tid='2614', class="m">context_scope</a>(<a id='2615' tid='2616', class="m">utility_context_</a>);
 305  <a id='2617' tid='2618', class="m">Handle</a>&lt;<a id='2619' tid='2620', class="m">Object</a>&gt; <a id='2621' tid='2622', class="m">global</a> = <a id='2623' tid='2624', class="m">utility_context_</a>-&gt;<a id='2625' tid='2626', class="m">Global</a>();
 306  <a id='2627' tid='2628', class="m">Handle</a>&lt;<a id='2629' tid='2630', class="m">Value</a>&gt; <a id='2631' tid='2632', class="m">fun</a> = <a id='2633' tid='2634', class="m">global</a>-&gt;<a id='2635' tid='2636', class="m">Get</a>(<a id='2637' tid='2638', class="m">String</a><a id='2639' tid='2640', class="m">::</a><a id='2641' tid='2642', class="m">New</a>(<a id='2643' tid='2644', class="m">&quot;DebugCommandToJSONRequest&quot;</a>));
 307  <a id='2645' tid='2646', class="m">static</a> <a id='2647' tid='2648', class="m">const</a> <a id='2649' tid='2650', class="m">int</a> <a id='2651' tid='2652', class="m">kArgc</a> = <a id='2653' tid='2654', class="m">1</a>;
 308  <a id='2655' tid='2656', class="m">Handle</a>&lt;<a id='2657' tid='2658', class="m">Value</a>&gt; <a id='2659' tid='2660', class="m">argv</a>[<a id='2661' tid='2662', class="m">kArgc</a>] = { <a id='2663' tid='2664', class="m">command</a> };
 309  <a id='2665' tid='2666', class="m">Handle</a>&lt;<a id='2667' tid='2668', class="m">Value</a>&gt; <a id='2669' tid='2670', class="m">val</a> = <a id='2671' tid='2672', class="m">Handle</a>&lt;<a id='2673' tid='2674', class="m">Function</a>&gt;<a id='2675' tid='2676', class="m">::</a><a id='2677' tid='2678', class="m">Cast</a>(<a id='2679' tid='2680', class="m">fun</a>)-&gt;<a id='2681' tid='2682', class="m">Call</a>(<a id='2683' tid='2684', class="m">global</a>, <a id='2685' tid='2686', class="m">kArgc</a>, <a id='2687' tid='2688', class="m">argv</a>);
 310  <a id='2689' tid='2690', class="m">return</a> <a id='2691' tid='2692', class="m">val</a>;
 311}
 312<span class="d">#endif</span>
 313
 314
 315<a id='2493' tid='2494', class="m">int32_t</a><a id='2495' tid='2496', class="m">*</a> <a id='2497' tid='2498', class="m">Counter</a><a id='2499' tid='2500', class="m">::</a><a id='2501' tid='2502', class="m">Bind</a>(<a id='2503' tid='2504', class="m">const</a> <a id='2505' tid='2506', class="m">char</a><a id='2507' tid='2508', class="m">*</a> <a id='2509' tid='2510', class="m">name</a>, <a id='2511' tid='2512', class="m">bool</a> <a id='2513' tid='2514', class="m">is_histogram</a>) {
 316  <a id='2515' tid='2516', class="m">int</a> <a id='2517' tid='2518', class="m">i</a>;
 317  <a id='2519' tid='2520', class="m">for</a> (<a id='2521' tid='2522', class="m">i</a> <a id='2523' tid='2524', class="m">=</a> <a id='2525' tid='2526', class="m">0</a>; <a id='2527' tid='2528', class="m">i</a> <a id='2529' tid='2530', class="m">&lt;</a> <a id='2531' tid='2532', class="m">kMaxNameSize</a> <a id='2533' tid='2534', class="m">-</a> <a id='2535' tid='2536', class="m">1</a> <a id='2537' tid='2538', class="m">&&</a> <a id='2539' tid='2540', class="m">name</a>[<a id='2541' tid='2542', class="m">i</a>]; <a id='2543' tid='2544', class="m">i</a><a id='2545' tid='2546', class="m">++</a>)
 318    <a id='2547' tid='2548', class="m">name_</a>[<a id='2549' tid='2550', class="m">i</a>] <a id='2551' tid='2552', class="m">=</a> <a id='2553' tid='2554', class="m">static_cast</a>&lt;<a id='2555' tid='2556', class="m">char</a>&gt;(<a id='2557' tid='2558', class="m">name</a>[<a id='2559' tid='2560', class="m">i</a>]);
 319  <a id='2561' tid='2562', class="m">name_</a>[<a id='2563' tid='2564', class="m">i</a>] <a id='2565' tid='2566', class="m">=</a> <a id='2567' tid='2568', class="m">&#39;\0&#39;</a>;
 320  <a id='2569' tid='2570', class="m">is_histogram_</a> <a id='2571' tid='2572', class="m">=</a> <a id='2573' tid='2574', class="m">is_histogram</a>;
 321  <a id='2575' tid='2576', class="m">return</a> <a id='2577' tid='2578', class="m">ptr</a>();
 322}
 323
 324
 325<a id='2449' tid='2450', class="m">void</a> <a id='2451' tid='2452', class="m">Counter</a><a id='2453' tid='2454', class="m">::</a><a id='2455' tid='2456', class="m">AddSample</a>(<a id='2457' tid='2458', class="m">int32_t</a> <a id='2459' tid='2460', class="m">sample</a>) {
 326  <a id='2461' tid='2462', class="m">count_</a><a id='2463' tid='2464', class="m">++</a>;
 327  <a id='2465' tid='2466', class="m">sample_total_</a> <a id='2467' tid='2468', class="m">+=</a> <a id='2469' tid='2470', class="m">sample</a>;
 328}
 329
 330
 331<a id='2393' tid='2394', class="m">CounterCollection</a><a id='2395' tid='2396', class="m">::</a><a id='2397' tid='2398', class="m">CounterCollection</a>() {
 332  <a id='2399' tid='2400', class="m">magic_number_</a> <a id='2401' tid='2402', class="m">=</a> <a id='2403' tid='2404', class="m">0xDEADFACE</a>;
 333  <a id='2405' tid='2406', class="m">max_counters_</a> <a id='2407' tid='2408', class="m">=</a> <a id='2409' tid='2410', class="m">kMaxCounters</a>;
 334  <a id='2411' tid='2412', class="m">max_name_size_</a> <a id='2413' tid='2414', class="m">=</a> <a id='2415' tid='2416', class="m">Counter</a><a id='2417' tid='2418', class="m">::</a><a id='2419' tid='2420', class="m">kMaxNameSize</a>;
 335  <a id='2421' tid='2422', class="m">counters_in_use_</a> <a id='2423' tid='2424', class="m">=</a> <a id='2425' tid='2426', class="m">0</a>;
 336}
 337
 338
 339<a id='2361' tid='2362', class="m">Counter</a><a id='2363' tid='2364', class="m">*</a> <a id='2365' tid='2366', class="m">CounterCollection</a><a id='2367' tid='2368', class="m">::</a><a id='2369' tid='2370', class="m">GetNextCounter</a>() {
 340  <a id='2371' tid='2372', class="m">if</a> (<a id='2373' tid='2374', class="m">counters_in_use_</a> <a id='2375' tid='2376', class="m">==</a> <a id='2377' tid='2378', class="m">kMaxCounters</a>) <a id='2379' tid='2380', class="m">return</a> <a id='2381' tid='2382', class="m">NULL</a>;
 341  <a id='2383' tid='2384', class="m">return</a> <a id='2385' tid='2386', class="m">&</a><a id='2387' tid='2388', class="m">counters_</a>[<a id='2389' tid='2390', class="m">counters_in_use_</a><a id='2391' tid='2392', class="m">++</a>];
 342}
 343
 344
 345<a id='2245' tid='2246', class="m">void</a> <a id='2247' tid='2248', class="m">Shell</a><a id='2249' tid='2250', class="m">::</a><a id='2251' tid='2252', class="m">MapCounters</a>(<a id='2253' tid='2254', class="m">const</a> <a id='2255' tid='2256', class="m">char</a><a id='2257' tid='2258', class="m">*</a> <a id='2259' tid='2260', class="m">name</a>) {
 346  <a id='2261' tid='2262', class="m">counters_file_</a> <a id='2263' tid='2264', class="m">=</a> <a id='2265' tid='2266', class="m">i</a><a id='2267' tid='2268', class="m">::</a><a id='2269' tid='2270', class="m">OS</a><a id='2271' tid='2272', class="m">::</a><a id='2273' tid='2274', class="m">MemoryMappedFile</a><a id='2275' tid='2276', class="m">::</a><a id='2277' tid='2278', class="m">create</a>(<a id='2279' tid='2280', class="m">name</a>,
 347    <a id='2281' tid='2282', class="m">sizeof</a>(<a id='2283' tid='2284', class="m">CounterCollection</a>), <a id='2285' tid='2286', class="m">&</a><a id='2287' tid='2288', class="m">local_counters_</a>);
 348  <a id='2289' tid='2290', class="m">void</a><a id='2291' tid='2292', class="m">*</a> <a id='2293' tid='2294', class="m">memory</a> = (<a id='2295' tid='2296', class="m">counters_file_</a> <a id='2297' tid='2298', class="m">==</a> <a id='2299' tid='2300', class="m">NULL</a>) ?
 349      <a id='2301' tid='2302', class="m">NULL</a> : <a id='2303' tid='2304', class="m">counters_file_</a>-&gt;<a id='2305' tid='2306', class="m">memory</a>();
 350  <a id='2307' tid='2308', class="m">if</a> (<a id='2309' tid='2310', class="m">memory</a> <a id='2311' tid='2312', class="m">==</a> <a id='2313' tid='2314', class="m">NULL</a>) {
 351    <a id='2315' tid='2316', class="m">printf</a>(<a id='2317' tid='2318', class="m">&quot;Could not map counters file %s\n&quot;</a>, <a id='2319' tid='2320', class="m">name</a>);
 352    <a id='2321' tid='2322', class="m">exit</a>(<a id='2323' tid='2324', class="m">1</a>);
 353  }
 354  <a id='2325' tid='2326', class="m">counters_</a> <a id='2327' tid='2328', class="m">=</a> <a id='2329' tid='2330', class="m">static_cast</a>&lt;<a id='2331' tid='2332', class="m">CounterCollection</a><a id='2333' tid='2334', class="m">*</a>&gt;(<a id='2335' tid='2336', class="m">memory</a>);
 355  <a id='2337' tid='2338', class="m">V8</a><a id='2339' tid='2340', class="m">::</a><a id='2341' tid='2342', class="m">SetCounterFunction</a>(<a id='2343' tid='2344', class="m">LookupCounter</a>);
 356  <a id='2345' tid='2346', class="m">V8</a><a id='2347' tid='2348', class="m">::</a><a id='2349' tid='2350', class="m">SetCreateHistogramFunction</a>(<a id='2351' tid='2352', class="m">CreateHistogram</a>);
 357  <a id='2353' tid='2354', class="m">V8</a><a id='2355' tid='2356', class="m">::</a><a id='2357' tid='2358', class="m">SetAddHistogramSampleFunction</a>(<a id='2359' tid='2360', class="m">AddHistogramSample</a>);
 358}
 359
 360
 361<a id='2183' tid='2184', class="m">int</a> <a id='2185' tid='2186', class="m">CounterMap</a><a id='2187' tid='2188', class="m">::</a><a id='2189' tid='2190', class="m">Hash</a>(<a id='2191' tid='2192', class="m">const</a> <a id='2193' tid='2194', class="m">char</a><a id='2195' tid='2196', class="m">*</a> <a id='2197' tid='2198', class="m">name</a>) {
 362  <a id='2199' tid='2200', class="m">int</a> <a id='2201' tid='2202', class="m">h</a> = <a id='2203' tid='2204', class="m">0</a>;
 363  <a id='2205' tid='2206', class="m">int</a> <a id='2207' tid='2208', class="m">c</a>;
 364  <a id='2209' tid='2210', class="m">while</a> ((<a id='2211' tid='2212', class="m">c</a> <a id='2213' tid='2214', class="m">=</a> <a id='2215' tid='2216', class="m">*</a><a id='2217' tid='2218', class="m">name</a><a id='2219' tid='2220', class="m">++</a>) <a id='2221' tid='2222', class="m">!=</a> <a id='2223' tid='2224', class="m">0</a>) {
 365    <a id='2225' tid='2226', class="m">h</a> <a id='2227' tid='2228', class="m">+=</a> <a id='2229' tid='2230', class="m">h</a> <a id='2231' tid='2232', class="m">&lt;&lt;</a> <a id='2233' tid='2234', class="m">5</a>;
 366    <a id='2235' tid='2236', class="m">h</a> <a id='2237' tid='2238', class="m">+=</a> <a id='2239' tid='2240', class="m">c</a>;
 367  }
 368  <a id='2241' tid='2242', class="m">return</a> <a id='2243' tid='2244', class="m">h</a>;
 369}
 370
 371
 372<a id='2093' tid='2094', class="m">Counter</a><a id='2095' tid='2096', class="m">*</a> <a id='2097' tid='2098', class="m">Shell</a><a id='2099' tid='2100', class="m">::</a><a id='2101' tid='2102', class="m">GetCounter</a>(<a id='2103' tid='2104', class="m">const</a> <a id='2105' tid='2106', class="m">char</a><a id='2107' tid='2108', class="m">*</a> <a id='2109' tid='2110', class="m">name</a>, <a id='2111' tid='2112', class="m">bool</a> <a id='2113' tid='2114', class="m">is_histogram</a>) {
 373  <a id='2115' tid='2116', class="m">Counter</a><a id='2117' tid='2118', class="m">*</a> <a id='2119' tid='2120', class="m">counter</a> = <a id='2121' tid='2122', class="m">counter_map_</a>-&gt;<a id='2123' tid='2124', class="m">Lookup</a>(<a id='2125' tid='2126', class="m">name</a>);
 374
 375  <a id='2127' tid='2128', class="m">if</a> (<a id='2129' tid='2130', class="m">counter</a> <a id='2131' tid='2132', class="m">==</a> <a id='2133' tid='2134', class="m">NULL</a>) {
 376    <a id='2135' tid='2136', class="m">counter</a> <a id='2137' tid='2138', class="m">=</a> <a id='2139' tid='2140', class="m">counters_</a>-&gt;<a id='2141' tid='2142', class="m">GetNextCounter</a>();
 377    <a id='2143' tid='2144', class="m">if</a> (<a id='2145' tid='2146', class="m">counter</a> <a id='2147' tid='2148', class="m">!=</a> <a id='2149' tid='2150', class="m">NULL</a>) {
 378      <a id='2151' tid='2152', class="m">counter_map_</a>-&gt;<a id='2153' tid='2154', class="m">Set</a>(<a id='2155' tid='2156', class="m">name</a>, <a id='2157' tid='2158', class="m">counter</a>);
 379      <a id='2159' tid='2160', class="m">counter</a>-&gt;<a id='2161' tid='2162', class="m">Bind</a>(<a id='2163' tid='2164', class="m">name</a>, <a id='2165' tid='2166', class="m">is_histogram</a>);
 380    }
 381  } <a id='2167' tid='2168', class="m">else</a> {
 382    <a id='2169' tid='2170', class="m">ASSERT</a>(<a id='2171' tid='2172', class="m">counter</a>-&gt;<a id='2173' tid='2174', class="m">is_histogram</a>() <a id='2175' tid='2176', class="m">==</a> <a id='2177' tid='2178', class="m">is_histogram</a>);
 383  }
 384  <a id='2179' tid='2180', class="m">return</a> <a id='2181' tid='2182', class="m">counter</a>;
 385}
 386
 387
 388<a id='2043' tid='2044', class="m">int</a><a id='2045' tid='2046', class="m">*</a> <a id='2047' tid='2048', class="m">Shell</a><a id='2049' tid='2050', class="m">::</a><a id='2051' tid='2052', class="m">LookupCounter</a>(<a id='2053' tid='2054', class="m">const</a> <a id='2055' tid='2056', class="m">char</a><a id='2057' tid='2058', class="m">*</a> <a id='2059' tid='2060', class="m">name</a>) {
 389  <a id='2061' tid='2062', class="m">Counter</a><a id='2063' tid='2064', class="m">*</a> <a id='2065' tid='2066', class="m">counter</a> = <a id='2067' tid='2068', class="m">GetCounter</a>(<a id='2069' tid='2070', class="m">name</a>, <a id='2071' tid='2072', class="m">false</a>);
 390
 391  <a id='2073' tid='2074', class="m">if</a> (<a id='2075' tid='2076', class="m">counter</a> <a id='2077' tid='2078', class="m">!=</a> <a id='2079' tid='2080', class="m">NULL</a>) {
 392    <a id='2081' tid='2082', class="m">return</a> <a id='2083' tid='2084', class="m">counter</a>-&gt;<a id='2085' tid='2086', class="m">ptr</a>();
 393  } <a id='2087' tid='2088', class="m">else</a> {
 394    <a id='2089' tid='2090', class="m">return</a> <a id='2091' tid='2092', class="m">NULL</a>;
 395  }
 396}
 397
 398
 399<a id='2005' tid='2006', class="m">void</a><a id='2007' tid='2008', class="m">*</a> <a id='2009' tid='2010', class="m">Shell</a><a id='2011' tid='2012', class="m">::</a><a id='2013' tid='2014', class="m">CreateHistogram</a>(<a id='2015' tid='2016', class="m">const</a> <a id='2017' tid='2018', class="m">char</a><a id='2019' tid='2020', class="m">*</a> <a id='2021' tid='2022', class="m">name</a>,
 400                             <a id='2023' tid='2024', class="m">int</a> <a id='2025' tid='2026', class="m">min</a>,
 401                             <a id='2027' tid='2028', class="m">int</a> <a id='2029' tid='2030', class="m">max</a>,
 402                             <a id='2031' tid='2032', class="m">size_t</a> <a id='2033' tid='2034', class="m">buckets</a>) {
 403  <a id='2035' tid='2036', class="m">return</a> <a id='2037' tid='2038', class="m">GetCounter</a>(<a id='2039' tid='2040', class="m">name</a>, <a id='2041' tid='2042', class="m">true</a>);
 404}
 405
 406
 407<a id='1967' tid='1968', class="m">void</a> <a id='1969' tid='1970', class="m">Shell</a><a id='1971' tid='1972', class="m">::</a><a id='1973' tid='1974', class="m">AddHistogramSample</a>(<a id='1975' tid='1976', class="m">void</a><a id='1977' tid='1978', class="m">*</a> <a id='1979' tid='1980', class="m">histogram</a>, <a id='1981' tid='1982', class="m">int</a> <a id='1983' tid='1984', class="m">sample</a>) {
 408  <a id='1985' tid='1986', class="m">Counter</a><a id='1987' tid='1988', class="m">*</a> <a id='1989' tid='1990', class="m">counter</a> = <a id='1991' tid='1992', class="m">reinterpret_cast</a>&lt;<a id='1993' tid='1994', class="m">Counter</a><a id='1995' tid='1996', class="m">*</a>&gt;(<a id='1997' tid='1998', class="m">histogram</a>);
 409  <a id='1999' tid='2000', class="m">counter</a>-&gt;<a id='2001' tid='2002', class="m">AddSample</a>(<a id='2003' tid='2004', class="m">sample</a>);
 410}
 411
 412
 413<span class="d">void</span> <span class="d">Shell::Initialize</span><span class="d">()</span> {
 414  <a id='1043' tid='1044', class="m">Shell</a><a id='1045' tid='1046', class="m">::</a><a id='1047' tid='1048', class="m">counter_map_</a> <a id='1049' tid='1050', class="m">=</a> <a id='1051' tid='1052', class="m">new</a> <a id='1053' tid='1054', class="m">CounterMap</a>();
 415  // Set up counters
 416  <span class="d">if (i::FLAG_map_counters != NULL)
 417    MapCounters(i::FLAG_map_counters);</span>
 418  <a id='181' tid='182', class="m">if</a> (<a id='183' tid='184', class="m">i</a><a id='185' tid='186', class="m">::</a><a id='187' tid='188', class="m">FLAG_dump_counters</a>) {
 419    <a id='189' tid='190', class="m">V8</a><a id='191' tid='192', class="m">::</a><a id='193' tid='194', class="m">SetCounterFunction</a>(<a id='195' tid='196', class="m">LookupCounter</a>);
 420    <a id='197' tid='198', class="m">V8</a><a id='199' tid='200', class="m">::</a><a id='201' tid='202', class="m">SetCreateHistogramFunction</a>(<a id='203' tid='204', class="m">CreateHistogram</a>);
 421    <a id='205' tid='206', class="m">V8</a><a id='207' tid='208', class="m">::</a><a id='209' tid='210', class="m">SetAddHistogramSampleFunction</a>(<a id='211' tid='212', class="m">AddHistogramSample</a>);
 422  }
 423
 424  // Initialize the global objects
 425  <span class="d">HandleScope scope;</span>
 426  <span class="d">Handle&lt;ObjectTemplate&gt; global_template = ObjectTemplate::New();</span>
 427  <a id='1903' tid='1904', class="m">global_template</a>-&gt;<a id='1905' tid='1906', class="m">Set</a>(<a id='1907' tid='1908', class="m">String</a><a id='1909' tid='1910', class="m">::</a><a id='1911' tid='1912', class="m">New</a>(<a id='1913' tid='1914', class="m">&quot;print&quot;</a>), <a id='1915' tid='1916', class="m">FunctionTemplate</a><a id='1917' tid='1918', class="m">::</a><a id='1919' tid='1920', class="m">New</a>(<a id='1921' tid='1922', class="m">Print</a>));
 428  <a id='1751' tid='1752', class="m">global_template</a>-&gt;<a id='1753' tid='1754', class="m">Set</a>(<a id='1755' tid='1756', class="m">String</a><a id='1757' tid='1758', class="m">::</a><a id='1759' tid='1760', class="m">New</a>(<a id='1761' tid='1762', class="m">&quot;write&quot;</a>), <a id='1763' tid='1764', class="m">FunctionTemplate</a><a id='1765' tid='1766', class="m">::</a><a id='1767' tid='1768', class="m">New</a>(<a id='1769' tid='1770', class="m">Write</a>));
 429  <a id='1491' tid='1492', class="m">global_template</a>-&gt;<a id='1493' tid='1494', class="m">Set</a>(<a id='1495' tid='1496', class="m">String</a><a id='1497' tid='1498', class="m">::</a><a id='1499' tid='1500', class="m">New</a>(<a id='1501' tid='1502', class="m">&quot;read&quot;</a>), <a id='1503' tid='1504', class="m">FunctionTemplate</a><a id='1505' tid='1506', class="m">::</a><a id='1507' tid='1508', class="m">New</a>(<a id='1509' tid='1510', class="m">Read</a>));
 430  <a id='1397' tid='1398', class="m">global_template</a>-&gt;<a id='1399' tid='1400', class="m">Set</a>(<a id='1401' tid='1402', class="m">String</a><a id='1403' tid='1404', class="m">::</a><a id='1405' tid='1406', class="m">New</a>(<a id='1407' tid='1408', class="m">&quot;readline&quot;</a>),
 431                       <a id='1409' tid='1410', class="m">FunctionTemplate</a><a id='1411' tid='1412', class="m">::</a><a id='1413' tid='1414', class="m">New</a>(<a id='1415' tid='1416', class="m">ReadLine</a>));
 432  <a id='1303' tid='1304', class="m">global_template</a>-&gt;<a id='1305' tid='1306', class="m">Set</a>(<a id='1307' tid='1308', class="m">String</a><a id='1309' tid='1310', class="m">::</a><a id='1311' tid='1312', class="m">New</a>(<a id='1313' tid='1314', class="m">&quot;load&quot;</a>), <a id='1315' tid='1316', class="m">FunctionTemplate</a><a id='1317' tid='1318', class="m">::</a><a id='1319' tid='1320', class="m">New</a>(<a id='1321' tid='1322', class="m">Load</a>));
 433  <a id='1085' tid='1086', class="m">global_template</a>-&gt;<a id='1087' tid='1088', class="m">Set</a>(<a id='1089' tid='1090', class="m">String</a><a id='1091' tid='1092', class="m">::</a><a id='1093' tid='1094', class="m">New</a>(<a id='1095' tid='1096', class="m">&quot;quit&quot;</a>), <a id='1097' tid='1098', class="m">FunctionTemplate</a><a id='1099' tid='1100', class="m">::</a><a id='1101' tid='1102', class="m">New</a>(<a id='1103' tid='1104', class="m">Quit</a>));
 434  <a id='437' tid='438', class="m">global_template</a>-&gt;<a id='439' tid='440', class="m">Set</a>(<a id='441' tid='442', class="m">String</a><a id='443' tid='444', class="m">::</a><a id='445' tid='446', class="m">New</a>(<a id='447' tid='448', class="m">&quot;version&quot;</a>), <a id='449' tid='450', class="m">FunctionTemplate</a><a id='451' tid='452', class="m">::</a><a id='453' tid='454', class="m">New</a>(<a id='455' tid='456', class="m">Version</a>));
 435
 436  <a id='263' tid='264', class="m">Handle</a>&lt;<a id='265' tid='266', class="m">ObjectTemplate</a>&gt; <a id='267' tid='268', class="m">os_templ</a> = <a id='269' tid='270', class="m">ObjectTemplate</a><a id='271' tid='272', class="m">::</a><a id='273' tid='274', class="m">New</a>();
 437  <span class="d">AddOSMethods(os_templ);</span>
 438  <a id='249' tid='250', class="m">global_template</a>-&gt;<a id='251' tid='252', class="m">Set</a>(<a id='253' tid='254', class="m">String</a><a id='255' tid='256', class="m">::</a><a id='257' tid='258', class="m">New</a>(<a id='259' tid='260', class="m">&quot;os&quot;</a>), <a id='261' tid='262', class="m">os_templ</a>);
 439
 440  <span class="d">utility_context_</span> <span class="d">=</span> <a id='953' tid='954', class="m">Context</a><a id='955' tid='956', class="m">::</a><a id='957' tid='958', class="m">New</a>(<a id='959' tid='960', class="m">NULL</a>, <a id='961' tid='962', class="m">global_template</a>);
 441  <span class="d">utility_context_-&gt;SetSecurityToken(Undefined());</span>
 442  <a id='1957' tid='1958', class="m">Context</a><a id='1959' tid='1960', class="m">::</a><a id='1961' tid='1962', class="m">Scope</a> <a id='1963' tid='1964', class="m">utility_scope</a>(<a id='1965' tid='1966', class="m">utility_context_</a>);
 443
 444  <a id='167' tid='168', class="m">i</a><a id='169' tid='170', class="m">::</a><a id='171' tid='172', class="m">JSArguments</a> <a id='173' tid='174', class="m">js_args</a> = <a id='175' tid='176', class="m">i</a><a id='177' tid='178', class="m">::</a><a id='179' tid='180', class="m">FLAG_js_arguments</a>;
 445  <a id='137' tid='138', class="m">i</a><a id='139' tid='140', class="m">::</a><a id='141' tid='142', class="m">Handle</a>&lt;<a id='143' tid='144', class="m">i</a><a id='145' tid='146', class="m">::</a><a id='147' tid='148', class="m">FixedArray</a>&gt; <span class="d">arguments_array =
 446      i::Factory::NewFixedArray(js_args.argc())</span>;
 447  <a id='29' tid='30', class="m">for</a> (<a id='31' tid='32', class="m">int</a> <a id='33' tid='34', class="m">j</a> = <a id='35' tid='36', class="m">0</a>; <a id='37' tid='38', class="m">j</a> <a id='39' tid='40', class="m">&lt;</a> <a id='41' tid='42', class="m">js_args</a>.<a id='43' tid='44', class="m">argc</a>(); <a id='45' tid='46', class="m">j</a><a id='47' tid='48', class="m">++</a>) {
 448    <a id='49' tid='50', class="m">i</a><a id='51' tid='52', class="m">::</a><a id='53' tid='54', class="m">Handle</a>&lt;<a id='55' tid='56', class="m">i</a><a id='57' tid='58', class="m">::</a><a id='59' tid='60', class="m">String</a>&gt; <a id='61' tid='62', class="m">arg</a> =
 449        <span class="d">i::Factory::NewStringFromUtf8</span>(<a id='63' tid='64', class="m">i</a><a id='65' tid='66', class="m">::</a><a id='67' tid='68', class="m">CStrVector</a>(<a id='69' tid='70', class="m">js_args</a>[<a id='71' tid='72', class="m">j</a>]));
 450    <a id='73' tid='74', class="m">arguments_array</a>-&gt;<a id='75' tid='76', class="m">set</a>(<a id='77' tid='78', class="m">j</a>, <a id='79' tid='80', class="m">*</a><a id='81' tid='82', class="m">arg</a>);
 451  }
 452  <a id='17' tid='18', class="m">i</a><a id='19' tid='20', class="m">::</a><a id='21' tid='22', class="m">Handle</a>&lt;<a id='23' tid='24', class="m">i</a><a id='25' tid='26', class="m">::</a><a id='27' tid='28', class="m">JSArray</a>&gt; <span class="d">arguments_jsarray =
 453      i::Factory::NewJSArrayWithElements(arguments_array)</span>;
 454  <span class="d">global_template-&gt;Set</span>(<a id='1' tid='2', class="m">String</a><a id='3' tid='4', class="m">::</a><a id='5' tid='6', class="m">New</a>(<a id='7' tid='8', class="m">&quot;arguments&quot;</a>),
 455                       <a id='9' tid='10', class="m">Utils</a><a id='11' tid='12', class="m">::</a><a id='13' tid='14', class="m">ToLocal</a>(<a id='15' tid='16', class="m">arguments_jsarray</a>));
 456
 457<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
 458  // Install the debugger object in the utility scope
 459  <span class="d">i::Debug::Load();</span>
 460  <span class="d">i::JSObject* debug = i::Debug::debug_context()-&gt;global();</span>
 461  <span class="d">utility_context_-&gt;Global()-&gt;Set(String::New(&quot;$debug&quot;),
 462                                  Utils::ToLocal(&debug));</span>
 463<span class="d">#endif</span>
 464
 465  // Run the d8 shell utility script in the utility context
 466  <a id='1935' tid='1936', class="m">int</a> <a id='1937' tid='1938', class="m">source_index</a> = <a id='1939' tid='1940', class="m">i</a><a id='1941' tid='1942', class="m">::</a><a id='1943' tid='1944', class="m">NativesCollection</a>&lt;<a id='1945' tid='1946', class="m">i</a><a id='1947' tid='1948', class="m">::</a><a id='1949' tid='1950', class="m">D8</a>&gt;<a id='1951' tid='1952', class="m">::</a><a id='1953' tid='1954', class="m">GetIndex</a>(<a id='1955' tid='1956', class="m">&quot;d8&quot;</a>);
 467  <a id='1577' tid='1578', class="m">i</a><a id='1579' tid='1580', class="m">::</a><a id='1581' tid='1582', class="m">Vector</a>&lt;<a id='1583' tid='1584', class="m">const</a> <a id='1585' tid='1586', class="m">char</a>&gt; <span class="d">shell_source
 468      = i::NativesCollection&lt;i::D8&gt;::GetScriptSource(source_index)</span>;
 469  <a id='1439' tid='1440', class="m">i</a><a id='1441' tid='1442', class="m">::</a><a id='1443' tid='1444', class="m">Vector</a>&lt;<a id='1445' tid='1446', class="m">const</a> <a id='1447' tid='1448', class="m">char</a>&gt; <a id='1449' tid='1450', class="m">shell_source_name</a>
 470      = <a id='1451' tid='1452', class="m">i</a><a id='1453' tid='1454', class="m">::</a><a id='1455' tid='1456', class="m">NativesCollection</a>&lt;<a id='1457' tid='1458', class="m">i</a><a id='1459' tid='1460', class="m">::</a><a id='1461' tid='1462', class="m">D8</a>&gt;<a id='1463' tid='1464', class="m">::</a><a id='1465' tid='1466', class="m">GetScriptName</a>(<a id='1467' tid='1468', class="m">source_index</a>);
 471  <a id='1249' tid='1250', class="m">Handle</a>&lt;<a id='1251' tid='1252', class="m">String</a>&gt; <a id='1253' tid='1254', class="m">source</a> = <a id='1255' tid='1256', class="m">String</a><a id='1257' tid='1258', class="m">::</a><a id='1259' tid='1260', class="m">New</a>(<a id='1261' tid='1262', class="m">shell_source</a>.<a id='1263' tid='1264', class="m">start</a>(),
 472                                      <a id='1265' tid='1266', class="m">shell_source</a>.<a id='1267' tid='1268', class="m">length</a>());
 473  <a id='555' tid='556', class="m">Handle</a>&lt;<a id='557' tid='558', class="m">String</a>&gt; <a id='559' tid='560', class="m">name</a> = <a id='561' tid='562', class="m">String</a><a id='563' tid='564', class="m">::</a><a id='565' tid='566', class="m">New</a>(<a id='567' tid='568', class="m">shell_source_name</a>.<a id='569' tid='570', class="m">start</a>(),
 474                                    <a id='571' tid='572', class="m">shell_source_name</a>.<a id='573' tid='574', class="m">length</a>());
 475  <a id='313' tid='314', class="m">Handle</a>&lt;<a id='315' tid='316', class="m">Script</a>&gt; <a id='317' tid='318', class="m">script</a> = <a id='319' tid='320', class="m">Script</a><a id='321' tid='322', class="m">::</a><a id='323' tid='324', class="m">Compile</a>(<a id='325' tid='326', class="m">source</a>, <a id='327' tid='328', class="m">name</a>);
 476  <span class="d">script-&gt;Run();</span>
 477
 478  // Mark the d8 shell script as native to avoid it showing up as normal source
 479  // in the debugger.
 480  <span class="d">i::Handle&lt;i::JSFunction&gt;</span> <span class="d">script_fun</span> = <a id='285' tid='286', class="m">Utils</a><a id='287' tid='288', class="m">::</a><a id='289' tid='290', class="m">OpenHandle</a>(<a id='291' tid='292', class="m">*</a><a id='293' tid='294', class="m">script</a>);
 481  <a id='213' tid='214', class="m">i</a><a id='215' tid='216', class="m">::</a><a id='217' tid='218', class="m">Handle</a>&lt;<a id='219' tid='220', class="m">i</a><a id='221' tid='222', class="m">::</a><a id='223' tid='224', class="m">Script</a>&gt; <a id='225' tid='226', class="m">script_object</a> =
 482      <a id='227' tid='228', class="m">i</a><a id='229' tid='230', class="m">::</a><a id='231' tid='232', class="m">Handle</a>&lt;<a id='233' tid='234', class="m">i</a><a id='235' tid='236', class="m">::</a><a id='237' tid='238', class="m">Script</a>&gt;(<a id='239' tid='240', class="m">i</a><a id='241' tid='242', class="m">::</a><a id='243' tid='244', class="m">Script</a><a id='245' tid='246', class="m">::</a><a id='247' tid='248', class="m">cast</a><span class="d">(script_fun-&gt;shared()-&gt;script())</span>);
 483  <a id='113' tid='114', class="m">script_object</a>-&gt;<a id='115' tid='116', class="m">set_type</a>(<a id='117' tid='118', class="m">i</a><a id='119' tid='120', class="m">::</a><a id='121' tid='122', class="m">Smi</a><a id='123' tid='124', class="m">::</a><a id='125' tid='126', class="m">FromInt</a>(<a id='127' tid='128', class="m">i</a><a id='129' tid='130', class="m">::</a><a id='131' tid='132', class="m">Script</a><a id='133' tid='134', class="m">::</a><a id='135' tid='136', class="m">TYPE_NATIVE</a>));
 484
 485  // Create the evaluation context
 486  <span class="d">evaluation_context_</span> <span class="d">=</span> <a id='637' tid='638', class="m">Context</a><a id='639' tid='640', class="m">::</a><a id='641' tid='642', class="m">New</a>(<a id='643' tid='644', class="m">NULL</a>, <a id='645' tid='646', class="m">global_template</a>);
 487  <span class="d">evaluation_context_-&gt;SetSecurityToken(Undefined());</span>
 488
 489<span class="d">#ifdef ENABLE_DEBUGGER_SUPPORT</span>
 490  // Set the security token of the debug context to allow access.
 491  <span class="d">i::Debug::debug_context()-&gt;set_security_token(i::Heap::undefined_value());</span>
 492
 493  // Start the debugger agent if requested.
 494  <a id='149' tid='150', class="m">if</a> (<a id='151' tid='152', class="m">i</a><a id='153' tid='154', class="m">::</a><a id='155' tid='156', class="m">FLAG_debugger_agent</a>) {
 495    <a id='157' tid='158', class="m">v8</a><a id='159' tid='160', class="m">::</a><a id='161' tid='162', class="m">Debug</a><a id='163' tid='164', class="m">::</a><a id='165' tid='166', class="m">EnableAgent</a><span class="d">(&quot;d8 shell&quot;, i::FLAG_debugger_port)</span>;
 496  }
 497
 498  // Start the in-process debugger if requested.
 499  <a id='83' tid='84', class="m">if</a> (<a id='85' tid='86', class="m">i</a><a id='87' tid='88', class="m">::</a><a id='89' tid='90', class="m">FLAG_debugger</a> <a id='91' tid='92', class="m">&&</a> <a id='93' tid='94', class="m">!</a><a id='95' tid='96', class="m">i</a><a id='97' tid='98', class="m">::</a><a id='99' tid='100', class="m">FLAG_debugger_agent</a>) {
 500    <a id='101' tid='102', class="m">v8</a><a id='103' tid='104', class="m">::</a><a id='105' tid='106', class="m">Debug</a><a id='107' tid='108', class="m">::</a><a id='109' tid='110', class="m">SetDebugEventListener</a>(<a id='111' tid='112', class="m">HandleDebugEvent</a>);
 501  }
 502<span class="d">#endif</span>
 503}
 504
 505
 506<a id='1771' tid='1772', class="m">void</a> <a id='1773' tid='1774', class="m">Shell</a><a id='1775' tid='1776', class="m">::</a><a id='1777' tid='1778', class="m">OnExit</a>() {
 507  <a id='1779' tid='1780', class="m">if</a> (<a id='1781' tid='1782', class="m">i</a><a id='1783' tid='1784', class="m">::</a><a id='1785' tid='1786', class="m">FLAG_dump_counters</a>) {
 508    <a id='1787' tid='1788', class="m">::</a><a id='1789' tid='1790', class="m">printf</a>(<a id='1791' tid='1792', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
 509    <a id='1793' tid='1794', class="m">::</a><a id='1795' tid='1796', class="m">printf</a>(<a id='1797' tid='1798', class="m">&quot;| Name                                   | Value       |\n&quot;</a>);
 510    <a id='1799' tid='1800', class="m">::</a><a id='1801' tid='1802', class="m">printf</a>(<a id='1803' tid='1804', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
 511    <a id='1805' tid='1806', class="m">for</a> (<a id='1807' tid='1808', class="m">CounterMap</a><a id='1809' tid='1810', class="m">::</a><a id='1811' tid='1812', class="m">Iterator</a> <a id='1813' tid='1814', class="m">i</a>(<a id='1815' tid='1816', class="m">counter_map_</a>); <a id='1817' tid='1818', class="m">i</a>.<a id='1819' tid='1820', class="m">More</a>(); <a id='1821' tid='1822', class="m">i</a>.<a id='1823' tid='1824', class="m">Next</a>()) {
 512      <a id='1825' tid='1826', class="m">Counter</a><a id='1827' tid='1828', class="m">*</a> <a id='1829' tid='1830', class="m">counter</a> = <a id='1831' tid='1832', class="m">i</a>.<a id='1833' tid='1834', class="m">CurrentValue</a>();
 513      <a id='1835' tid='1836', class="m">if</a> (<a id='1837' tid='1838', class="m">counter</a>-&gt;<a id='1839' tid='1840', class="m">is_histogram</a>()) {
 514        <a id='1841' tid='1842', class="m">::</a><a id='1843' tid='1844', class="m">printf</a>(<a id='1845' tid='1846', class="m">&quot;| c:%-36s | %11i |\n&quot;</a>, <a id='1847' tid='1848', class="m">i</a>.<a id='1849' tid='1850', class="m">CurrentKey</a>(), <a id='1851' tid='1852', class="m">counter</a>-&gt;<a id='1853' tid='1854', class="m">count</a>());
 515        <a id='1855' tid='1856', class="m">::</a><a id='1857' tid='1858', class="m">printf</a>(<a id='1859' tid='1860', class="m">&quot;| t:%-36s | %11i |\n&quot;</a>,
 516                 <a id='1861' tid='1862', class="m">i</a>.<a id='1863' tid='1864', class="m">CurrentKey</a>(),
 517                 <a id='1865' tid='1866', class="m">counter</a>-&gt;<a id='1867' tid='1868', class="m">sample_total</a>());
 518      } <a id='1869' tid='1870', class="m">else</a> {
 519        <a id='1871' tid='1872', class="m">::</a><a id='1873' tid='1874', class="m">printf</a>(<a id='1875' tid='1876', class="m">&quot;| %-38s | %11i |\n&quot;</a>, <a id='1877' tid='1878', class="m">i</a>.<a id='1879' tid='1880', class="m">CurrentKey</a>(), <a id='1881' tid='1882', class="m">counter</a>-&gt;<a id='1883' tid='1884', class="m">count</a>());
 520      }
 521    }
 522    <a id='1885' tid='1886', class="m">::</a><a id='1887' tid='1888', class="m">printf</a>(<a id='1889' tid='1890', class="m">&quot;+----------------------------------------+-------------+\n&quot;</a>);
 523  }
 524  <a id='1891' tid='1892', class="m">if</a> (<a id='1893' tid='1894', class="m">counters_file_</a> <a id='1895' tid='1896', class="m">!=</a> <a id='1897' tid='1898', class="m">NULL</a>)
 525    <a id='1899' tid='1900', class="m">delete</a> <a id='1901' tid='1902', class="m">counters_file_</a>;
 526}
 527
 528
 529<a id='1587' tid='1588', class="m">static</a> <a id='1589' tid='1590', class="m">char</a><a id='1591' tid='1592', class="m">*</a> <a id='1593' tid='1594', class="m">ReadChars</a>(<a id='1595' tid='1596', class="m">const</a> <a id='1597' tid='1598', class="m">char</a><a id='1599' tid='1600', class="m">*</a> <a id='1601' tid='1602', class="m">name</a>, <a id='1603' tid='1604', class="m">int</a><a id='1605' tid='1606', class="m">*</a> <a id='1607' tid='1608', class="m">size_out</a>) {
 530  <a id='1609' tid='1610', class="m">v8</a><a id='1611' tid='1612', class="m">::</a><a id='1613' tid='1614', class="m">Unlocker</a> <a id='1615' tid='1616', class="m">unlocker</a>;  // Release the V8 lock while reading files.
 531  <a id='1617' tid='1618', class="m">FILE</a><a id='1619' tid='1620', class="m">*</a> <a id='1621' tid='1622', class="m">file</a> = <a id='1623' tid='1624', class="m">i</a><a id='1625' tid='1626', class="m">::</a><a id='1627' tid='1628', class="m">OS</a><a id='1629' tid='1630', class="m">::</a><a id='1631' tid='1632', class="m">FOpen</a>(<a id='1633' tid='1634', class="m">name</a>, <a id='1635' tid='1636', class="m">&quot;rb&quot;</a>);
 532  <a id='1637' tid='1638', class="m">if</a> (<a id='1639' tid='1640', class="m">file</a> <a id='1641' tid='1642', class="m">==</a> <a id='1643' tid='1644', class="m">NULL</a>) <a id='1645' tid='1646', class="m">return</a> <a id='1647' tid='1648', class="m">NULL</a>;
 533
 534  <a id='1649' tid='1650', class="m">fseek</a>(<a id='1651' tid='1652', class="m">file</a>, <a id='1653' tid='1654', class="m">0</a>, <a id='1655' tid='1656', class="m">SEEK_END</a>);
 535  <a id='1657' tid='1658', class="m">int</a> <a id='1659' tid='1660', class="m">size</a> = <a id='1661' tid='1662', class="m">ftell</a>(<a id='1663' tid='1664', class="m">file</a>);
 536  <a id='1665' tid='1666', class="m">rewind</a>(<a id='1667' tid='1668', class="m">file</a>);
 537
 538  <a id='1669' tid='1670', class="m">char</a><a id='1671' tid='1672', class="m">*</a> <a id='1673' tid='1674', class="m">chars</a> = <a id='1675' tid='1676', class="m">new</a> <a id='1677' tid='1678', class="m">char</a>[<a id='1679' tid='1680', class="m">size</a> <a id='1681' tid='1682', class="m">+</a> <a id='1683' tid='1684', class="m">1</a>];
 539  <a id='1685' tid='1686', class="m">chars</a>[<a id='1687' tid='1688', class="m">size</a>] <a id='1689' tid='1690', class="m">=</a> <a id='1691' tid='1692', class="m">&#39;\0&#39;</a>;
 540  <a id='1693' tid='1694', class="m">for</a> (<a id='1695' tid='1696', class="m">int</a> <a id='1697' tid='1698', class="m">i</a> = <a id='1699' tid='1700', class="m">0</a>; <a id='1701' tid='1702', class="m">i</a> <a id='1703' tid='1704', class="m">&lt;</a> <a id='1705' tid='1706', class="m">size</a>;) {
 541    <a id='1707' tid='1708', class="m">int</a> <a id='1709' tid='1710', class="m">read</a> = <a id='1711' tid='1712', class="m">fread</a>(<a id='1713' tid='1714', class="m">&</a><a id='1715' tid='1716', class="m">chars</a>[<a id='1717' tid='1718', class="m">i</a>], <a id='1719' tid='1720', class="m">1</a>, <a id='1721' tid='1722', class="m">size</a> <a id='1723' tid='1724', class="m">-</a> <a id='1725' tid='1726', class="m">i</a>, <a id='1727' tid='1728', class="m">file</a>);
 542    <a id='1729' tid='1730', class="m">i</a> <a id='1731' tid='1732', class="m">+=</a> <a id='1733' tid='1734', class="m">read</a>;
 543  }
 544  <a id='1735' tid='1736', class="m">fclose</a>(<a id='1737' tid='1738', class="m">file</a>);
 545  <a id='1739' tid='1740', class="m">*</a><a id='1741' tid='1742', class="m">size_out</a> <a id='1743' tid='1744', class="m">=</a> <a id='1745' tid='1746', class="m">size</a>;
 546  <a id='1747' tid='1748', class="m">return</a> <a id='1749' tid='1750', class="m">chars</a>;
 547}
 548
 549
 550<a id='1511' tid='1512', class="m">static</a> <a id='1513' tid='1514', class="m">char</a><a id='1515' tid='1516', class="m">*</a> <a id='1517' tid='1518', class="m">ReadToken</a>(<a id='1519' tid='1520', class="m">char</a><a id='1521' tid='1522', class="m">*</a> <a id='1523' tid='1524', class="m">data</a>, <a id='1525' tid='1526', class="m">char</a> <a id='1527' tid='1528', class="m">token</a>) {
 551  <a id='1529' tid='1530', class="m">char</a><a id='1531' tid='1532', class="m">*</a> <a id='1533' tid='1534', class="m">next</a> = <a id='1535' tid='1536', class="m">i</a><a id='1537' tid='1538', class="m">::</a><a id='1539' tid='1540', class="m">OS</a><a id='1541' tid='1542', class="m">::</a><a id='1543' tid='1544', class="m">StrChr</a>(<a id='1545' tid='1546', class="m">data</a>, <a id='1547' tid='1548', class="m">token</a>);
 552  <a id='1549' tid='1550', class="m">if</a> (<a id='1551' tid='1552', class="m">next</a> <a id='1553' tid='1554', class="m">!=</a> <a id='1555' tid='1556', class="m">NULL</a>) {
 553    <a id='1557' tid='1558', class="m">*</a><a id='1559' tid='1560', class="m">next</a> <a id='1561' tid='1562', class="m">=</a> <a id='1563' tid='1564', class="m">&#39;\0&#39;</a>;
 554    <a id='1565' tid='1566', class="m">return</a> (<a id='1567' tid='1568', class="m">next</a> <a id='1569' tid='1570', class="m">+</a> <a id='1571' tid='1572', class="m">1</a>);
 555  }
 556
 557  <a id='1573' tid='1574', class="m">return</a> <a id='1575' tid='1576', class="m">NULL</a>;
 558}
 559
 560
 561<a id='1469' tid='1470', class="m">static</a> <a id='1471' tid='1472', class="m">char</a><a id='1473' tid='1474', class="m">*</a> <a id='1475' tid='1476', class="m">ReadLine</a>(<a id='1477' tid='1478', class="m">char</a><a id='1479' tid='1480', class="m">*</a> <a id='1481' tid='1482', class="m">data</a>) {
 562  <a id='1483' tid='1484', class="m">return</a> <a id='1485' tid='1486', class="m">ReadToken</a>(<a id='1487' tid='1488', class="m">data</a>, <a id='1489' tid='1490', class="m">&#39;\n&#39;</a>);
 563}
 564
 565
 566<a id='1417' tid='1418', class="m">static</a> <a id='1419' tid='1420', class="m">char</a><a id='1421' tid='1422', class="m">*</a> <a id='1423' tid='1424', class="m">ReadWord</a>(<a id='1425' tid='1426', class="m">char</a><a id='1427' tid='1428', class="m">*</a> <a id='1429' tid='1430', class="m">data</a>) {
 567  <a id='1431' tid='1432', class="m">return</a> <a id='1433' tid='1434', class="m">ReadToken</a>(<a id='1435' tid='1436', class="m">data</a>, <a id='1437' tid='1438', class="m">&#39; &#39;</a>);
 568}
 569
 570
 571// Reads a file into a v8 string.
 572<a id='1323' tid='1324', class="m">Handle</a>&lt;<a id='1325' tid='1326', class="m">String</a>&gt; <a id='1327' tid='1328', class="m">Shell</a><a id='1329' tid='1330', class="m">::</a><a id='1331' tid='1332', class="m">ReadFile</a>(<a id='1333' tid='1334', class="m">const</a> <a id='1335' tid='1336', class="m">char</a><a id='1337' tid='1338', class="m">*</a> <a id='1339' tid='1340', class="m">name</a>) {
 573  <a id='1341' tid='1342', class="m">int</a> <a id='1343' tid='1344', class="m">size</a> = <a id='1345' tid='1346', class="m">0</a>;
 574  <a id='1347' tid='1348', class="m">char</a><a id='1349' tid='1350', class="m">*</a> <a id='1351' tid='1352', class="m">chars</a> = <a id='1353' tid='1354', class="m">ReadChars</a>(<a id='1355' tid='1356', class="m">name</a>, <a id='1357' tid='1358', class="m">&</a><a id='1359' tid='1360', class="m">size</a>);
 575  <a id='1361' tid='1362', class="m">if</a> (<a id='1363' tid='1364', class="m">chars</a> <a id='1365' tid='1366', class="m">==</a> <a id='1367' tid='1368', class="m">NULL</a>) <a id='1369' tid='1370', class="m">return</a> <a id='1371' tid='1372', class="m">Handle</a>&lt;<a id='1373' tid='1374', class="m">String</a>&gt;();
 576  <a id='1375' tid='1376', class="m">Handle</a>&lt;<a id='1377' tid='1378', class="m">String</a>&gt; <a id='1379' tid='1380', class="m">result</a> = <a id='1381' tid='1382', class="m">String</a><a id='1383' tid='1384', class="m">::</a><a id='1385' tid='1386', class="m">New</a>(<a id='1387' tid='1388', class="m">chars</a>);
 577  <a id='1389' tid='1390', class="m">delete</a>[] <a id='1391' tid='1392', class="m">chars</a>;
 578  <a id='1393' tid='1394', class="m">return</a> <a id='1395' tid='1396', class="m">result</a>;
 579}
 580
 581
 582<a id='1283' tid='1284', class="m">void</a> <a id='1285' tid='1286', class="m">Shell</a><a id='1287' tid='1288', class="m">::</a><a id='1289' tid='1290', class="m">RunShell</a>() {
 583  <a id='1291' tid='1292', class="m">LineEditor</a><a id='1293' tid='1294', class="m">*</a> <a id='1295' tid='1296', class="m">editor</a> = <a id='1297' tid='1298', class="m">LineEditor</a><a id='1299' tid='1300', class="m">::</a><a id='1301' tid='1302', class="m">Get</a>();
 584  <a id='1269' tid='1270', class="m">printf</a>(<a id='1271' tid='1272', class="m">&quot;V8 version %s [console: %s]\n&quot;</a>, <a id='1273' tid='1274', class="m">V8</a><a id='1275' tid='1276', class="m">::</a><a id='1277' tid='1278', class="m">GetVersion</a>(), <a id='1279' tid='1280', class="m">editor</a>-&gt;<a id='1281' tid='1282', class="m">name</a>());
 585  <span class="d">editor-&gt;Open();</span>
 586  <a id='1105' tid='1106', class="m">while</a> (<a id='1107' tid='1108', class="m">true</a>) {
 587    <a id='1119' tid='1120', class="m">Locker</a> <a id='1121' tid='1122', class="m">locker</a>;
 588    <a id='1123' tid='1124', class="m">HandleScope</a> <a id='1125' tid='1126', class="m">handle_scope</a>;
 589    <a id='1109' tid='1110', class="m">Context</a><a id='1111' tid='1112', class="m">::</a><a id='1113' tid='1114', class="m">Scope</a> <a id='1115' tid='1116', class="m">context_scope</a>(<a id='1117' tid='1118', class="m">evaluation_context_</a>);
 590    <a id='1127' tid='1128', class="m">i</a><a id='1129' tid='1130', class="m">::</a><a id='1131' tid='1132', class="m">SmartPointer</a>&lt;<a id='1133' tid='1134', class="m">char</a>&gt; <a id='1135' tid='1136', class="m">input</a> = <a id='1137' tid='1138', class="m">editor</a>-&gt;<a id='1139' tid='1140', class="m">Prompt</a>(<a id='1141' tid='1142', class="m">Shell</a><a id='1143' tid='1144', class="m">::</a><a id='1145' tid='1146', class="m">kPrompt</a>);
 591    <a id='1147' tid='1148', class="m">if</a> (<a id='1149' tid='1150', class="m">input</a>.<a id='1151' tid='1152', class="m">is_empty</a>())
 592      <a id='1153' tid='1154', class="m">break</a>;
 593    <a id='1155' tid='1156', class="m">editor</a>-&gt;<a id='1157' tid='1158', class="m">AddHistory</a>(<a id='1159' tid='1160', class="m">*</a><a id='1161' tid='1162', class="m">input</a>);
 594    <a id='1163' tid='1164', class="m">Handle</a>&lt;<a id='1165' tid='1166', class="m">String</a>&gt; <a id='1167' tid='1168', class="m">name</a> = <a id='1169' tid='1170', class="m">String</a><a id='1171' tid='1172', class="m">::</a><a id='1173' tid='1174', class="m">New</a>(<a id='1175' tid='1176', class="m">&quot;(d8)&quot;</a>);
 595    <a id='1177' tid='1178', class="m">ExecuteString</a>(<a id='1179' tid='1180', class="m">String</a><a id='1181' tid='1182', class="m">::</a><a id='1183' tid='1184', class="m">New</a>(<a id='1185' tid='1186', class="m">*</a><a id='1187' tid='1188', class="m">input</a>), <a id='1189' tid='1190', class="m">name</a>, <a id='1191' tid='1192', class="m">true</a>, <a id='1193' tid='1194', class="m">true</a>);
 596  }
 597  <span class="d">editor-&gt;Close();</span>
 598  <span class="d">printf(&quot;\n&quot;);</span>
 599}
 600
 601
 602<a id='1195' tid='1196', class="m">class</a> <a id='1197' tid='1198', class="m">ShellThread</a> : <a id='1199' tid='1200', class="m">public</a> <a id='1201' tid='1202', class="m">i</a><a id='1203' tid='1204', class="m">::</a><a id='1205' tid='1206', class="m">Thread</a> {
 603 <a id='1229' tid='1230', class="m">public</a>:
 604  <a id='1065' tid='1066', class="m">ShellThread</a>(<a id='1213' tid='1214', class="m">int</a> <a id='1215' tid='1216', class="m">no</a>, <a id='1217' tid='1218', class="m">i</a><a id='1219' tid='1220', class="m">::</a><a id='1221' tid='1222', class="m">Vector</a>&lt;<a id='1223' tid='1224', class="m">const</a> <a id='1225' tid='1226', class="m">char</a>&gt; <a id='1227' tid='1228', class="m">files</a>)
 605    : <span class="d">no_(no), files_(files)</span> <span class="d">{ }</span>
 606  <a id='1207' tid='1208', class="m">virtual</a> <a id='1209' tid='1210', class="m">void</a> <a id='1211' tid='1212', class="m">Run</a>();
 607 <a id='1231' tid='1232', class="m">private</a>:
 608  <a id='1233' tid='1234', class="m">int</a> <a id='1235' tid='1236', class="m">no_</a>;
 609  <a id='1237' tid='1238', class="m">i</a><a id='1239' tid='1240', class="m">::</a><a id='1241' tid='1242', class="m">Vector</a>&lt;<a id='1243' tid='1244', class="m">const</a> <a id='1245' tid='1246', class="m">char</a>&gt; <a id='1247' tid='1248', class="m">files_</a>;
 610};
 611
 612
 613<span class="d">void</span> <span class="d">ShellThread::Run</span><span class="d">()</span> {
 614  // Prepare the context for this thread.
 615  <span class="d">Locker locker;</span>
 616  <span class="d">HandleScope scope;</span>
 617  <a id='1923' tid='1924', class="m">Handle</a>&lt;<a id='1925' tid='1926', class="m">ObjectTemplate</a>&gt; <a id='1927' tid='1928', class="m">global_template</a> = <a id='1929' tid='1930', class="m">ObjectTemplate</a><a id='1931' tid='1932', class="m">::</a><a id='1933' tid='1934', class="m">New</a>();
 618  <span class="d">global_template-&gt;Set(String::New(&quot;print&quot;),
 619                       FunctionTemplate::New(Shell::Print));</span>
 620  <span class="d">global_template-&gt;Set(String::New(&quot;write&quot;),
 621                       FunctionTemplate::New(Shell::Write));</span>
 622  <span class="d">global_template-&gt;Set(String::New(&quot;read&quot;),
 623                       FunctionTemplate::New(Shell::Read));</span>
 624  <span class="d">global_template-&gt;Set(String::New(&quot;readline&quot;),
 625                       FunctionTemplate::New(Shell::ReadLine));</span>
 626  <span class="d">global_template-&gt;Set(String::New(&quot;load&quot;),
 627                       FunctionTemplate::New(Shell::Load));</span>
 628  <span class="d">global_template-&gt;Set(String::New(&quot;yield&quot;),
 629                       FunctionTemplate::New(Shell::Yield));</span>
 630  <span class="d">global_template-&gt;Set(String::New(&quot;version&quot;),
 631                       FunctionTemplate::New(Shell::Version));</span>
 632
 633  <a id='457' tid='458', class="m">char</a><a id='459' tid='460', class="m">*</a> <a id='461' tid='462', class="m">ptr</a> = <a id='463' tid='464', class="m">const_cast</a>&lt;<a id='465' tid='466', class="m">char</a><a id='467' tid='468', class="m">*</a>&gt;(<a id='469' tid='470', class="m">files_</a>.<a id='471' tid='472', class="m">start</a>());
 634  <a id='473' tid='474', class="m">while</a> ((<a id='575' tid='576', class="m">ptr</a> <a id='577' tid='578', class="m">!=</a> <a id='579' tid='580', class="m">NULL</a>) <a id='581' tid='582', class="m">&&</a> (<a id='583' tid='584', class="m">*</a><a id='585' tid='586', class="m">ptr</a> <a id='587' tid='588', class="m">!=</a> <a id='589' tid='590', class="m">&#39;\0&#39;</a>)) {
 635    // For each newline-separated line.
 636    <a id='329' tid='330', class="m">char</a><a id='331' tid='332', class="m">*</a> <a id='333' tid='334', class="m">next_line</a> = <a id='335' tid='336', class="m">ReadLine</a>(<a id='337' tid='338', class="m">ptr</a>);
 637
 638    <a id='295' tid='296', class="m">if</a> (<a id='297' tid='298', class="m">*</a><a id='299' tid='300', class="m">ptr</a> <a id='301' tid='302', class="m">==</a> <a id='303' tid='304', class="m">&#39;#&#39;</a>) {
 639      // Skip comment lines.
 640      <a id='305' tid='306', class="m">ptr</a> <a id='307' tid='308', class="m">=</a> <a id='309' tid='310', class="m">next_line</a>;
 641      <a id='311' tid='312', class="m">continue</a>;
 642    }
 643
 644    <span class="d">Persistent&lt;Context&gt; thread_context = Context::New(NULL, global_template);</span>
 645    <span class="d">thread_context-&gt;SetSecurityToken(Undefined());</span>
 646    <a id='275' tid='276', class="m">Context</a><a id='277' tid='278', class="m">::</a><a id='279' tid='280', class="m">Scope</a> <a id='281' tid='282', class="m">context_scope</a>(<a id='283' tid='284', class="m">thread_context</a>);
 647
 648    <a id='339' tid='340', class="m">while</a> ((<a id='475' tid='476', class="m">ptr</a> <a id='477' tid='478', class="m">!=</a> <a id='479' tid='480', class="m">NULL</a>) <a id='481' tid='482', class="m">&&</a> (<a id='483' tid='484', class="m">*</a><a id='485' tid='486', class="m">ptr</a> <a id='487' tid='488', class="m">!=</a> <a id='489' tid='490', class="m">&#39;\0&#39;</a>)) {
 649      <a id='341' tid='342', class="m">char</a><a id='343' tid='344', class="m">*</a> <a id='345' tid='346', class="m">filename</a> = <a id='347' tid='348', class="m">ptr</a>;
 650      <a id='349' tid='350', class="m">ptr</a> <a id='351' tid='352', class="m">=</a> <a id='353' tid='354', class="m">ReadWord</a>(<a id='355' tid='356', class="m">ptr</a>);
 651
 652      // Skip empty strings.
 653      <a id='357' tid='358', class="m">if</a> (<a id='359' tid='360', class="m">strlen</a>(<a id='361' tid='362', class="m">filename</a>) <a id='363' tid='364', class="m">==</a> <a id='365' tid='366', class="m">0</a>) {
 654        <a id='367' tid='368', class="m">break</a>;
 655      }
 656
 657      <a id='369' tid='370', class="m">Handle</a>&lt;<a id='371' tid='372', class="m">String</a>&gt; <a id='373' tid='374', class="m">str</a> = <a id='375' tid='376', class="m">Shell</a><a id='377' tid='378', class="m">::</a><a id='379' tid='380', class="m">ReadFile</a>(<a id='381' tid='382', class="m">filename</a>);
 658      <a id='383' tid='384', class="m">if</a> (<a id='385' tid='386', class="m">str</a>.<a id='387' tid='388', class="m">IsEmpty</a>()) {
 659        <a id='389' tid='390', class="m">printf</a>(<a id='391' tid='392', class="m">&quot;WARNING: %s not found\n&quot;</a>, <a id='393' tid='394', class="m">filename</a>);
 660        <a id='395' tid='396', class="m">break</a>;
 661      }
 662
 663      <a id='397' tid='398', class="m">Shell</a><a id='399' tid='400', class="m">::</a><a id='401' tid='402', class="m">ExecuteString</a>(<a id='403' tid='404', class="m">str</a>, <a id='405' tid='406', class="m">String</a><a id='407' tid='408', class="m">::</a><a id='409' tid='410', class="m">New</a>(<a id='411' tid='412', class="m">filename</a>), <a id='413' tid='414', class="m">false</a>, <a id='415' tid='416', class="m">false</a>);
 664    }
 665
 666    <span class="d">thread_context.Dispose();</span>
 667    <span class="d">ptr = next_line;</span>
 668  }
 669}
 670
 671
 672<span class="d">int</span> <span class="d">Shell::Main</span><span class="d">(int argc, char* argv[])</span> {
 673  <span class="d">i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);</span>
 674  <span class="d">if (i::FLAG_help) {
 675    return 1;
 676  }</span>
 677  <span class="d">Initialize();</span>
 678  <span class="d">bool run_shell = (argc == 1);</span>
 679
 680  // Default use preemption if threads are created.
 681  <span class="d">bool use_preemption = true;</span>
 682
 683  // Default to use lowest possible thread preemption interval to test as many
 684  // edgecases as possible.
 685  <span class="d">int preemption_interval = 1;</span>
 686
 687  <a id='1067' tid='1068', class="m">i</a><a id='1069' tid='1070', class="m">::</a><a id='1071' tid='1072', class="m">List</a>&lt;<a id='1073' tid='1074', class="m">i</a><a id='1075' tid='1076', class="m">::</a><a id='1077' tid='1078', class="m">Thread</a><a id='1079' tid='1080', class="m">*</a>&gt; <a id='1081' tid='1082', class="m">threads</a>(<a id='1083' tid='1084', class="m">1</a>);
 688
 689  {
 690    // Acquire the V8 lock once initialization has finished. Since the thread
 691    // below may spawn new threads accessing V8 holding the V8 lock here is
 692    // mandatory.
 693    <span class="d">Locker locker;</span>
 694    <a id='1055' tid='1056', class="m">Context</a><a id='1057' tid='1058', class="m">::</a><a id='1059' tid='1060', class="m">Scope</a> <a id='1061' tid='1062', class="m">context_scope</a>(<a id='1063' tid='1064', class="m">evaluation_context_</a>);
 695    <a id='1005' tid='1006', class="m">for</a> (<a id='1007' tid='1008', class="m">int</a> <a id='1009' tid='1010', class="m">i</a> = <a id='1011' tid='1012', class="m">1</a>; <a id='1013' tid='1014', class="m">i</a> <a id='1015' tid='1016', class="m">&lt;</a> <a id='1017' tid='1018', class="m">argc</a>; <a id='1019' tid='1020', class="m">i</a><a id='1021' tid='1022', class="m">++</a>) {
 696      <a id='1023' tid='1024', class="m">char</a><a id='1025' tid='1026', class="m">*</a> <a id='1027' tid='1028', class="m">str</a> = <a id='1029' tid='1030', class="m">argv</a>[<a id='1031' tid='1032', class="m">i</a>];
 697      <span class="d">if</span> <span class="d">(strcmp(str, &quot;--shell&quot;) == 0)</span> <span class="d">{
 698        run_shell = true;
 699      }</span> <span class="d">else</span> <a id='669' tid='670', class="m">if</a> (<a id='1033' tid='1034', class="m">strcmp</a>(<a id='1035' tid='1036', class="m">str</a>, <a id='1037' tid='1038', class="m">&quot;--preemption&quot;</a>) <a id='1039' tid='1040', class="m">==</a> <a id='1041' tid='1042', class="m">0</a>) {
 700        <a id='671' tid='672', class="m">use_preemption</a> <a id='673' tid='674', class="m">=</a> <a id='675' tid='676', class="m">true</a>;
 701      } <a id='677' tid='678', class="m">else</a> <a id='679' tid='680', class="m">if</a> (<a id='681' tid='682', class="m">strcmp</a>(<a id='683' tid='684', class="m">str</a>, <a id='685' tid='686', class="m">&quot;--no-preemption&quot;</a>) <a id='687' tid='688', class="m">==</a> <a id='689' tid='690', class="m">0</a>) {
 702        <a id='691' tid='692', class="m">use_preemption</a> <a id='693' tid='694', class="m">=</a> <a id='695' tid='696', class="m">false</a>;
 703      } <a id='697' tid='698', class="m">else</a> <a id='699' tid='700', class="m">if</a> (<a id='701' tid='702', class="m">strcmp</a>(<a id='703' tid='704', class="m">str</a>, <a id='705' tid='706', class="m">&quot;--preemption-interval&quot;</a>) <a id='707' tid='708', class="m">==</a> <a id='709' tid='710', class="m">0</a>) {
 704        <a id='711' tid='712', class="m">if</a> (<a id='713' tid='714', class="m">i</a> <a id='715' tid='716', class="m">+</a> <a id='717' tid='718', class="m">1</a> <a id='719' tid='720', class="m">&lt;</a> <a id='721' tid='722', class="m">argc</a>) {
 705          <a id='723' tid='724', class="m">char</a><a id='725' tid='726', class="m">*</a> <a id='727' tid='728', class="m">end</a> = <a id='729' tid='730', class="m">NULL</a>;
 706          <a id='731' tid='732', class="m">preemption_interval</a> <a id='733' tid='734', class="m">=</a> <a id='735' tid='736', class="m">strtol</a>(<a id='737' tid='738', class="m">argv</a>[<a id='739' tid='740', class="m">++</a><a id='741' tid='742', class="m">i</a>], <a id='743' tid='744', class="m">&</a><a id='745' tid='746', class="m">end</a>, <a id='747' tid='748', class="m">10</a>);  // NOLINT
 707          <a id='749' tid='750', class="m">if</a> (<a id='751' tid='752', class="m">preemption_interval</a> <a id='753' tid='754', class="m">&lt;=</a> <a id='755' tid='756', class="m">0</a> <a id='757' tid='758', class="m">||</a> <a id='759' tid='760', class="m">*</a><a id='761' tid='762', class="m">end</a> <a id='763' tid='764', class="m">!=<