<commit_before>"use strict"

var JavaScriptPlaygroundEditor = require("./JavaScriptPlaygroundEditor.js")
  , vm = require("vm")

var JavaScriptPlayground = module.exports = function (playgroundElement, jsStubText) {
	this._playgroundElem = playgroundElement

	var jsEditorElement = document.createElement("div")
    jsEditorElement.style.width = "100%"
    jsEditorElement.style.height = "100%"
	this._playgroundElem.appendChild(jsEditorElement)

	this._jsEditor = new JavaScriptPlaygroundEditor(jsEditorElement, jsStubText)
	this._jsEditor.on("changeValidJS", this._handleJSChange.bind(this))
}

JavaScriptPlayground.prototype._handleJSChange = function (event) {
    try {
        var result = vm.runInNewContext(event.documentText(), {
            "require": require,
            "module": { "exports": {} }
        })
        result("bar")
    }
    catch (e) {
        console.log(e)
    }
}
<commit_msg>Fix for running exported function instead of result of last statement.<commit_after>"use strict"

var JavaScriptPlaygroundEditor = require("./JavaScriptPlaygroundEditor.js")
  , vm = require("vm")

var JavaScriptPlayground = module.exports = function (playgroundElement, jsStubText) {
	this._playgroundElem = playgroundElement

	var jsEditorElement = document.createElement("div")
    jsEditorElement.style.width = "100%"
    jsEditorElement.style.height = "100%"
	this._playgroundElem.appendChild(jsEditorElement)

	this._jsEditor = new JavaScriptPlaygroundEditor(jsEditorElement, jsStubText)
	this._jsEditor.on("changeValidJS", this._handleJSChange.bind(this))
}

JavaScriptPlayground.prototype._handleJSChange = function (event) {
    var context = {
        "require": require,
        "module": { "exports": {} }
    }

        vm.runInNewContext(event.documentText(), context)
        context.module.exports.call(undefined, "bar")
    try {
    }
    catch (e) {
        console.log(e)
    }
}

{'fraction_non_alphanumeric': 0.11891042430591933, 'fraction_numerical': 0.006286013619696176, 'mean_word_length': 4.079787234042553, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '3921954', 'n_tokens_mistral': 566, 'n_tokens_neox': 545, 'n_words': 100}