⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string-stream.cc.svn-base

📁 Google浏览器V8内核代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
  return true;}void StringStream::PrintName(Object* name) {  if (name->IsString()) {    String* str = String::cast(name);    if (str->length() > 0) {      Put(str);    } else {      Add("/* anonymous */");    }  } else {    Add("%o", name);  }}void StringStream::PrintUsingMap(JSObject* js_object) {  Map* map = js_object->map();  if (!Heap::Contains(map) ||      !map->IsHeapObject() ||      !map->IsMap()) {    Add("<Invalid map>\n");    return;  }  for (DescriptorReader r(map->instance_descriptors()); !r.eos(); r.advance()) {    switch (r.type()) {      case FIELD: {        Object* key = r.GetKey();        if (key->IsString() || key->IsNumber()) {          int len = 3;          if (key->IsString()) {            len = String::cast(key)->length();          }          for (; len < 18; len++)            Put(' ');          if (key->IsString()) {            Put(String::cast(key));          } else {            key->ShortPrint();          }          Add(": ");          Object* value = js_object->properties()->get(r.GetFieldIndex());          Add("%o\n", value);        }      }      break;      default:      break;    }  }}void StringStream::PrintFixedArray(FixedArray* array, unsigned int limit) {  for (unsigned int i = 0; i < 10 && i < limit; i++) {    Object* element = array->get(i);    if (element != Heap::the_hole_value()) {      for (int len = 1; len < 18; len++)        Put(' ');      Add("%d: %o\n", i, array->get(i));    }  }  if (limit >= 10) {    Add("                  ...\n");  }}void StringStream::PrintByteArray(ByteArray* byte_array) {  unsigned int limit = byte_array->length();  for (unsigned int i = 0; i < 10 && i < limit; i++) {    byte b = byte_array->get(i);    Add("             %d: %3d 0x%02x", i, b, b);    if (b >= ' ' && b <= '~') {      Add(" '%c'", b);    } else if (b == '\n') {      Add(" '\n'");    } else if (b == '\r') {      Add(" '\r'");    } else if (b >= 1 && b <= 26) {      Add(" ^%c", b + 'A' - 1);    }    Add("\n");  }  if (limit >= 10) {    Add("                  ...\n");  }}void StringStream::PrintMentionedObjectCache() {  Add("==== Key         ============================================\n\n");  for (int i = 0; i < debug_object_cache->length(); i++) {    HeapObject* printee = (*debug_object_cache)[i];    Add(" #%d# %p: ", i, printee);    printee->ShortPrint(this);    Add("\n");    if (printee->IsJSObject()) {      if (printee->IsJSValue()) {        Add("           value(): %o\n", JSValue::cast(printee)->value());      }      PrintUsingMap(JSObject::cast(printee));      if (printee->IsJSArray()) {        JSArray* array = JSArray::cast(printee);        if (array->HasFastElements()) {          unsigned int limit = FixedArray::cast(array->elements())->length();          unsigned int length =            static_cast<uint32_t>(JSArray::cast(array)->length()->Number());          if (length < limit) limit = length;          PrintFixedArray(FixedArray::cast(array->elements()), limit);        }      }    } else if (printee->IsByteArray()) {      PrintByteArray(ByteArray::cast(printee));    } else if (printee->IsFixedArray()) {      unsigned int limit = FixedArray::cast(printee)->length();      PrintFixedArray(FixedArray::cast(printee), limit);    }  }}void StringStream::PrintSecurityTokenIfChanged(Object* f) {  if (!f->IsHeapObject() || !Heap::Contains(HeapObject::cast(f))) {    return;  }  Map* map = HeapObject::cast(f)->map();  if (!map->IsHeapObject() ||      !Heap::Contains(map) ||      !map->IsMap() ||      !f->IsJSFunction()) {    return;  }  JSFunction* fun = JSFunction::cast(f);  Object* perhaps_context = fun->unchecked_context();  if (perhaps_context->IsHeapObject() &&      Heap::Contains(HeapObject::cast(perhaps_context)) &&      perhaps_context->IsContext()) {    Context* context = fun->context();    if (!Heap::Contains(context)) {      Add("(Function context is outside heap)\n");      return;    }    GlobalObject* global = context->global();    if (!Heap::Contains(global)) {      Add("(Function context global is outside heap)\n");      return;    }    if (global->IsJSGlobalObject()) {      Object* token = JSGlobalObject::cast(global)->security_token();      if (token != current_security_token) {        Add("Security context: %o\n", token);        current_security_token = token;      }    } else {      Add("(No security context)\n");    }  } else {    Add("(Function context is corrupt)\n");  }}void StringStream::PrintFunction(Object* f, Object* receiver, Code** code) {  if (f->IsHeapObject() &&      Heap::Contains(HeapObject::cast(f)) &&      Heap::Contains(HeapObject::cast(f)->map()) &&      HeapObject::cast(f)->map()->IsMap()) {    if (f->IsJSFunction()) {      JSFunction* fun = JSFunction::cast(f);      // Common case: on-stack function present and resolved.      PrintPrototype(fun, receiver);      *code = fun->code();    } else if (f->IsSymbol()) {      // Unresolved and megamorphic calls: Instead of the function      // we have the function name on the stack.      PrintName(f);      Add("/* unresolved */ ");    } else {      // Unless this is the frame of a built-in function, we should always have      // the callee function or name on the stack. If we don't, we have a      // problem or a change of the stack frame layout.      Add("%o", f);      Add("/* warning: no JSFunction object or function name found */ ");    }    /* } else if (is_trampoline()) {       Print("trampoline ");    */  } else {    if (!f->IsHeapObject()) {      Add("/* warning: 'function' was not a heap object */ ");      return;    }    if (!Heap::Contains(HeapObject::cast(f))) {      Add("/* warning: 'function' was not on the heap */ ");      return;    }    if (!Heap::Contains(HeapObject::cast(f)->map())) {      Add("/* warning: function's map was not on the heap */ ");      return;    }    if (!HeapObject::cast(f)->map()->IsMap()) {      Add("/* warning: function's map was not a valid map */ ");      return;    }    Add("/* warning: Invalid JSFunction object found */ ");  }}void StringStream::PrintPrototype(JSFunction* fun, Object* receiver) {  Object* name = fun->shared()->name();  bool print_name = false;  for (Object* p = receiver; p != Heap::null_value(); p = p->GetPrototype()) {    if (p->IsJSObject()) {      Object* key = JSObject::cast(p)->SlowReverseLookup(fun);      if (key != Heap::undefined_value()) {        if (!name->IsString() ||            !key->IsString() ||            !String::cast(name)->Equals(String::cast(key))) {          print_name = true;        }        if (name->IsString() && String::cast(name)->length() == 0) {          print_name = false;        }        name = key;      }    } else {      print_name = true;    }  }  PrintName(name);  // Also known as - if the name in the function doesn't match the name under  // which it was looked up.  if (print_name) {    Add("(aka ");    PrintName(fun->shared()->name());    Put(')');  }}char* HeapStringAllocator::grow(unsigned* bytes) {  unsigned new_bytes = *bytes * 2;  // Check for overflow.  if (new_bytes <= *bytes) {    return space_;  }  char* new_space = NewArray<char>(new_bytes);  if (new_space == NULL) {    return space_;  }  memcpy(new_space, space_, *bytes);  *bytes = new_bytes;  DeleteArray(space_);  space_ = new_space;  return new_space;}char* NoAllocationStringAllocator::grow(unsigned* bytes) {  unsigned new_bytes = *bytes * 2;  if (new_bytes > size_) {    new_bytes = size_;  }  *bytes = new_bytes;  return space_;}} }  // namespace v8::internal

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -