PageRenderTime 1273ms CodeModel.GetById 32ms app.highlight 46ms 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

Large files files are truncated, but you can click here to view the full 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…

Large files files are truncated, but you can click here to view the full file