<commit_before>var WebKit = require('../');
var expect = require('expect.js');
var fs = require('fs');

describe("error reporting", function suite() {
	it("should catch async script errors", function(done) {
		this.timeout(1000);
		var w = WebKit.load("http://localhost", {content: '<html></html>'}, function(err) {
			w.run(function(done) {
				setTimeout(function() {
					var r = 2 + h;
					done(); // won't actually be called
				}, 100);
			}, function(err) {
				expect(err).to.be.ok(); // timeout
			});
			w.on('error', function(msg, uri, line, col, err) {
				expect(msg).to.be('ReferenceError: Can\'t find variable: h');
				done();
			});
		});
	});
	it("should catch sync script errors", function(done) {
		this.timeout(1000);
		var w = WebKit.load("http://localhost", {content: '<html></html>'}, function(err) {
			w.run(function() {
				document.createWhatever("tata");
			}, function(err) {
				expect(err && err.stack).to.be.ok();
				done();
			});
		});
	});
	it("should log uncaught Error instances with actual exception stack", function(done) {
		this.timeout(1000);
		WebKit(function(err, w) {
			w.load("http://localhost", {content: '<html></html>'}, function(err) {
				w.run(function(done) {
					setTimeout(function myfunc() {
						throw new Error("i am here");
						done(); // won't actually be called
					}, 100);
				}, function(err) {
					expect(err).to.be.ok(); // timeout
				});
			});
			w.on('error', function(msg, uri, line, col, err) {
				expect(err).to.be.ok();
				expect(err.message).to.be("i am here");
				expect(err.stack).to.be.ok();
				done();
			});
		});
	});
});<commit_msg>Test custom property on error<commit_after>var WebKit = require('../');
var expect = require('expect.js');
var fs = require('fs');

describe("error reporting", function suite() {
	it("should catch async script errors", function(done) {
		this.timeout(1000);
		var w = WebKit.load("http://localhost", {content: '<html></html>'}, function(err) {
			w.run(function(done) {
				setTimeout(function() {
					var r = 2 + h;
					done(); // won't actually be called
				}, 100);
			}, function(err) {
				expect(err).to.be.ok(); // timeout
			});
			w.on('error', function(msg, uri, line, col, err) {
				expect(msg).to.be('ReferenceError: Can\'t find variable: h');
				done();
			});
		});
	});
	it("should catch sync script errors", function(done) {
		this.timeout(1000);
		var w = WebKit.load("http://localhost", {content: '<html></html>'}, function(err) {
			w.run(function() {
				document.createWhatever("tata");
			}, function(err) {
				expect(err && err.stack).to.be.ok();
				done();
			});
		});
	});
	it("should log uncaught Error instances with actual exception stack", function(done) {
		this.timeout(1000);
		WebKit(function(err, w) {
			w.load("http://localhost", {content: '<html></html>'}, function(err) {
				w.run(function(done) {
					setTimeout(function myfunc() {
						var err = new Error("i am here");
						err.code = 404;
						throw err;
						done(); // won't actually be called
					}, 100);
				}, function(err) {
					expect(err).to.be.ok(); // timeout
				});
			});
			w.on('error', function(msg, uri, line, col, err) {
				expect(err).to.be.ok();
				expect(err.message).to.be("i am here");
				expect(err.code).to.be(404);
				expect(err.stack).to.be.ok();
				done();
			});
		});
	});
});
{'fraction_non_alphanumeric': 0.21475507765830346, 'fraction_numerical': 0.013142174432497013, 'mean_word_length': 3.233881163084703, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1622267', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1117, 'n_words': 246}