Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: src/api.cc

Issue 106763002: Get information about original function from bound function (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #define API_ENTRY_CHECK(isolate, msg) \ 121 #define API_ENTRY_CHECK(isolate, msg) \
122 do { \ 122 do { \
123 if (v8::Locker::IsActive()) { \ 123 if (v8::Locker::IsActive()) { \
124 ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ 124 ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \
125 msg, \ 125 msg, \
126 "Entering the V8 API without proper locking in place"); \ 126 "Entering the V8 API without proper locking in place"); \
127 } \ 127 } \
128 } while (false) 128 } while (false)
129 129
130 130
131 static i::Handle<i::JSFunction> GetOriginalFunctionFromBound(
132 i::Handle<i::JSFunction> bound_function) {
133 i::Handle<i::FixedArray> bound_args = i::Handle<i::FixedArray>(
134 i::FixedArray::cast(bound_function->function_bindings()));
135 i::Handle<i::Object> orig_function(
136 i::JSReceiver::cast(bound_args->get(
137 i::JSFunction::kBoundFunctionIndex)),
138 i::Isolate::Current());
139 return i::Handle<i::JSFunction>::cast(orig_function);
140 }
141
142
131 // --- E x c e p t i o n B e h a v i o r --- 143 // --- E x c e p t i o n B e h a v i o r ---
132 144
133 145
134 static void DefaultFatalErrorHandler(const char* location, 146 static void DefaultFatalErrorHandler(const char* location,
135 const char* message) { 147 const char* message) {
136 i::Isolate* isolate = i::Isolate::Current(); 148 i::Isolate* isolate = i::Isolate::Current();
137 if (isolate->IsInitialized()) { 149 if (isolate->IsInitialized()) {
138 i::VMState<i::OTHER> state(isolate); 150 i::VMState<i::OTHER> state(isolate);
139 API_Fatal(location, message); 151 API_Fatal(location, message);
140 } else { 152 } else {
(...skipping 4059 matching lines...) Expand 10 before | Expand all | Expand 10 after
4200 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4212 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4201 ENTER_V8(isolate); 4213 ENTER_V8(isolate);
4202 USE(isolate); 4214 USE(isolate);
4203 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4215 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4204 func->shared()->set_name(*Utils::OpenHandle(*name)); 4216 func->shared()->set_name(*Utils::OpenHandle(*name));
4205 } 4217 }
4206 4218
4207 4219
4208 Handle<Value> Function::GetName() const { 4220 Handle<Value> Function::GetName() const {
4209 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4221 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4222 if (func->shared()->bound()) {
yurys 2013/12/09 12:17:16 We should add Function::GetBoundFunction() instead
Alexandra Mikhaylova 2013/12/12 12:41:14 Done.
4223 func = GetOriginalFunctionFromBound(func);
4224 }
4210 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(), 4225 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->name(),
4211 func->GetIsolate())); 4226 func->GetIsolate()));
4212 } 4227 }
4213 4228
4214 4229
4215 Handle<Value> Function::GetInferredName() const { 4230 Handle<Value> Function::GetInferredName() const {
4216 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4231 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4232 if (func->shared()->bound()) {
4233 func = GetOriginalFunctionFromBound(func);
4234 }
4217 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(), 4235 return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(),
4218 func->GetIsolate())); 4236 func->GetIsolate()));
4219 } 4237 }
4220 4238
4221 4239
4222 Handle<Value> Function::GetDisplayName() const { 4240 Handle<Value> Function::GetDisplayName() const {
4223 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 4241 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
4224 ON_BAILOUT(isolate, "v8::Function::GetDisplayName()", 4242 ON_BAILOUT(isolate, "v8::Function::GetDisplayName()",
4225 return ToApiHandle<Primitive>( 4243 return ToApiHandle<Primitive>(
4226 isolate->factory()->undefined_value())); 4244 isolate->factory()->undefined_value()));
4227 ENTER_V8(isolate); 4245 ENTER_V8(isolate);
4228 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4246 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4247 if (func->shared()->bound()) {
4248 func = GetOriginalFunctionFromBound(func);
4249 }
4229 i::Handle<i::String> property_name = 4250 i::Handle<i::String> property_name =
4230 isolate->factory()->InternalizeOneByteString( 4251 isolate->factory()->InternalizeOneByteString(
4231 STATIC_ASCII_VECTOR("displayName")); 4252 STATIC_ASCII_VECTOR("displayName"));
4232 i::LookupResult lookup(isolate); 4253 i::LookupResult lookup(isolate);
4233 func->LookupRealNamedProperty(*property_name, &lookup); 4254 func->LookupRealNamedProperty(*property_name, &lookup);
4234 if (lookup.IsFound()) { 4255 if (lookup.IsFound()) {
4235 i::Object* value = lookup.GetLazyValue(); 4256 i::Object* value = lookup.GetLazyValue();
4236 if (value && value->IsString()) { 4257 if (value && value->IsString()) {
4237 i::String* name = i::String::cast(value); 4258 i::String* name = i::String::cast(value);
4238 if (name->length() > 0) return Utils::ToLocal(i::Handle<i::String>(name)); 4259 if (name->length() > 0) return Utils::ToLocal(i::Handle<i::String>(name));
4239 } 4260 }
4240 } 4261 }
4241 return ToApiHandle<Primitive>(isolate->factory()->undefined_value()); 4262 return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
4242 } 4263 }
4243 4264
4244 4265
4245 ScriptOrigin Function::GetScriptOrigin() const { 4266 ScriptOrigin Function::GetScriptOrigin() const {
4246 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4267 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4268 if (func->shared()->bound()) {
4269 func = GetOriginalFunctionFromBound(func);
4270 }
4247 if (func->shared()->script()->IsScript()) { 4271 if (func->shared()->script()->IsScript()) {
4248 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4272 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4249 i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script); 4273 i::Handle<i::Object> scriptName = GetScriptNameOrSourceURL(script);
4250 v8::ScriptOrigin origin( 4274 v8::ScriptOrigin origin(
4251 Utils::ToLocal(scriptName), 4275 Utils::ToLocal(scriptName),
4252 v8::Integer::New(script->line_offset()->value()), 4276 v8::Integer::New(script->line_offset()->value()),
4253 v8::Integer::New(script->column_offset()->value())); 4277 v8::Integer::New(script->column_offset()->value()));
4254 return origin; 4278 return origin;
4255 } 4279 }
4256 return v8::ScriptOrigin(Handle<Value>()); 4280 return v8::ScriptOrigin(Handle<Value>());
4257 } 4281 }
4258 4282
4259 4283
4260 const int Function::kLineOffsetNotFound = -1; 4284 const int Function::kLineOffsetNotFound = -1;
4261 4285
4262 4286
4263 int Function::GetScriptLineNumber() const { 4287 int Function::GetScriptLineNumber() const {
4264 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4288 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4289 if (func->shared()->bound()) {
4290 func = GetOriginalFunctionFromBound(func);
4291 }
4265 if (func->shared()->script()->IsScript()) { 4292 if (func->shared()->script()->IsScript()) {
4266 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4293 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4267 return i::GetScriptLineNumber(script, func->shared()->start_position()); 4294 return i::GetScriptLineNumber(script, func->shared()->start_position());
4268 } 4295 }
4269 return kLineOffsetNotFound; 4296 return kLineOffsetNotFound;
4270 } 4297 }
4271 4298
4272 4299
4273 int Function::GetScriptColumnNumber() const { 4300 int Function::GetScriptColumnNumber() const {
4274 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4301 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4302 if (func->shared()->bound()) {
4303 func = GetOriginalFunctionFromBound(func);
4304 }
4275 if (func->shared()->script()->IsScript()) { 4305 if (func->shared()->script()->IsScript()) {
4276 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4306 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4277 return i::GetScriptColumnNumber(script, func->shared()->start_position()); 4307 return i::GetScriptColumnNumber(script, func->shared()->start_position());
4278 } 4308 }
4279 return kLineOffsetNotFound; 4309 return kLineOffsetNotFound;
4280 } 4310 }
4281 4311
4282 4312
4283 bool Function::IsBuiltin() const { 4313 bool Function::IsBuiltin() const {
4284 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4314 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4285 return func->IsBuiltin(); 4315 return func->IsBuiltin();
4286 } 4316 }
4287 4317
4288 4318
4289 Handle<Value> Function::GetScriptId() const { 4319 Handle<Value> Function::GetScriptId() const {
4290 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4320 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4291 i::Isolate* isolate = func->GetIsolate(); 4321 i::Isolate* isolate = func->GetIsolate();
4292 if (!func->shared()->script()->IsScript()) { 4322 if (!func->shared()->script()->IsScript()) {
4293 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 4323 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
4294 } 4324 }
4295 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4325 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4296 return Utils::ToLocal(i::Handle<i::Object>(script->id(), isolate)); 4326 return Utils::ToLocal(i::Handle<i::Object>(script->id(), isolate));
4297 } 4327 }
4298 4328
4299 4329
4300 int Function::ScriptId() const { 4330 int Function::ScriptId() const {
4301 i::Handle<i::JSFunction> func = Utils::OpenHandle(this); 4331 i::Handle<i::JSFunction> func = Utils::OpenHandle(this);
4332 if (func->shared()->bound()) {
4333 func = GetOriginalFunctionFromBound(func);
4334 }
4302 if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId; 4335 if (!func->shared()->script()->IsScript()) return v8::Script::kNoScriptId;
4303 i::Handle<i::Script> script(i::Script::cast(func->shared()->script())); 4336 i::Handle<i::Script> script(i::Script::cast(func->shared()->script()));
4304 return script->id()->value(); 4337 return script->id()->value();
4305 } 4338 }
4306 4339
4307 4340
4308 int String::Length() const { 4341 int String::Length() const {
4309 i::Handle<i::String> str = Utils::OpenHandle(this); 4342 i::Handle<i::String> str = Utils::OpenHandle(this);
4310 return str->length(); 4343 return str->length();
4311 } 4344 }
(...skipping 3468 matching lines...) Expand 10 before | Expand all | Expand 10 after
7780 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7813 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7781 Address callback_address = 7814 Address callback_address =
7782 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7815 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7783 VMState<EXTERNAL> state(isolate); 7816 VMState<EXTERNAL> state(isolate);
7784 ExternalCallbackScope call_scope(isolate, callback_address); 7817 ExternalCallbackScope call_scope(isolate, callback_address);
7785 callback(info); 7818 callback(info);
7786 } 7819 }
7787 7820
7788 7821
7789 } } // namespace v8::internal 7822 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698