| 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/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/string-builder.h" | 10 #include "src/string-builder.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 base::SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( | 135 base::SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( |
| 136 Isolate* isolate, Handle<Object> data) { | 136 Isolate* isolate, Handle<Object> data) { |
| 137 HandleScope scope(isolate); | 137 HandleScope scope(isolate); |
| 138 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); | 138 return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS); |
| 139 } | 139 } |
| 140 | 140 |
| 141 | 141 |
| 142 Handle<Object> CallSite::GetFileName(Isolate* isolate) { | 142 CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj) |
| 143 Handle<Object> script(fun_->shared()->script(), isolate); | 143 : isolate_(isolate) { |
| 144 if (script->IsScript()) { | 144 receiver_ = JSObject::GetDataProperty( |
| 145 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate); | 145 call_site_obj, isolate->factory()->call_site_receiver_symbol()); |
| 146 } | 146 fun_ = Handle<JSFunction>::cast(JSObject::GetDataProperty( |
| 147 return isolate->factory()->null_value(); | 147 call_site_obj, isolate->factory()->call_site_function_symbol())); |
| 148 pos_ = Handle<Smi>::cast(JSObject::GetDataProperty( |
| 149 call_site_obj, |
| 150 isolate->factory()->call_site_position_symbol())) |
| 151 ->value(); |
| 148 } | 152 } |
| 149 | 153 |
| 150 | 154 |
| 151 Handle<Object> CallSite::GetFunctionName(Isolate* isolate) { | 155 Handle<Object> CallSite::GetFileName() { |
| 156 Handle<Object> script(fun_->shared()->script(), isolate_); |
| 157 if (script->IsScript()) { |
| 158 return Handle<Object>(Handle<Script>::cast(script)->name(), isolate_); |
| 159 } |
| 160 return isolate_->factory()->null_value(); |
| 161 } |
| 162 |
| 163 |
| 164 Handle<Object> CallSite::GetFunctionName() { |
| 152 Handle<String> result = JSFunction::GetDebugName(fun_); | 165 Handle<String> result = JSFunction::GetDebugName(fun_); |
| 153 if (result->length() != 0) return result; | 166 if (result->length() != 0) return result; |
| 154 Handle<Object> script(fun_->shared()->script(), isolate); | 167 Handle<Object> script(fun_->shared()->script(), isolate_); |
| 155 if (script->IsScript() && | 168 if (script->IsScript() && |
| 156 Handle<Script>::cast(script)->compilation_type() == | 169 Handle<Script>::cast(script)->compilation_type() == |
| 157 Script::COMPILATION_TYPE_EVAL) { | 170 Script::COMPILATION_TYPE_EVAL) { |
| 158 return isolate->factory()->eval_string(); | 171 return isolate_->factory()->eval_string(); |
| 159 } | 172 } |
| 160 return isolate->factory()->null_value(); | 173 return isolate_->factory()->null_value(); |
| 161 } | 174 } |
| 162 | 175 |
| 163 | 176 |
| 164 Handle<Object> CallSite::GetScriptNameOrSourceUrl(Isolate* isolate) { | 177 Handle<Object> CallSite::GetScriptNameOrSourceUrl() { |
| 165 Handle<Object> script_obj(fun_->shared()->script(), isolate); | 178 Handle<Object> script_obj(fun_->shared()->script(), isolate_); |
| 166 if (script_obj->IsScript()) { | 179 if (script_obj->IsScript()) { |
| 167 Handle<Script> script = Handle<Script>::cast(script_obj); | 180 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 168 Object* source_url = script->source_url(); | 181 Object* source_url = script->source_url(); |
| 169 if (source_url->IsString()) return Handle<Object>(source_url, isolate); | 182 if (source_url->IsString()) return Handle<Object>(source_url, isolate_); |
| 170 return Handle<Object>(script->name(), isolate); | 183 return Handle<Object>(script->name(), isolate_); |
| 171 } | 184 } |
| 172 return isolate->factory()->null_value(); | 185 return isolate_->factory()->null_value(); |
| 173 } | 186 } |
| 174 | 187 |
| 175 | 188 |
| 176 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, | 189 bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, |
| 177 Handle<JSFunction> fun, | 190 Handle<JSFunction> fun, |
| 178 LookupIterator::Configuration config) { | 191 LookupIterator::Configuration config) { |
| 179 LookupIterator iter = | 192 LookupIterator iter = |
| 180 LookupIterator::PropertyOrElement(isolate, obj, name, config); | 193 LookupIterator::PropertyOrElement(isolate, obj, name, config); |
| 181 if (iter.state() == LookupIterator::DATA) { | 194 if (iter.state() == LookupIterator::DATA) { |
| 182 return iter.GetDataValue().is_identical_to(fun); | 195 return iter.GetDataValue().is_identical_to(fun); |
| 183 } else if (iter.state() == LookupIterator::ACCESSOR) { | 196 } else if (iter.state() == LookupIterator::ACCESSOR) { |
| 184 Handle<Object> accessors = iter.GetAccessors(); | 197 Handle<Object> accessors = iter.GetAccessors(); |
| 185 if (accessors->IsAccessorPair()) { | 198 if (accessors->IsAccessorPair()) { |
| 186 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); | 199 Handle<AccessorPair> pair = Handle<AccessorPair>::cast(accessors); |
| 187 return pair->getter() == *fun || pair->setter() == *fun; | 200 return pair->getter() == *fun || pair->setter() == *fun; |
| 188 } | 201 } |
| 189 } | 202 } |
| 190 return false; | 203 return false; |
| 191 } | 204 } |
| 192 | 205 |
| 193 | 206 |
| 194 Handle<Object> CallSite::GetMethodName(Isolate* isolate) { | 207 Handle<Object> CallSite::GetMethodName() { |
| 195 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate, receiver_); | 208 MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate_, receiver_); |
| 196 Handle<JSReceiver> receiver; | 209 Handle<JSReceiver> receiver; |
| 197 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { | 210 if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { |
| 198 return isolate->factory()->null_value(); | 211 return isolate_->factory()->null_value(); |
| 199 } | 212 } |
| 200 | 213 |
| 201 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); | 214 Handle<JSObject> obj = Handle<JSObject>::cast(receiver); |
| 202 Handle<Object> function_name(fun_->shared()->name(), isolate); | 215 Handle<Object> function_name(fun_->shared()->name(), isolate_); |
| 203 if (function_name->IsName()) { | 216 if (function_name->IsName()) { |
| 204 Handle<Name> name = Handle<Name>::cast(function_name); | 217 Handle<Name> name = Handle<Name>::cast(function_name); |
| 205 if (CheckMethodName(isolate, obj, name, fun_, | 218 if (CheckMethodName(isolate_, obj, name, fun_, |
| 206 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) | 219 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) |
| 207 return name; | 220 return name; |
| 208 } | 221 } |
| 209 | 222 |
| 210 HandleScope outer_scope(isolate); | 223 HandleScope outer_scope(isolate_); |
| 211 Handle<Object> result; | 224 Handle<Object> result; |
| 212 for (PrototypeIterator iter(isolate, obj, | 225 for (PrototypeIterator iter(isolate_, obj, |
| 213 PrototypeIterator::START_AT_RECEIVER); | 226 PrototypeIterator::START_AT_RECEIVER); |
| 214 !iter.IsAtEnd(); iter.Advance()) { | 227 !iter.IsAtEnd(); iter.Advance()) { |
| 215 Handle<Object> current = PrototypeIterator::GetCurrent(iter); | 228 Handle<Object> current = PrototypeIterator::GetCurrent(iter); |
| 216 if (!current->IsJSObject()) break; | 229 if (!current->IsJSObject()) break; |
| 217 Handle<JSObject> current_obj = Handle<JSObject>::cast(current); | 230 Handle<JSObject> current_obj = Handle<JSObject>::cast(current); |
| 218 if (current_obj->IsAccessCheckNeeded()) break; | 231 if (current_obj->IsAccessCheckNeeded()) break; |
| 219 Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false); | 232 Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false); |
| 220 for (int i = 0; i < keys->length(); i++) { | 233 for (int i = 0; i < keys->length(); i++) { |
| 221 HandleScope inner_scope(isolate); | 234 HandleScope inner_scope(isolate_); |
| 222 if (!keys->get(i)->IsName()) continue; | 235 if (!keys->get(i)->IsName()) continue; |
| 223 Handle<Name> name_key(Name::cast(keys->get(i)), isolate); | 236 Handle<Name> name_key(Name::cast(keys->get(i)), isolate_); |
| 224 if (!CheckMethodName(isolate, current_obj, name_key, fun_, | 237 if (!CheckMethodName(isolate_, current_obj, name_key, fun_, |
| 225 LookupIterator::OWN_SKIP_INTERCEPTOR)) | 238 LookupIterator::OWN_SKIP_INTERCEPTOR)) |
| 226 continue; | 239 continue; |
| 227 // Return null in case of duplicates to avoid confusion. | 240 // Return null in case of duplicates to avoid confusion. |
| 228 if (!result.is_null()) return isolate->factory()->null_value(); | 241 if (!result.is_null()) return isolate_->factory()->null_value(); |
| 229 result = inner_scope.CloseAndEscape(name_key); | 242 result = inner_scope.CloseAndEscape(name_key); |
| 230 } | 243 } |
| 231 } | 244 } |
| 232 | 245 |
| 233 if (!result.is_null()) return outer_scope.CloseAndEscape(result); | 246 if (!result.is_null()) return outer_scope.CloseAndEscape(result); |
| 234 return isolate->factory()->null_value(); | 247 return isolate_->factory()->null_value(); |
| 235 } | 248 } |
| 236 | 249 |
| 237 | 250 |
| 238 int CallSite::GetLineNumber(Isolate* isolate) { | 251 int CallSite::GetLineNumber() { |
| 239 if (pos_ >= 0) { | 252 if (pos_ >= 0) { |
| 240 Handle<Object> script_obj(fun_->shared()->script(), isolate); | 253 Handle<Object> script_obj(fun_->shared()->script(), isolate_); |
| 241 if (script_obj->IsScript()) { | 254 if (script_obj->IsScript()) { |
| 242 Handle<Script> script = Handle<Script>::cast(script_obj); | 255 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 243 return Script::GetLineNumber(script, pos_) + 1; | 256 return Script::GetLineNumber(script, pos_) + 1; |
| 244 } | 257 } |
| 245 } | 258 } |
| 246 return -1; | 259 return -1; |
| 247 } | 260 } |
| 248 | 261 |
| 249 | 262 |
| 250 int CallSite::GetColumnNumber(Isolate* isolate) { | 263 int CallSite::GetColumnNumber() { |
| 251 if (pos_ >= 0) { | 264 if (pos_ >= 0) { |
| 252 Handle<Object> script_obj(fun_->shared()->script(), isolate); | 265 Handle<Object> script_obj(fun_->shared()->script(), isolate_); |
| 253 if (script_obj->IsScript()) { | 266 if (script_obj->IsScript()) { |
| 254 Handle<Script> script = Handle<Script>::cast(script_obj); | 267 Handle<Script> script = Handle<Script>::cast(script_obj); |
| 255 return Script::GetColumnNumber(script, pos_) + 1; | 268 return Script::GetColumnNumber(script, pos_) + 1; |
| 256 } | 269 } |
| 257 } | 270 } |
| 258 return -1; | 271 return -1; |
| 259 } | 272 } |
| 260 | 273 |
| 261 | 274 |
| 262 bool CallSite::IsNative(Isolate* isolate) { | 275 bool CallSite::IsNative() { |
| 263 Handle<Object> script(fun_->shared()->script(), isolate); | 276 Handle<Object> script(fun_->shared()->script(), isolate_); |
| 264 return script->IsScript() && | 277 return script->IsScript() && |
| 265 Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE; | 278 Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE; |
| 266 } | 279 } |
| 267 | 280 |
| 268 | 281 |
| 269 bool CallSite::IsToplevel(Isolate* isolate) { | 282 bool CallSite::IsToplevel() { |
| 270 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || | 283 return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || |
| 271 receiver_->IsUndefined(); | 284 receiver_->IsUndefined(); |
| 272 } | 285 } |
| 273 | 286 |
| 274 | 287 |
| 275 bool CallSite::IsEval(Isolate* isolate) { | 288 bool CallSite::IsEval() { |
| 276 Handle<Object> script(fun_->shared()->script(), isolate); | 289 Handle<Object> script(fun_->shared()->script(), isolate_); |
| 277 return script->IsScript() && | 290 return script->IsScript() && |
| 278 Handle<Script>::cast(script)->compilation_type() == | 291 Handle<Script>::cast(script)->compilation_type() == |
| 279 Script::COMPILATION_TYPE_EVAL; | 292 Script::COMPILATION_TYPE_EVAL; |
| 280 } | 293 } |
| 281 | 294 |
| 282 | 295 |
| 283 bool CallSite::IsConstructor(Isolate* isolate) { | 296 bool CallSite::IsConstructor() { |
| 284 if (!receiver_->IsJSObject()) return false; | 297 if (!receiver_->IsJSObject()) return false; |
| 285 Handle<Object> constructor = | 298 Handle<Object> constructor = |
| 286 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), | 299 JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), |
| 287 isolate->factory()->constructor_string()); | 300 isolate_->factory()->constructor_string()); |
| 288 return constructor.is_identical_to(fun_); | 301 return constructor.is_identical_to(fun_); |
| 289 } | 302 } |
| 290 | 303 |
| 291 | 304 |
| 292 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, | 305 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, |
| 293 int template_index, | 306 int template_index, |
| 294 Handle<Object> arg) { | 307 Handle<Object> arg) { |
| 295 Factory* factory = isolate->factory(); | 308 Factory* factory = isolate->factory(); |
| 296 Handle<String> result_string; | 309 Handle<String> result_string; |
| 297 if (arg->IsString()) { | 310 if (arg->IsString()) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 if (obj->IsUndefined()) return default_value; | 469 if (obj->IsUndefined()) return default_value; |
| 457 if (!obj->IsString()) { | 470 if (!obj->IsString()) { |
| 458 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Execution::ToString(isolate, obj), | 471 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Execution::ToString(isolate, obj), |
| 459 String); | 472 String); |
| 460 } | 473 } |
| 461 return Handle<String>::cast(obj); | 474 return Handle<String>::cast(obj); |
| 462 } | 475 } |
| 463 | 476 |
| 464 } // namespace internal | 477 } // namespace internal |
| 465 } // namespace v8 | 478 } // namespace v8 |
| OLD | NEW |