OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/execution.h" | 8 #include "src/execution.h" |
9 #include "src/heap/spaces-inl.h" | 9 #include "src/heap/spaces-inl.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 | 157 |
158 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( | 158 SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( |
159 Isolate* isolate, | 159 Isolate* isolate, |
160 Handle<Object> data) { | 160 Handle<Object> data) { |
161 HandleScope scope(isolate); | 161 HandleScope scope(isolate); |
162 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); | 162 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); |
163 } | 163 } |
164 | 164 |
165 | 165 |
| 166 Handle<Object> CallSite::GetFileName(Isolate* isolate) { |
| 167 Handle<Object> script(fun_->shared()->script(), isolate); |
| 168 if (script->IsScript()) { |
| 169 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate); |
| 170 } |
| 171 return isolate->factory()->null_value(); |
| 172 } |
| 173 |
| 174 |
| 175 Handle<Object> CallSite::GetFunctionName(Isolate* isolate) { |
| 176 Handle<String> result = JSFunction::GetDebugName(fun_); |
| 177 if (result->length() != 0) return result; |
| 178 Handle<Object> script(fun_->shared()->script(), isolate); |
| 179 if (script->IsScript() && |
| 180 Handle<Script>::cast(script)->compilation_type() == |
| 181 Script::COMPILATION_TYPE_EVAL) { |
| 182 return isolate->factory()->eval_string(); |
| 183 } |
| 184 return isolate->factory()->null_value(); |
| 185 } |
| 186 |
| 187 |
| 188 Handle<Object> CallSite::GetScriptNameOrSourceUrl(Isolate* isolate) { |
| 189 Handle<Object> script_obj(fun_->shared()->script(), isolate); |
| 190 if (script_obj->IsScript()) { |
| 191 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 192 Object* source_url = script->source_url(); |
| 193 if (source_url->IsString()) return Handle<Object>(source_url, isolate); |
| 194 return Handle<Object>(script->name(), isolate); |
| 195 } |
| 196 return isolate->factory()->null_value(); |
| 197 } |
| 198 |
| 199 |
| 200 int CallSite::GetLineNumber(Isolate* isolate) { |
| 201 if (pos_ >= 0) { |
| 202 Handle<Object> script_obj(fun_->shared()->script(), isolate); |
| 203 if (script_obj->IsScript()) { |
| 204 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 205 return Script::GetLineNumber(script, pos_) + 1; |
| 206 } |
| 207 } |
| 208 return -1; |
| 209 } |
| 210 |
| 211 |
| 212 int CallSite::GetColumnNumber(Isolate* isolate) { |
| 213 if (pos_ >= 0) { |
| 214 Handle<Object> script_obj(fun_->shared()->script(), isolate); |
| 215 if (script_obj->IsScript()) { |
| 216 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 217 return Script::GetColumnNumber(script, pos_) + 1; |
| 218 } |
| 219 } |
| 220 return -1; |
| 221 } |
| 222 |
| 223 |
| 224 bool CallSite::IsNative(Isolate* isolate) { |
| 225 Handle<Object> script(fun_->shared()->script(), isolate); |
| 226 return script->IsScript() && |
| 227 Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE; |
| 228 } |
| 229 |
| 230 |
| 231 bool CallSite::IsToplevel(Isolate* isolate) { |
| 232 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || |
| 233 receiver_->IsUndefined(); |
| 234 } |
| 235 |
| 236 |
| 237 bool CallSite::IsEval(Isolate* isolate) { |
| 238 Handle<Object> script(fun_->shared()->script(), isolate); |
| 239 return script->IsScript() && |
| 240 Handle<Script>::cast(script)->compilation_type() == |
| 241 Script::COMPILATION_TYPE_EVAL; |
| 242 } |
| 243 |
| 244 |
166 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, | 245 MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, |
167 Handle<String> arg0, | 246 Handle<String> arg0, |
168 Handle<String> arg1, | 247 Handle<String> arg1, |
169 Handle<String> arg2) { | 248 Handle<String> arg2) { |
170 const char* template_string; | 249 const char* template_string; |
171 switch (template_index) { | 250 switch (template_index) { |
172 #define CASE(NAME, STRING) \ | 251 #define CASE(NAME, STRING) \ |
173 case k##NAME: \ | 252 case k##NAME: \ |
174 template_string = STRING; \ | 253 template_string = STRING; \ |
175 break; | 254 break; |
(...skipping 16 matching lines...) Expand all Loading... |
192 DCHECK(i < arraysize(args)); | 271 DCHECK(i < arraysize(args)); |
193 builder.AppendString(args[i++]); | 272 builder.AppendString(args[i++]); |
194 } else { | 273 } else { |
195 builder.AppendCharacter(*c); | 274 builder.AppendCharacter(*c); |
196 } | 275 } |
197 } | 276 } |
198 | 277 |
199 return builder.Finish(); | 278 return builder.Finish(); |
200 } | 279 } |
201 } } // namespace v8::internal | 280 } } // namespace v8::internal |
OLD | NEW |