Skip to content

Instantly share code, notes, and snippets.

@execjosh
Created August 28, 2011 14:57
Show Gist options
  • Save execjosh/1176761 to your computer and use it in GitHub Desktop.
Save execjosh/1176761 to your computer and use it in GitHub Desktop.
Simple test file for phantomjs issue 206
<!doctype html>
<script>
function isObject(o) {
return typeof o === 'object';
}
function isFunction(o) {
return typeof o === 'function';
}
function isUndefined(o) {
return typeof o === 'undefined';
}
function isUndefinedOrNull(o) {
return isUndefined(o) || null === o;
}
function copyInto(target, source) {
if (target === source || isUndefinedOrNull(source)) {
return target;
}
target = target || {};
// Copy into objects only
if (isObject(target)) {
// Make sure source exists
source = source || {};
if (isObject(source)) {
var i, newTarget, newSource;
for (i in source) {
if (source.hasOwnProperty(i)) {
newTarget = target[i];
newSource = source[i];
if (newTarget && isObject(newSource)) {
// Deep copy
newTarget = copyInto(target[i], newSource);
} else {
newTarget = newSource;
}
if (!isUndefined(newTarget)) {
target[i] = newTarget;
}
}
}
} else {
target = source;
}
}
return target;
}
var page;
var a = {
a: "a"
},
b = {
b: "b",
c: undefined,
d: null
},
c = {
c: function () {
console.log("c");
}
},
;
function applier(val, src) {
return copyInto(val, src);
}
function stringify(o, level) {
level = level || 1;
var joinStr = ["\n"],
endStr = ["\n"];
for (var i = 0; i < level; i++) {
joinStr.push("\t");
if (0 < i) {
endStr.push("\t");
}
}
joinStr = joinStr.join('');
endStr = endStr.join('');
if (isObject(o)) {
var str = ["{"], i;
for (i in o) {
str.push(i + ": " + (stringify(o[i], level+1)));
}
return str.join(joinStr) + endStr + "}";
} else if (isFunction(o)) {
return o.toString();
} else {
return JSON.stringify(o);
}
}
console.log("undefined = " + stringify(applier(undefined)));
console.log("null = " + stringify(applier(null)));
console.log("true = " + stringify(applier(true)));
console.log("false = " + stringify(applier(false)));
console.log("1 = " + stringify(applier(1)));
console.log("1.2 = " + stringify(applier(1.2)));
console.log("'hey' = " + stringify(applier("hey")));
console.log("func = " + stringify(applier(function () {console.log("func");})));
console.log("{} = " + stringify(applier({})));
console.log("----");
console.log("undefined = " + stringify(applier(undefined, a)));
console.log("null = " + stringify(applier(null, a)));
console.log("true = " + stringify(applier(true, a)));
console.log("false = " + stringify(applier(false, a)));
console.log("1 = " + stringify(applier(1, a)));
console.log("1.2 = " + stringify(applier(1.2, a)));
console.log("'hey' = " + stringify(applier("hey", a)));
console.log("func = " + stringify(applier(function () {console.log("func");}, a)));
console.log("{} = " + stringify(applier({}, a)));
console.log("----");
console.log("undefined = " + stringify(applier(undefined, b)));
console.log("null = " + stringify(applier(null, b)));
console.log("true = " + stringify(applier(true, b)));
console.log("false = " + stringify(applier(false, b)));
console.log("1 = " + stringify(applier(1, b)));
console.log("1.2 = " + stringify(applier(1.2, b)));
console.log("'hey' = " + stringify(applier("hey", b)));
console.log("func = " + stringify(applier(function () {console.log("func");}, b)));
console.log("{} = " + stringify(applier({}, b)));
console.log("----");
console.log("undefined = " + stringify(applier(undefined, c)));
console.log("null = " + stringify(applier(null, c)));
console.log("true = " + stringify(applier(true, c)));
console.log("false = " + stringify(applier(false, c)));
console.log("1 = " + stringify(applier(1, c)));
console.log("1.2 = " + stringify(applier(1.2, c)));
console.log("'hey' = " + stringify(applier("hey", c)));
console.log("func = " + stringify(applier(function () {}, c)));
console.log("{} = " + stringify(applier({}, c)));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment