Merge mozilla-inbound into mozilla-central.

This commit is contained in:
Mounir Lamouri 2011-06-29 17:38:29 +02:00
commit 820becb78e
23 changed files with 516 additions and 156 deletions

View File

@ -946,6 +946,10 @@ public:
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
PRInt64 SizeOf() const {
return sizeof(*this);
}
protected:
/**
* Hook for implementing GetID. This is guaranteed to only be

View File

@ -1534,6 +1534,8 @@ public:
#undef DEPRECATED_OPERATION
void WarnOnceAbout(DeprecatedOperations aOperation);
PRInt64 SizeOf() const;
private:
PRUint32 mWarnedAbout;

View File

@ -8375,3 +8375,16 @@ nsDocument::CreateTouchList(nsIVariant* aPoints,
return NS_OK;
}
PRInt64
nsIDocument::SizeOf() const
{
PRInt64 size = sizeof(*this);
for (nsIContent* node = GetFirstChild(); node;
node = node->GetNextNode(this)) {
size += node->SizeOf();
}
return size;
}

View File

@ -2593,7 +2593,7 @@ struct NS_STACK_CLASS nsCanvasBidiProcessor : public nsBidiPresUtils::BidiProces
mBoundingBox = mBoundingBox.Union(textRunMetrics.mBoundingBox);
}
return static_cast<nscoord>(textRunMetrics.mAdvanceWidth/gfxFloat(mAppUnitsPerDevPixel));
return NSToCoordRound(textRunMetrics.mAdvanceWidth);
}
virtual void DrawText(nscoord xOffset, nscoord width)
@ -2744,7 +2744,7 @@ nsCanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
processor.mFontgrp = GetCurrentFontStyle();
NS_ASSERTION(processor.mFontgrp, "font group is null");
nscoord totalWidth;
nscoord totalWidthCoord;
// calls bidi algo twice since it needs the full text width and the
// bounding boxes before rendering anything
@ -2756,12 +2756,13 @@ nsCanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
nsBidiPresUtils::MODE_MEASURE,
nsnull,
0,
&totalWidth);
&totalWidthCoord);
if (NS_FAILED(rv))
return rv;
float totalWidth = float(totalWidthCoord) / processor.mAppUnitsPerDevPixel;
if (aWidth)
*aWidth = static_cast<float>(totalWidth);
*aWidth = totalWidth;
// if only measuring, don't need to do any more work
if (aOp==TEXT_DRAW_OPERATION_MEASURE)

View File

@ -216,8 +216,7 @@ _TEST_FILES = \
test_bug555840.html \
test_bug561636.html \
test_bug590363.html \
test_bug557628-1.html \
test_bug557628-2.html \
test_bug557628.html \
test_bug592802.html \
test_bug595429.html \
test_bug595447.html \

View File

@ -20,6 +20,72 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=551670
/** Test for Bug 551670 **/
// TODO: maybe make those reflections be tested against all input types.
// .accept
reflectString(document.createElement("input"), "accept",
[ "audio/*", "video/*", "image/*", "image/png",
"application/msword", "appplication/pdf" ]);
// .alt
reflectString(document.createElement("input"), "alt");
// .autocomplete
reflectLimitedEnumerated(document.createElement("input"), "autocomplete",
[ "on", "off" ], [ "", "default", "foo", "tulip" ]);
// TODO: autofocus (boolean)
// TODO: defaultChecked (boolean)
// TODO: checked (boolean)
// TODO: dirName (not implemented)
// TODO: disabled (boolean)
// TODO: form (HTMLFormElement)
// TODO: files (FileList)
// TODO: formAction (URL)
// .formEnctype
reflectLimitedEnumerated(document.createElement("input"), "formEnctype",
[ "application/x-www-form-urlencoded",
"multipart/form-data", "text/plain" ],
[ "", "foo", "tulip", "multipart/foo" ],
"application/x-www-form-urlencoded");
// .formMethod
reflectLimitedEnumerated(document.createElement("input"), "formMethod",
[ "get", "post" ], [ "", "foo", "tulip" ], "get");
// TODO: formNoValidate (boolean)
// .formTarget
reflectString(document.createElement("input"), "formTarget",
[ "_blank", "_self", "_parent", "_top" ]);
// TODO: height (non-negative integer)
// TODO: indeterminate (boolean)
// TODO: list (HTMLElement)
// TODO: max (not implemented)
// TODO: maxLength (long)
// TODO: min (not implemented)
// TODO: multiple (boolean)
// .name
reflectString(document.createElement("input"), "name",
[ "isindex", "_charset_" ]);
// .pattern
reflectString(document.createElement("input"), "pattern",
[ "[0-9][A-Z]{3}" ]);
// .placeholder
reflectString(document.createElement("input"), "placeholder",
[ "foo\nbar", "foo\rbar", "foo\r\nbar" ]);
// TODO: readOnly (boolean)
// TODO: required (boolean)
// TODO: size (unsigned long)
// TODO: src (URL)
// TODO: step (not implemented)
// .type
reflectLimitedEnumerated(document.createElement("input"),
"type",
@ -31,6 +97,17 @@ reflectLimitedEnumerated(document.createElement("input"),
[ "datetime", "date", "month", "week", "time",
"datetime-local", "number", "range", "color" ]);
// TODO: defaultValue (reflects @value)
// .value doesn't reflect a content attribute.
// TODO: valueAsDate (not implemented)
// TODO: valueAsNumber (not implemented)
// TODO: selectedOption (not implemented)
// TODO: width (non-negative integer)
// .willValidate doesn't reflect a content attribute.
// .validity doesn't reflect a content attribute.
// .validationMessage doesn't reflect a content attribute.
// .labels doesn't reflect a content attribute.
</script>
</pre>
</body>

View File

@ -33,34 +33,6 @@ function invalidEventHandler(e)
gInvalid = true;
}
function checkPatternAttribute(element)
{
ok('pattern' in element, "Element should have the pattern attribute");
is(element.pattern, "tulip",
"pattern IDL attribute value should be 'tulip'");
is(element.getAttribute('pattern'), "tulip",
"pattern content attribute value should be 'tulip'");
element.pattern = "foo";
is(element.pattern, "foo",
"pattern IDL attribute value should be 'foo'");
is(element.getAttribute('pattern'), "foo",
"pattern content attribute value should be 'foo'");
element.removeAttribute('pattern');
ok(!element.pattern,
"Element pattern attribute shouldn't be specified");
is(element.getAttribute('pattern'), null,
"Element pattern attribute shouldn't be specified");
element.setAttribute("pattern", "bar");
is(element.pattern, "bar",
"pattern IDL attribute value should be 'bar'");
is(element.getAttribute('pattern'), "bar",
"pattern content attribute value should be 'bar'");
}
function completeValidityCheck(element, alwaysValid, isBarred)
{
if (element.type == 'file') {
@ -286,9 +258,6 @@ function checkPatternValidity(element)
var input = document.getElementById('i');
// All input types should have the pattern attribute.
checkPatternAttribute(input);
// |validTypes| are the types which accept @pattern
// and |invalidTypes| are the ones which do not accept it.
var validTypes = Array('text', 'password', 'search', 'tel', 'email', 'url');

View File

@ -1,3 +1,107 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* reflect.js is a collection of methods to test HTML attribute reflection.
* Each of attribute is reflected differently, depending on various parameters,
* see:
* http://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes
*
* Do not forget to add these line at the beginning of each new reflect* method:
* ok(aAttr in aElement, aAttr + " should be an IDL attribute of this element");
* is(typeof aElement[aAttr], <type>, aAttr + " IDL attribute should be a <type>");
*/
/**
* Checks that a given attribute is correctly reflected as a string.
*
* @param aElement Element node to test
* @param aAttr String name of the attribute
* @param aOtherValues Array other values to test in addition of the default ones [optional]
*/
function reflectString(aElement, aAttr, aOtherValues)
{
var otherValues = aOtherValues !== undefined ? aOtherValues : [];
ok(aAttr in aElement, aAttr + " should be an IDL attribute of this element");
is(typeof aElement[aAttr], "string", aAttr + " IDL attribute should be a string");
// Tests when the attribute isn't set.
is(aElement.getAttribute(aAttr), null,
"When not set, the content attribute should be undefined.");
is(aElement[aAttr], "",
"When not set, the IDL attribute should return the empty string");
/**
* TODO: as long as null stringification doesn't fallow the webidl specs,
* don't add it to the loop below and keep it here.
*/
aElement.setAttribute(aAttr, null);
todo_is(aElement.getAttribute(aAttr), "null",
"null should have been stringified to 'null'");
todo_is(aElement[aAttr], "null",
"null should have been stringified to 'null'");
aElement.removeAttribute(aAttr);
aElement[aAttr] = null;
todo_is(aElement.getAttribute(aAttr), "null",
"null should have been stringified to 'null'");
todo_is(aElement[aAttr], "null",
"null should have been stringified to 'null'");
aElement.removeAttribute(aAttr);
// Tests various strings.
var stringsToTest = [
// [ test value, expected result ]
[ "", "" ],
[ "null", "null" ],
[ "undefined", "undefined" ],
[ "foo", "foo" ],
[ aAttr, aAttr ],
// TODO: uncomment this when null stringification will follow the specs.
// [ null, "null" ],
[ undefined, "undefined" ],
[ true, "true" ],
[ false, "false" ],
[ 42, "42" ],
// ES5, verse 8.12.8.
[ { toString: function() { return "foo" } },
"foo" ],
[ { valueOf: function() { return "foo" } },
"[object Object]" ],
[ { valueOf: function() { return "quux" },
toString: undefined },
"quux" ],
[ { valueOf: function() { return "foo" },
toString: function() { return "bar" } },
"bar" ]
];
otherValues.forEach(function(v) { stringsToTest.push([v, v]) });
stringsToTest.forEach(function([v, r]) {
aElement.setAttribute(aAttr, v);
is(aElement[aAttr], r,
"IDL attribute should return the value it has been set to.");
is(aElement.getAttribute(aAttr), r,
"Content attribute should return the value it has been set to.");
aElement.removeAttribute(aAttr);
aElement[aAttr] = v;
is(aElement[aAttr], r,
"IDL attribute should return the value it has been set to.");
is(aElement.getAttribute(aAttr), r,
"Content attribute should return the value it has been set to.");
aElement.removeAttribute(aAttr);
});
// Tests after removeAttribute() is called. Should be equivalent with not set.
is(aElement.getAttribute(aAttr), null,
"When not set, the content attribute should be undefined.");
is(aElement[aAttr], "",
"When not set, the IDL attribute should return the empty string");
}
/**
* Checks that a given attribute name for a given element is correctly reflected
* as an unsigned int.
@ -19,6 +123,9 @@ function reflectUnsignedInt(aElement, aAttr, aNonNull, aDefault)
}
}
ok(aAttr in aElement, aAttr + " should be an IDL attribute of this element");
is(typeof aElement[aAttr], "number", aAttr + " IDL attribute should be a string");
// Check default value.
is(aElement[aAttr], aDefault, "default value should be " + aDefault);
ok(!aElement.hasAttribute(aAttr), aAttr + " shouldn't be present");
@ -108,6 +215,10 @@ function reflectLimitedEnumerated(aElement, aAttr, aValidValues, aInvalidValues,
var defaultValue = aDefaultValue !== undefined ? aDefaultValue : "";
var unsupportedValues = aUnsupportedValues !== undefined ? aUnsupportedValues
: [];
ok(aAttr in aElement, aAttr + " should be an IDL attribute of this element");
is(typeof aElement[aAttr], "string", aAttr + " IDL attribute should be a string");
// Explicitly check the default value.
aElement.removeAttribute(aAttr);
is(aElement[aAttr], defaultValue,
@ -126,7 +237,7 @@ function reflectLimitedEnumerated(aElement, aAttr, aValidValues, aInvalidValues,
is(aElement[aAttr], v,
"Enumerated attributes should be case-insensitive.");
is(aElement.getAttribute(aAttr), v.toUpperCase(),
"Content attribute should be upper-cased.");
"Content attribute should not be lower-cased.");
aElement.removeAttribute(aAttr);
aElement[aAttr] = v;
@ -140,7 +251,7 @@ function reflectLimitedEnumerated(aElement, aAttr, aValidValues, aInvalidValues,
is(aElement[aAttr], v,
"Enumerated attributes should be case-insensitive.");
is(aElement.getAttribute(aAttr), v.toUpperCase(),
"Content attribute should be upper-cased.");
"Content attribute should not be lower-cased.");
aElement.removeAttribute(aAttr);
});
@ -175,7 +286,7 @@ function reflectLimitedEnumerated(aElement, aAttr, aValidValues, aInvalidValues,
todo_is(aElement[aAttr], v,
"Enumerated attributes should be case-insensitive.");
is(aElement.getAttribute(aAttr), v.toUpperCase(),
"Content attribute should be upper-cased.");
"Content attribute should not be lower-cased.");
aElement.removeAttribute(aAttr);
aElement[aAttr] = v;
@ -189,7 +300,7 @@ function reflectLimitedEnumerated(aElement, aAttr, aValidValues, aInvalidValues,
todo_is(aElement[aAttr], v,
"Enumerated attributes should be case-insensitive.");
is(aElement.getAttribute(aAttr), v.toUpperCase(),
"Content attribute should be upper-cased.");
"Content attribute should not be lower-cased.");
aElement.removeAttribute(aAttr);
});
}

View File

@ -13,8 +13,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=457800
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=457800">Mozilla Bug 457800</a>
<p id="display"></p>
<div id="content" style="display: none">
<input type="text" id="inputtext"/><br/>
<input type="password"id="inputpassword"/><br/>
<textarea id="textarea"></textarea>
</div>
<pre id="test">
@ -51,8 +49,6 @@ function testPlaceholderForElement(element)
is(element.getAttribute('placeholder'), 'place\rholder', "\\r shouldn't be stripped");
}
testPlaceholderForElement(document.getElementById('inputtext'));
testPlaceholderForElement(document.getElementById('inputpassword'));
testPlaceholderForElement(document.getElementById('textarea'));
</script>

View File

@ -1,72 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=557628
-->
<head>
<title>Test for Bug 557628</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557628">Mozilla Bug 557628</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 557628 **/
var inputAutocompleteTestData = [
// Default value.
[ "" ],
// Valid values.
[ "on", "off" ],
// Invalid values.
[ "", " ", "foo", "default", "foo bar" ]
];
function checkAttribute(element, name, data)
{
is(element.getAttribute(name), undefined,
"By default " + name + " content attribute should be undefined");
is(element[name], data[0][0],
"By default " + name + " IDL attribute should be equal to " +
data[0][0]);
// Valid values.
for (i in data[1]) {
element.setAttribute(name, data[1][i]);
is(element.getAttribute(name), data[1][i],
"getAttribute should return the content attribute");
is(element[name], data[1][i], "When getting, " + name + " IDL attribute " +
"should be equal to the content attribute if the value is known");
}
// Invalid values.
for (i in data[2]) {
element.setAttribute(name, data[2][i]);
is(element.getAttribute(name), data[2][i],
"getAttribute should return the content attribute");
is(element[name], data[0][0], "When getting, " + name + " IDL attribute " +
"should return the default value if the content attribute value isn't known");
}
// TODO values.
for (i in data[3]) {
element.setAttribute(name, data[3][i]);
is(element.getAttribute(name), data[3][i],
"getAttribute should return the content attribute");
todo_is(element[name], data[3][i], "When getting, " + name + " IDL attribute " +
"should be equal to the content attribute if the value is known");
}
}
var input = document.createElement('input');
checkAttribute(input, 'autocomplete', inputAutocompleteTestData);
</script>
</pre>
</body>
</html>

View File

@ -48,13 +48,10 @@ function checkFormTarget(aElement)
isFormTargetEquals(aElement, "", true);
}
var input = document.createElement('input');
var button = document.createElement('button');
ok('formTarget' in input, "formTarget is a HTMLInputElement property");
ok('formTarget' in button, "formTarget is a HTMLButtonElement property");
checkFormTarget(input);
checkFormTarget(button);
</script>

View File

@ -63,13 +63,10 @@ function checkAttribute(form, attrName, idlName, data)
}
var form = document.createElement('form');
var input = document.createElement('input');
var button = document.createElement('button');
checkAttribute(form, 'enctype', 'enctype', enctypeTestData);
checkAttribute(form, 'method', 'method', methodTestData);
checkAttribute(input, 'formenctype', 'formEnctype', enctypeTestData);
checkAttribute(input, 'formmethod', 'formMethod', methodTestData);
checkAttribute(button, 'formenctype', 'formEnctype', enctypeTestData);
checkAttribute(button, 'formmethod', 'formMethod', methodTestData);

