#include "ecmascript.h"
#include "core/engine.h"
#include "core/io/file_access_encrypted.h"
#include "ecmascript_instance.h"
#include "ecmascript_language.h"
#include "scene/resources/resource_format_text.h"
#define GET_CLASS_BINDER(cls) ECMAScriptLanguage::get_singleton()->binding->get_context_binder(cls->constructor.context)
ScriptLanguage *ECMAScript::get_language() const {
return ECMAScriptLanguage::get_singleton();
}
ECMAScript::ECMAScript() {
ecma_class = NULL;
}
ECMAScript::~ECMAScript() {
}
bool ECMAScript::can_instance() const {
#ifdef TOOLS_ENABLED
return is_valid() && (is_tool() || ScriptServer::is_scripting_enabled());
#else
return is_valid();
#endif
}
StringName ECMAScript::get_instance_base_type() const {
const ECMAClassInfo *cls = get_ecma_class();
if (cls) {
return cls->native_class->name;
} else {
static StringName empty;
return empty;
}
}
ScriptInstance *ECMAScript::instance_create(Object *p_this) {
const ECMAClassInfo *cls = get_ecma_class();
ERR_FAIL_NULL_V(cls, NULL);
if (!ClassDB::is_parent_class(p_this->get_class_name(), cls->native_class->name)) {
ERR_PRINTS("Script inherits from native type '" + String(cls->native_class->name) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'");
ERR_FAIL_V(NULL);
}
Variant::CallError unchecked_error;
ECMAScriptGCHandler ecma_instance = GET_CLASS_BINDER(cls)->create_ecma_instance_for_godot_object(cls, p_this);
ERR_FAIL_NULL_V(ecma_instance.ecma_object, NULL);
ECMAScriptInstance *instance = memnew(ECMAScriptInstance);
instance->script = Ref