Example #1
0
/* static */ BOOL
ES_DebugBuiltins::getObjectDemographics(ES_Execution_Context *context, unsigned argc, ES_Value_Internal *argv, ES_Value_Internal *return_value)
{
    return_value->SetNull();

	if (argc == 1)
	{
        if (!argv[0].ToNumber(context) || !argv[0].IsUInt32())
            return FALSE;

		if (ES_Heap *heap = g_ecmaManager->GetHeapById(argv[0].GetNumAsUInt32()))
		{
			TempBuffer *buffer = g_ecmaManager->GetHeapDebuggerBuffer();

			buffer->Clear();
			buffer->Append("{ ");

			unsigned *live_objects = heap->live_objects;

			for (unsigned index = 0; index < GCTAG_UNINITIALIZED; ++index)
			{
				if (index != 0)
					buffer->Append(", ");

				buffer->Append("\"");
				buffer->Append(g_ecmaClassName[index]);
				buffer->Append("\": ");
				buffer->AppendUnsignedLong(live_objects[index]);
			}

			buffer->Append(" }");

            return_value->SetString(JString::Make(context, buffer->GetStorage(), buffer->Length()));
		}
	}

	return TRUE;
}
Example #2
0
/* static */ BOOL
ES_DebugBuiltins::getHeapInformation(ES_Execution_Context *context, unsigned argc, ES_Value_Internal *argv, ES_Value_Internal *return_value)
{
	Head *active, *inactive, *destroy;

	g_ecmaManager->GetHeapLists(active, inactive, destroy);

	TempBuffer *buffer = g_ecmaManager->GetHeapDebuggerBuffer();
	buffer->Clear();

	buffer->Append("{ \"heaps\": { ");

	ES_Heap *heads[3] = { static_cast<ES_Heap *>(active->First()), static_cast<ES_Heap *>(inactive->First()), static_cast<ES_Heap *>(destroy->First()) };

	for (unsigned head = 0; head < 3; ++head)
		for (ES_Heap *heap = heads[head]; heap; heap = static_cast<ES_Heap *>(heap->Suc()))
		{
			buffer->AppendFormat(UNI_L("\"%u\": { \"bytesLive\": %u, \"bytesLivePeak\": %u, \"bytesLimit\": %u, \"runtimes\": ["), heap->Id(), heap->GetBytesLive(), heap->GetBytesLivePeak(), heap->GetBytesLimit());

			ES_Runtime *runtime = heap->GetFirstRuntime();

			while (runtime)
			{
#ifndef _STANDALONE
				ES_Object *global_object = runtime->GetGlobalObject();
				if (global_object->IsHostObject() && ES_Runtime::GetHostObject(global_object)->IsA(DOM_TYPE_WINDOW))
				{
					OpString url;

					DOM_Utils::GetOriginURL(DOM_Utils::GetDOM_Runtime(runtime)).GetAttribute(URL::KUniName, url);

					for (unsigned index = 0; index < static_cast<unsigned>(url.Length()); ++index)
						if (url.CStr()[index] == '"')
							url.Insert(index++, "\\");

					buffer->AppendFormat(UNI_L("\"%s\""), url.CStr());
				}
				else
#endif // _STANDALONE
					buffer->Append("\"<unidentified runtime>\"");

				runtime = g_ecmaManager->GetNextRuntimePerHeap(runtime);

				if (runtime)
					buffer->Append(", ");
			}

			buffer->Append("] }, ");
		}

	buffer->AppendFormat(UNI_L("\"count\": %u }, \"allocators\": ["), active->Cardinal() + inactive->Cardinal() + destroy->Cardinal());

	for (ES_PageAllocator *allocator = static_cast<ES_PageAllocator *>(g_ecmaPageAllocatorList->First()); allocator; allocator = static_cast<ES_PageAllocator *>(allocator->Suc()))
	{
		buffer->AppendFormat(UNI_L("{ \"chunks\": %u, \"chunkSize\": %u, \"pages\": %u, \"pageSize\": %u, \"heaps\": ["), allocator->CountChunks(), allocator->ChunkSize(), allocator->CountPages(), allocator->PageSize());

		for (ES_HeapHandle *heaph = allocator->GetFirstHeapHandle(); heaph; heaph = static_cast<ES_HeapHandle *>(heaph->Suc()))
		{
			buffer->AppendUnsignedLong(heaph->heap->Id());

			if (heaph->Suc())
				buffer->Append(", ");
		}

		buffer->Append("] }");

		if (allocator->Suc())
			buffer->Append(", ");
	}

	buffer->Append("], \"cachedPrograms\": [");

	for (Link *link = RT_DATA.program_cache->GetCachedPrograms()->First(); link; link = link->Suc())
	{
		ES_ProgramCodeStatic *program = static_cast<ES_ProgramCodeStatic *>(link);

		buffer->AppendFormat(UNI_L("{ \"url\": \"\", \"length\": %u }"), program->source.GetSource()->length);

		if (link->Suc())
			buffer->Append(", ");
	}

	buffer->Append("] }");

    return_value->SetString(JString::Make(context, buffer->GetStorage(), buffer->Length()));

    return TRUE;
}
Example #3
0
void SetDataFromItemData(const BookmarkItemData* item_data, BookmarkItem* bookmark)
{
	if (!bookmark || !item_data) return;

	// these 2 attributes must exist, as they have a different default value with others. (-1)
	::SetAttribute(bookmark, BOOKMARK_PERSONALBAR_POS, -1);
	::SetAttribute(bookmark, BOOKMARK_PANEL_POS, -1);	

	::SetAttribute(bookmark, BOOKMARK_URL,			item_data->url);
	::SetAttribute(bookmark, BOOKMARK_TITLE,		item_data->name);
	::SetAttribute(bookmark, BOOKMARK_DESCRIPTION,	item_data->description);
	::SetAttribute(bookmark, BOOKMARK_SHORTNAME,	item_data->shortname);
	::SetAttribute(bookmark, BOOKMARK_CREATED,		item_data->created);
	::SetAttribute(bookmark, BOOKMARK_VISITED,		item_data->visited);
	::SetAttribute(bookmark, BOOKMARK_TARGET,		item_data->target);
	::SetAttribute(bookmark, BOOKMARK_PERSONALBAR_POS,item_data->personalbar_position);
	::SetAttribute(bookmark, BOOKMARK_PANEL_POS,	item_data->panel_position);
	::SetAttribute(bookmark, BOOKMARK_ACTIVE,		item_data->active);
	::SetAttribute(bookmark, BOOKMARK_EXPANDED,		item_data->expanded);
	::SetAttribute(bookmark, BOOKMARK_SMALLSCREEN,	item_data->small_screen);
	::SetAttribute(bookmark, BOOKMARK_SHOW_IN_PERSONAL_BAR,item_data->personalbar_position >= 0);
	::SetAttribute(bookmark, BOOKMARK_SHOW_IN_PANEL,item_data->panel_position >= 0);
	::SetAttribute(bookmark, BOOKMARK_PARTNER_ID,	item_data->partner_id);
	::SetAttribute(bookmark, BOOKMARK_DISPLAY_URL,	item_data->display_url);

	// icon
	Image icon = g_favicon_manager->Get(item_data->url);
	OpString16 base64;
	OpBitmap *bitmap = icon.GetBitmap(NULL);
	if (bitmap)
	{
		TempBuffer buffer;
		if(OpStatus::IsSuccess(GetOpBitmapAsBase64PNG(bitmap, &buffer)))
		{
			if(OpStatus::IsSuccess(base64.Set(buffer.GetStorage(), buffer.Length())))
			{
				::SetAttribute(bookmark, BOOKMARK_FAVICON_FILE, base64);
			}
		}
		icon.ReleaseBitmap();
	}
	if (item_data->unique_id.HasContent())
	{
		OpString tmp;
		tmp.Set(item_data->unique_id);
		uni_char* uni_unique_id = OP_NEWA(uni_char, (tmp.Length()+1));
		if (uni_unique_id)
		{
			uni_strcpy(uni_unique_id, tmp.CStr());
			bookmark->SetUniqueId(uni_unique_id);
		}
	}

	bookmark->SetMaxCount(item_data->max_count);
	bookmark->SetMoveIsCopy(item_data->move_is_copy);
	bookmark->SetSubFoldersAllowed(item_data->subfolders_allowed);
	bookmark->SetSeparatorsAllowed(item_data->separators_allowed);
	bookmark->SetDeletable(item_data->deletable);

	bookmark->SetFolderType(item_data->type);
}