View File

@ -22,19 +22,25 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=590363
var testData = [
/* type to test | is the value reset when changing to file then reverting */
[ "button", false ],
[ "button", false ],
[ "checkbox", false ],
[ "hidden", false ],
[ "reset", false ],
[ "image", false ],
[ "radio", false ],
[ "submit", false ],
[ "tel", true ],
[ "text", true ],
[ "url", true ],
[ "email", true ],
[ "search", true ],
[ "hidden", false ],
[ "reset", false ],
[ "image", false ],
[ "radio", false ],
[ "submit", false ],
[ "tel", true ],
[ "text", true ],
[ "url", true ],
[ "email", true ],
[ "search", true ],
[ "password", true ],
[ "number", true ],
// 'file' is treated separatly.
];
var todoTypes = [
"datetime", "date", "month", "week", "time", "datetime-local", "range", "color"
];
var length = testData.length;
@ -42,9 +48,17 @@ for (var i=0; i<length; ++i) {
for (var j=0; j<length; ++j) {
var e = document.createElement('input');
e.type = testData[i][0];
e.value = "foo";
var expectedValue;
if (testData[i][0] == 'number' || testData[j][0] == 'number') {
expectedValue = '42';
} else {
expectedValue = "foo";
}
e.value = expectedValue;
e.type = testData[j][0];
is(e.value, "foo", ".value should still return the same value after " +
is(e.value, expectedValue, ".value should still return the same value after " +
"changing type from " + testData[i][0] + " to " + testData[j][0]);
}
}
@ -67,6 +81,13 @@ for each (var data in testData) {
}
}
// TODO checks
for each (var type in todoTypes) {
var e = document.createElement('input');
e.type = type;
todo_is(e.type, type, type + " type isn't supported yet");
}
</script>
</pre>
</body>

