Skip to content

Instantly share code, notes, and snippets.

View bryanforbes's full-sized avatar

Bryan Forbes bryanforbes

View GitHub Profile
addtest('bug-root-children-arent-styled', function(g, d, e){
var result = null, root;
if(d && d.documentElement && e){
root = d.documentElement;
e.style.cssText = 'width:40px;height:40px;';
try{
root.insertBefore(e, root.firstChild);
result = e.clientWidth == 0;
(function(global){
var NON_HOST_TYPES = { "boolean": 1, "number": 1, "string": 1, "undefined": 1 },
_listen, _stopListening, normalizeEventName;
// Imported from http://github.com/phiggins42/has.js.
// Host objects can return type values that are different from their actual
// data type. The objects we are concerned with usually return non-primitive
// types of object, function, or unknown.
function isHostType(object, property){
var type = typeof object[property];
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="2;url=">
<title>Leak Fix with Lookup Wrapper</title>
<script src="helper.js"></script>
<script>
var _cache = {};
var createWrapper = (function(){
@bryanforbes
bryanforbes / gist:663298
Created November 4, 2010 22:06
This is an attempt to explain what is happening behind the scenes with event handlers in ES3 and why IE leaks in one case and not another.
// Global Object
// (§10.2.1)
// GO.scope_chain = [GO]
// GO._cache = _cache
var _cache = {};
// Declaration (§13.2):
// CWanonfunc.[[Scope]] = GO.scope_chain.slice(0) (§13.2 step 7)
@bryanforbes
bryanforbes / dispatcher.js
Created December 15, 2010 19:21
A simple event disptacher to prevent leaks
var eventData = {};
(function(global){
function createDispatcher(id){
function dispatcher(){
if(id in _evtData){
_evtData[id].handler.apply(this, arguments);
}
}
return dispatcher;
var guid = (function(){
function hasUniqueNumber(){
var docEl = document.documentElement, elem = document.createElement("div");
return (typeof elem.uniqueNumber == "number" && typeof docEl.uniqueNumber == "number" &&
elem.uniqueNumber != docEl.uniqueNumber);
}
var guid, last = 1;
if(hasUniqueNumber()){
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<input id="txt" />
<script>
var txt = document.getElementById("txt"),
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<input id="txt" type="text">
<script>
var attach;
var Boolean = (function(){
var undefinedThis = (function(){
return this; // this depends on strict mode
})();
function Boolean(arg){
if(this == undefinedThis){
return !!arg;
}else{
return {};
}
@bryanforbes
bryanforbes / a.js
Created May 13, 2011 13:57
Recursive module requires
define([], function(){
require(['tests/recurse/b']);
return {};
});