Code* code = NULL;
if (IsConstructor()) accumulator->Add("new ");
accumulator->PrintFunction(function, receiver, &code);
+
+ if (function->IsJSFunction()) {
+ Handle<SharedFunctionInfo> shared(JSFunction::cast(function)->shared());
+ Object* script_obj = shared->script();
+ if (script_obj->IsScript()) {
+ Handle<Script> script(Script::cast(script_obj));
+ accumulator->Add(" [");
+ accumulator->PrintName(script->name());
+
+ Address pc = this->pc();
+ if (code != NULL && code->kind() == Code::FUNCTION &&
+ pc >= code->instruction_start() && pc < code->relocation_start()) {
+ int source_pos = code->SourcePosition(pc);
+ int line = GetScriptLineNumberSafe(script, source_pos) + 1;
+ accumulator->Add(":%d", line);
+ } else {
+ int function_start_pos = shared->start_position();
+ int line = GetScriptLineNumberSafe(script, function_start_pos) + 1;
+ accumulator->Add(":~%d", line);
+ }
+
+ accumulator->Add("] ");
+ }
+ }
+
accumulator->Add("(this=%o", receiver);
// Get scope information for nicer output, if possible. If code is
}
+int GetScriptLineNumberSafe(Handle<Script> script, int code_pos) {
+ AssertNoAllocation no_allocation;
+ if (!script->line_ends()->IsUndefined()) {
+ return GetScriptLineNumber(script, code_pos);
+ }
+ // Slow mode: we do not have line_ends. We have to iterate through source.
+ if (!script->source()->IsString()) {
+ return -1;
+ }
+ String* source = String::cast(script->source());
+ int line = 0;
+ int len = source->length();
+ for (int pos = 0; pos < len; pos++) {
+ if (pos == code_pos) {
+ break;
+ }
+ if (source->Get(pos) == '\n') {
+ line++;
+ }
+ }
+ return line;
+}
+
+
void CustomArguments::IterateInstance(ObjectVisitor* v) {
v->VisitPointers(values_, values_ + 4);
}
// Script line number computations.
void InitScriptLineEnds(Handle<Script> script);
int GetScriptLineNumber(Handle<Script> script, int code_position);
+// The safe version does not make heap allocations but may work much slower.
+int GetScriptLineNumberSafe(Handle<Script> script, int code_position);
// Computes the enumerable keys from interceptors. Used for debug mirrors and
// by GetKeysInFixedArrayFor below.