View File

@ -112,6 +112,7 @@ CPPSRCS = \
nsStructuredCloneContainer.cpp \
nsDOMNavigationTiming.cpp \
nsPerformance.cpp \
nsDOMMemoryReporter.cpp \
$(NULL)
include $(topsrcdir)/dom/dom-config.mk

View File

@ -0,0 +1,110 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsDOMMemoryReporter.h"
#include "nsGlobalWindow.h"
nsDOMMemoryReporter::nsDOMMemoryReporter()
{
}
NS_IMPL_ISUPPORTS1(nsDOMMemoryReporter, nsIMemoryReporter)
/* static */
void
nsDOMMemoryReporter::Init()
{
// The memory reporter manager is going to own this object.
NS_RegisterMemoryReporter(new nsDOMMemoryReporter());
}
NS_IMETHODIMP
nsDOMMemoryReporter::GetProcess(char** aProcess)
{
// "" means the main process.
*aProcess = strdup("");
return NS_OK;
}
NS_IMETHODIMP
nsDOMMemoryReporter::GetPath(char** aMemoryPath)
{
*aMemoryPath = strdup("explicit/dom");
return NS_OK;
}
NS_IMETHODIMP
nsDOMMemoryReporter::GetKind(int* aKind)
{
*aKind = KIND_HEAP;
return NS_OK;
}
NS_IMETHODIMP
nsDOMMemoryReporter::GetDescription(char** aDescription)
{
*aDescription = strdup("Memory used by the DOM.");
return NS_OK;
}
NS_IMETHODIMP
nsDOMMemoryReporter::GetUnits(PRInt32* aUnits)
{
*aUnits = UNITS_BYTES;
return NS_OK;
}
static
PLDHashOperator
GetWindowsMemoryUsage(const PRUint64& aId, nsGlobalWindow*& aWindow,
void* aClosure)
{
*(PRInt64*)aClosure += aWindow->SizeOf();
return PL_DHASH_NEXT;
}
NS_IMETHODIMP
nsDOMMemoryReporter::GetAmount(PRInt64* aAmount) {
*aAmount = 0;
nsGlobalWindow::WindowByIdTable* windows = nsGlobalWindow::GetWindowsTable();
windows->Enumerate(GetWindowsMemoryUsage, aAmount);
return NS_OK;
}

View File

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDOMMemoryReporter_h__
#define nsDOMMemoryReporter_h__
#include "nsIMemoryReporter.h"
class nsDOMMemoryReporter: public nsIMemoryReporter {
public:
NS_DECL_ISUPPORTS
static void Init();
NS_IMETHOD GetProcess(char** aProcess);
NS_IMETHOD GetPath(char** aMemoryPath);
NS_IMETHOD GetKind(int* aKnd);
NS_IMETHOD GetDescription(char** aDescription);
NS_IMETHOD GetUnits(PRInt32* aUnits);
NS_IMETHOD GetAmount(PRInt64* aAmount);
private:
// Protect ctor, use Init() instead.
nsDOMMemoryReporter();
};
#endif // nsDOMMemoryReporter_h__

View File

@ -252,7 +252,7 @@ using mozilla::TimeStamp;
using mozilla::TimeDuration;
nsIDOMStorageList *nsGlobalWindow::sGlobalStorageList = nsnull;
nsGlobalWindow::WindowByIdTable *nsGlobalWindow::sOuterWindowsById = nsnull;
nsGlobalWindow::WindowByIdTable *nsGlobalWindow::sWindowsById = nsnull;
static nsIEntropyCollector *gEntropyCollector = nsnull;
static PRInt32 gRefCnt = 0;
@ -887,18 +887,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
mObserver = nsnull;
SetIsProxy();
if (!sOuterWindowsById) {
sOuterWindowsById = new WindowByIdTable();
if (!sOuterWindowsById->Init()) {
delete sOuterWindowsById;
sOuterWindowsById = nsnull;
}
}
if (sOuterWindowsById) {
sOuterWindowsById->Put(mWindowID, this);
}
}
// We could have failed the first time through trying
@ -952,17 +940,35 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
("DOMWINDOW %p created outer=%p", this, aOuterWindow));
#endif
// TODO: could be moved to a ::Init() method, see bug 667183.
if (!sWindowsById) {
sWindowsById = new WindowByIdTable();
if (!sWindowsById->Init()) {
delete sWindowsById;
sWindowsById = nsnull;
NS_ERROR("sWindowsById initialization failed!");
}
}
if (sWindowsById) {
NS_ASSERTION(!sWindowsById->Get(mWindowID),
"This window shouldn't be in the hash table yet!");
sWindowsById->Put(mWindowID, this);
}
}
nsGlobalWindow::~nsGlobalWindow()
{
if (sOuterWindowsById) {
sOuterWindowsById->Remove(mWindowID);
// We have to check if sWindowsById isn't null because ::Shutdown might have
// been called.
if (sWindowsById) {
NS_ASSERTION(sWindowsById->Get(mWindowID),
"This window should be in the hash table");
sWindowsById->Remove(mWindowID);
}
if (!--gRefCnt) {
NS_IF_RELEASE(gEntropyCollector);
delete sOuterWindowsById;
sOuterWindowsById = nsnull;
}
#ifdef DEBUG
nsCAutoString url;
@ -1038,6 +1044,9 @@ nsGlobalWindow::ShutDown()
fclose(gDumpFile);
}
gDumpFile = nsnull;
delete sWindowsById;
sWindowsById = nsnull;
}
// static

View File

@ -287,6 +287,7 @@ public:
typedef mozilla::TimeStamp TimeStamp;
typedef mozilla::TimeDuration TimeDuration;
typedef nsDataHashtable<nsUint64HashKey, nsGlobalWindow*> WindowByIdTable;
// public methods
nsPIDOMWindow* GetPrivateParent();
@ -531,13 +532,28 @@ public:
}
static nsGlobalWindow* GetOuterWindowWithId(PRUint64 aWindowID) {
return sOuterWindowsById ? sOuterWindowsById->Get(aWindowID) : nsnull;
nsGlobalWindow* outerWindow = sWindowsById->Get(aWindowID);
return outerWindow && !outerWindow->IsInnerWindow() ? outerWindow : nsnull;
}
static bool HasIndexedDBSupport();
static bool HasPerformanceSupport();
static WindowByIdTable* GetWindowsTable() {
return sWindowsById;
}
PRInt64 SizeOf() const {
PRInt64 size = sizeof(*this);
if (IsInnerWindow() && mDoc) {
size += mDoc->SizeOf();
}
return size;
}
private:
// Enable updates for the accelerometer.
void EnableDeviceMotionUpdates();
@ -959,8 +975,7 @@ protected:
friend class PostMessageEvent;
static nsIDOMStorageList* sGlobalStorageList;
typedef nsDataHashtable<nsUint64HashKey, nsGlobalWindow*> WindowByIdTable;
static WindowByIdTable* sOuterWindowsById;
static WindowByIdTable* sWindowsById;
};
/*

View File

@ -122,6 +122,7 @@
#include "nsRefreshDriver.h"
#include "nsHyphenationManager.h"
#include "nsDOMMemoryReporter.h"
extern void NS_ShutdownChainItemPool();
@ -265,12 +266,22 @@ nsLayoutStatics::Initialize()
NS_SealStaticAtomTable();
// TODO: DOM_MEMORY_REPORTER should not be defined in a regular build for the
// moment. This protection will be removed when bug 663271 will be close enough
// to a shippable state.
#ifdef DOM_MEMORY_REPORTER
nsDOMMemoryReporter::Init();
#endif
return NS_OK;
}
void
nsLayoutStatics::Shutdown()
{
// Don't need to shutdown nsDOMMemoryReporter, that will be done by the memory
// reporter manager.
nsFrameScriptExecutor::Shutdown();
nsFocusManager::Shutdown();
#ifdef MOZ_XUL

View File

@ -41,6 +41,8 @@ asserts-if(cocoaWidget,0-2) == size-change-1.html size-change-1-ref.html
fails-if(Android) != text-font-lang.html text-font-lang-notref.html
== text-measure.html text-measure-ref.html
== strokeText-path.html strokeText-path-ref.html
# gradient off-by-one, fails on windows and linux

View File

@ -0,0 +1,15 @@
<html>
<script>
function load() {
var ctx = document.getElementById("canvas").getContext("2d");
ctx.font = "bold 12px sans-serif";
ctx.scale(4, 4);
var str = "HeHeHeHe";
ctx.fillText(str, 0, 15);
}
</script>
<body onload="load();">
<canvas id="canvas" width="400" height="200"></canvas>
</body>
</html>

View File

@ -0,0 +1,19 @@
<html>
<script>
function load() {
var ctx = document.getElementById("canvas").getContext("2d");
ctx.font = "bold 12px sans-serif";
ctx.scale(4, 4);
var str = "HeHeHeHe";
var x = 0;
for (var i = 0; i < str.length; ++i) {
ctx.fillText(str[i], x, 15);
x += ctx.measureText(str[i]).width;
}
}
</script>
<body onload="load();">
<canvas id="canvas" width="400" height="200"></canvas>
</body>
</html>