├── boot ├── .gitignore ├── support │ ├── winboot.rc │ ├── titanium.ico │ └── common_controls.manifest ├── popup_dialog_win32.h └── boot.h ├── site_scons ├── .gitignore └── site_init.py ├── libkroll ├── .gitignore ├── binding │ ├── klist.h │ ├── read_event.h │ ├── read_event.cpp │ ├── void_ptr.h │ ├── k_accessor_object.h │ ├── k_accessor_list.h │ ├── k_accessor_method.h │ ├── global_object.h │ ├── k_accessor_list.cpp │ ├── profiled_global_object.h │ ├── k_accessor_object.cpp │ ├── k_accessor_method.cpp │ ├── k_function_ptr_method.cpp │ ├── global_object.cpp │ ├── static_bound_method.cpp │ ├── stream.h │ ├── value_exception.h │ ├── k_function_ptr_method.h │ ├── stream.cpp │ ├── binding.h │ ├── profiled_global_object.cpp │ ├── profiled_bound_list.cpp │ ├── value_exception.cpp │ ├── profiled_bound_method.h │ ├── profiled_bound_method.cpp │ ├── scope_method_delegate.h │ ├── profiled_bound_list.h │ ├── static_bound_object.cpp │ ├── k_delegating_object.h │ ├── profiled_bound_object.h │ ├── arg_list.h │ ├── k_event_object.h │ ├── static_bound_method.h │ ├── event.h │ ├── klist.cpp │ ├── k_delegating_object.cpp │ ├── static_bound_list.h │ ├── k_event_method.h │ ├── static_bound_object.h │ ├── kmethod.h │ ├── kmethod.cpp │ └── scope_method_delegate.cpp ├── api │ ├── SConscript │ ├── api_module.cpp │ ├── environment_binding.h │ ├── api_module.h │ ├── dependency_binding.h │ ├── component_binding.h │ ├── environment_binding.cpp │ ├── dependency_binding.cpp │ └── application_binding.h ├── memory │ ├── basictypes.h │ └── README.md ├── win32 │ ├── win32.h │ ├── event_window.h │ ├── com_reference_counted.h │ ├── string_util_win.h │ └── port.h ├── net │ ├── net.h │ ├── proxy_config_linux.cpp │ └── proxy_config.h ├── osx │ ├── nslog_channel.mm │ └── nslog_channel.h ├── thread_manager.h ├── javascript │ ├── SConscript │ ├── javascript_methods.h │ ├── javascript_module_instance.h │ ├── k_kjs_object.h │ ├── k_kjs_list.h │ ├── k_kjs_method.h │ ├── kjs_util.h │ ├── javascript_module.h │ ├── javascript_module.cpp │ └── javascript_module_instance.cpp ├── utils │ ├── data_utils.cpp │ ├── osx │ │ ├── data_utils_osx.mm │ │ ├── boot_utils_osx.mm │ │ ├── osx_utils.h │ │ └── osx_utils.mm │ ├── data_utils.h │ ├── linux │ │ ├── data_utils_linux.cpp │ │ ├── file_utils_linux.cpp │ │ └── boot_utils_linux.cpp │ ├── win32 │ │ ├── data_utils_win32.cpp │ │ └── win32_utils.h │ ├── posix │ │ ├── posix_utils.h │ │ └── posix_utils.cpp │ ├── platform_utils.cpp │ ├── environment_utils.h │ ├── platform_utils.h │ ├── utils.h │ ├── kashmir │ │ ├── devrandom.h │ │ ├── noncopyable.h │ │ ├── winundocrand.h │ │ └── winrandom.h │ ├── url_utils.h │ └── poco │ │ └── KDigestEngine.cpp ├── reference_counted.h ├── Interpreter.h ├── main_thread_job.h ├── ScriptController.h ├── module_provider.h ├── ScriptController.cpp ├── main_thread_job.cpp └── kroll.h ├── .gitignore ├── tools ├── alloy │ ├── Resources │ │ └── index.html │ ├── manifest │ ├── tiapp.xml │ └── modules │ │ └── alloy │ │ └── alloymodule.js ├── crlf.py └── upload_thirdparty.py ├── modules ├── python │ ├── python_interpreter.h │ ├── python_api.h │ ├── python_module_instance.h │ ├── python_module_instance.cpp │ ├── k_python_dict.h │ ├── k_python_object.h │ ├── k_python_method.h │ ├── python_utils.h │ ├── SConscript │ ├── k_python_list.h │ ├── k_python_tuple.h │ ├── k_python_method.cpp │ └── python_module.h ├── php │ ├── php_api.h │ ├── php_interpreter.h │ ├── php_module_instance.cpp │ ├── php_module_instance.h │ ├── k_php_object.h │ ├── k_php_function.h │ ├── k_php_method.h │ ├── k_php_list.h │ ├── k_php_array_object.h │ ├── SConscript │ ├── php_utils.h │ └── php_interpreter.cpp ├── SConscript └── ruby │ ├── ruby_interpreter.h │ ├── ruby_module_instance.h │ ├── ruby_module_instance.cpp │ ├── ruby_utils.h │ ├── k_ruby_object.h │ ├── k_ruby_hash.h │ ├── k_ruby_method.h │ ├── SConscript │ ├── k_ruby_list.h │ ├── ruby_module.cpp │ └── ruby_module.h ├── SConscript ├── SConstruct └── SConscript.thirdparty /boot/.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | -------------------------------------------------------------------------------- /site_scons/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /libkroll/.gitignore: -------------------------------------------------------------------------------- 1 | *.dylib 2 | *.o 3 | -------------------------------------------------------------------------------- /boot/support/winboot.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON "titanium.ico" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .sconsign.dblite 2 | *.o 3 | *.os 4 | docs 5 | *.pyc 6 | thirdparty-* 7 | *.swp 8 | *.swo 9 | -------------------------------------------------------------------------------- /boot/support/titanium.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/kroll/HEAD/boot/support/titanium.ico -------------------------------------------------------------------------------- /libkroll/binding/klist.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcelerator-archive/kroll/HEAD/libkroll/binding/klist.h -------------------------------------------------------------------------------- /tools/alloy/Resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /site_scons/site_init.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os.path as path 3 | 4 | sys.path.append(path.join(path.abspath('.'), 'tools')) 5 | import kroll 6 | -------------------------------------------------------------------------------- /libkroll/api/SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os import path 3 | Import('build env module') 4 | 5 | env.Append(CPPDEFINES=('KROLL_API_API_EXPORT', 1)) 6 | 7 | build.add_thirdparty(env, 'poco') 8 | build.mark_build_target(env.SharedLibrary( 9 | path.join(module.dir, 'apimodule'), Glob('*.cpp'))) 10 | -------------------------------------------------------------------------------- /tools/alloy/manifest: -------------------------------------------------------------------------------- 1 | #appname:Alloy 2 | #version:1.0 3 | #appid:com.titaniumapp.alloy 4 | #publisher:Appcelerator 5 | #image:default_app_logo.png 6 | #url:http://titaniumapp.com 7 | #guid:be69fe4c-966b-483c-b57c-7ba4a34fbf10 8 | #desc:Alloy shell 9 | runtime: 10 | python: 11 | ruby: 12 | alloy: 13 | tiapp: 14 | #php: 15 | -------------------------------------------------------------------------------- /tools/alloy/tiapp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.titaniumapp.alloy 4 | Alloy 5 | 1.0 6 | Appcelerator 7 | titaniumapp.com 8 | 2009 by Appcelerator 9 | 10 | -------------------------------------------------------------------------------- /libkroll/memory/basictypes.h: -------------------------------------------------------------------------------- 1 | // Excerpt from Chromium's base/memory/basictypes.h 2 | // Only what we need to compile the other files we extracted. 3 | 4 | // A macro to disallow the copy constructor and operator= functions 5 | // This should be used in the private: declarations for a class 6 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 7 | TypeName(const TypeName&); \ 8 | void operator=(const TypeName&) 9 | 10 | -------------------------------------------------------------------------------- /boot/support/common_controls.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /libkroll/win32/win32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_WIN32_H_ 7 | #define _KR_WIN32_H_ 8 | #include "event_window.h" 9 | #include "basictypes.h" 10 | #include "port.h" 11 | #include "string16.h" 12 | #include "string_util.h" 13 | #include "string_util_win.h" 14 | #include "com_reference_counted.h" 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /libkroll/net/net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_NET_H_ 7 | #define _KR_NET_H_ 8 | #include 9 | #include 10 | #include 11 | namespace kroll 12 | { 13 | class Proxy; 14 | typedef SharedPtr SharedProxy; 15 | typedef SharedPtr SharedURI; 16 | } 17 | #include "proxy_config.h" 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /libkroll/osx/nslog_channel.mm: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | 9 | namespace kroll 10 | { 11 | NSLogChannel::NSLogChannel() 12 | : formatter("[%s] [%p] %t") 13 | { 14 | } 15 | 16 | void NSLogChannel::log(const Poco::Message& msg) 17 | { 18 | std::string text; 19 | formatter.format(msg, text); 20 | NSLog(@"%s", text.c_str()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libkroll/thread_manager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_THREAD_MANAGER_H_ 7 | #define _KR_THREAD_MANAGER_H_ 8 | 9 | #ifdef OS_OSX 10 | #define START_KROLL_THREAD NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 11 | #define END_KROLL_THREAD [pool release]; 12 | #else 13 | #define START_KROLL_THREAD 14 | #define END_KROLL_THREAD 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /libkroll/binding/read_event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_READ_EVENT_H_ 8 | #define _KR_READ_EVENT_H_ 9 | 10 | namespace kroll 11 | { 12 | class KROLL_API ReadEvent : public Event 13 | { 14 | public: 15 | ReadEvent(AutoPtr target, BytesRef); 16 | void _GetData(const ValueList&, KValueRef result); 17 | 18 | protected: 19 | BytesRef data; 20 | }; 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /modules/python/python_interpreter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef PYTHON_EVALUATOR_H_ 7 | #define PYTHON_EVALUATOR_H_ 8 | 9 | #include 10 | 11 | namespace kroll { 12 | 13 | class PythonInterpreter : public Interpreter { 14 | public: 15 | PythonInterpreter(); 16 | 17 | virtual KValueRef EvaluateFile(const char* filepath, KObjectRef context); 18 | }; 19 | 20 | } // namespace kroll 21 | 22 | #endif -------------------------------------------------------------------------------- /libkroll/binding/read_event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | namespace kroll 9 | { 10 | ReadEvent::ReadEvent(AutoPtr target, BytesRef data) : 11 | Event(target, Event::READ), 12 | data(data) 13 | { 14 | this->SetMethod("getData", &ReadEvent::_GetData); 15 | } 16 | 17 | void ReadEvent::_GetData(const ValueList&, KValueRef result) 18 | { 19 | result->SetObject(this->data); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /libkroll/javascript/SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os import path 3 | Import('build env module') 4 | 5 | env.Append(CPPDEFINES=('KROLL_JAVASCRIPT_API_EXPORT', 1)) 6 | 7 | build.add_thirdparty(env, 'poco') 8 | 9 | build.add_thirdparty(env, 'webkit') 10 | 11 | if build.is_win32(): 12 | env.Append(LIBS=[ 13 | 'kernel32', 'shell32', 14 | 'user32', 'ole32', 15 | 'comctl32', 'shlwapi', 16 | 'oleaut32', 'icuuc', 17 | 'pthreadVC2', 'kroll']) 18 | env.Append(LINKFLAGS=['/LTCG', '/INCREMENTAL:NO']) 19 | 20 | build.mark_build_target(env.SharedLibrary( 21 | path.join(module.dir, 'javascriptmodule'), Glob('*.cpp'))) 22 | -------------------------------------------------------------------------------- /libkroll/api/api_module.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include "api_module.h" 10 | 11 | namespace kroll 12 | { 13 | void APIModule::Initialize() 14 | { 15 | binding = new APIBinding(host); 16 | host->GetGlobalObject()->SetObject("API", binding); 17 | } 18 | 19 | void APIModule::Stop() 20 | { 21 | host->GetGlobalObject()->Set("API", Value::Undefined); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /libkroll/utils/data_utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "utils.h" 7 | #include "poco/KDigestEngine.h" 8 | #include "poco/KMD5Engine.h" 9 | 10 | using KPoco::DigestEngine; 11 | using KPoco::MD5Engine; 12 | 13 | namespace UTILS_NS 14 | { 15 | namespace DataUtils 16 | { 17 | std::string HexMD5(std::string data) 18 | { 19 | MD5Engine engine; 20 | engine.update(data); 21 | return DigestEngine::digestToHex(engine.digest()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /modules/php/php_api.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _PHPAPI_H_ 8 | #define _PHPAPI_H_ 9 | 10 | #if defined(OS_OSX) || defined(OS_LINUX) 11 | #define EXPORT __attribute__((visibility("default"))) 12 | #define KROLL_PHP_API EXPORT 13 | #elif defined(OS_WIN32) 14 | # ifdef KROLL_PHP_API_EXPORT 15 | # define KROLL_PHP_API __declspec(dllexport) 16 | # else 17 | # define KROLL_PHP_API __declspec(dllimport) 18 | # endif 19 | #endif 20 | 21 | #endif /* PHPAPI_H_ */ 22 | 23 | -------------------------------------------------------------------------------- /libkroll/utils/osx/data_utils_osx.mm: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../utils.h" 8 | #include "../kashmir/uuid.h" 9 | #include "../kashmir/devrandom.h" 10 | #include 11 | 12 | namespace UTILS_NS 13 | { 14 | std::string DataUtils::GenerateUUID() 15 | { 16 | kashmir::uuid_t uuid; 17 | kashmir::system::DevRandom devrandom; 18 | std::ostringstream outStream; 19 | devrandom >> uuid; 20 | outStream << uuid; 21 | return outStream.str(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libkroll/javascript/javascript_methods.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008-2010 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _JAVASCRIPT_METHODS_H_ 8 | #define _JAVASCRIPT_METHODS_H_ 9 | 10 | namespace kroll 11 | { 12 | namespace JavaScriptMethods 13 | { 14 | 15 | void Bind(KObjectRef global); 16 | KValueRef SetTimeout(const ValueList& args); 17 | KValueRef SetInterval(const ValueList& args); 18 | KValueRef ClearTimeout(const ValueList& args); 19 | KValueRef ClearInterval(const ValueList& args); 20 | 21 | } 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /libkroll/utils/data_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_DATA_UTILS_H_ 7 | #define _KR_DATA_UTILS_H_ 8 | #include 9 | namespace UTILS_NS 10 | { 11 | namespace DataUtils 12 | { 13 | /* 14 | * @returns the hexidecimal MD5 hash of a string 15 | */ 16 | KROLL_API std::string HexMD5(std::string); 17 | 18 | /** 19 | * Generate a new UUID 20 | * @returns a new UUID as a string 21 | */ 22 | KROLL_API std::string GenerateUUID(); 23 | } 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /modules/python/python_api.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef PYTHONAPI_H_ 8 | #define PYTHONAPI_H_ 9 | 10 | #if defined(OS_OSX) || defined(OS_LINUX) 11 | #define EXPORT __attribute__((visibility("default"))) 12 | #define KROLL_PYTHON_API EXPORT 13 | #elif defined(OS_WIN32) 14 | # ifdef KROLL_PYTHON_API_EXPORT 15 | # define KROLL_PYTHON_API __declspec(dllexport) 16 | # else 17 | # define KROLL_PYTHON_API __declspec(dllimport) 18 | # endif 19 | #endif 20 | 21 | #endif /* PYTHONAPI_H_ */ 22 | -------------------------------------------------------------------------------- /libkroll/utils/linux/data_utils_linux.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../utils.h" 8 | #include "../kashmir/uuid.h" 9 | #include "../kashmir/devrandom.h" 10 | #include 11 | 12 | namespace UTILS_NS 13 | { 14 | namespace DataUtils 15 | { 16 | std::string GenerateUUID() 17 | { 18 | kashmir::uuid_t uuid; 19 | kashmir::system::DevRandom devrandom; 20 | std::ostringstream outStream; 21 | devrandom >> uuid; 22 | outStream << uuid; 23 | return outStream.str(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libkroll/utils/win32/data_utils_win32.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../utils.h" 8 | #include "../kashmir/uuid.h" 9 | #include "../kashmir/winrandom.h" 10 | #include 11 | 12 | namespace UTILS_NS 13 | { 14 | namespace DataUtils 15 | { 16 | std::string GenerateUUID() 17 | { 18 | kashmir::uuid_t uuid; 19 | kashmir::system::WinRandom devrandom; 20 | std::ostringstream outStream; 21 | devrandom >> uuid; 22 | outStream << uuid; 23 | return outStream.str(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /modules/php/php_interpreter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _PHP_INTERPRETER_H_ 8 | #define _PHP_INTERPRETER_H_ 9 | 10 | #include 11 | 12 | namespace kroll { 13 | 14 | class PHPInterpreter : public Interpreter { 15 | public: 16 | PHPInterpreter(); 17 | 18 | KValueRef EvaluateFile(const char* filepath, KObjectRef context); 19 | 20 | private: 21 | std::string CreateContextName(); 22 | void FillGet(Poco::URI& uri TSRMLS_DC); 23 | }; 24 | 25 | } // namespace kroll 26 | 27 | #endif -------------------------------------------------------------------------------- /modules/php/php_module_instance.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "php_module_instance.h" 7 | 8 | namespace kroll 9 | { 10 | PHPModuleInstance::PHPModuleInstance(Host* host, std::string path, std::string dir, std::string name) : 11 | Module(host, dir.c_str(), name.c_str(), "0.1"), 12 | path(path) 13 | { 14 | } 15 | 16 | PHPModuleInstance::~PHPModuleInstance() 17 | { 18 | } 19 | 20 | void PHPModuleInstance::Initialize () 21 | { 22 | } 23 | 24 | void PHPModuleInstance::Destroy () 25 | { 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tools/crlf.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | "Replace CRLF with LF in argument files. Print names of changed files." 3 | 4 | import sys, os 5 | 6 | def main(): 7 | for filename in sys.argv[1:]: 8 | if os.path.isdir(filename): 9 | print filename, "Directory!" 10 | continue 11 | data = open(filename, "rb").read() 12 | if '\0' in data: 13 | print filename, "Binary!" 14 | continue 15 | newdata = data.replace("\r\n", "\n") 16 | if newdata != data: 17 | print filename 18 | f = open(filename, "wb") 19 | f.write(newdata) 20 | f.close() 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /libkroll/utils/posix/posix_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009-2010 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_POSIX_UTILS_H_ 7 | #define _KR_POSIX_UTILS_H_ 8 | #include 9 | namespace UTILS_NS 10 | { 11 | KROLL_API std::wstring UTF8ToWide(const std::string& in); 12 | KROLL_API std::wstring UTF8ToWide(const char* in); 13 | KROLL_API std::string WideToUTF8(const std::wstring& in); 14 | KROLL_API std::string WideToUTF8(const wchar_t* in); 15 | KROLL_API std::string UTF8ToSystem(const std::string& in); 16 | KROLL_API std::string UTF8ToSystem(const char* in); 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /modules/SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os import path 3 | from kroll import Module 4 | Import('build') 5 | 6 | def build_module_from_directory(dir): 7 | name = dir.lower().replace('.', '') 8 | module = Module(name, build.version, path.join(build.dir, 'modules', name)) 9 | build.modules.append(module) 10 | 11 | env = build.env.Clone() 12 | env.Append(CPPDEFINES=[('MODULE_NAME', name), ('MODULE_VERSION', build.version)]) 13 | 14 | SConscript( 15 | path.join(dir, 'SConscript'), 16 | variant_dir=path.join(build.dir, 'objs', 'modules', name), 17 | exports='build module env', 18 | duplicate=0) 19 | 20 | Export('build_module_from_directory') 21 | for dir in ['python', 'ruby', 'php']: 22 | build_module_from_directory(dir) 23 | -------------------------------------------------------------------------------- /libkroll/binding/void_ptr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_VOID_PTR_OBJECT_H_ 8 | #define _KR_VOID_PTR_OBJECT_H_ 9 | 10 | #include "../kroll.h" 11 | 12 | namespace kroll 13 | { 14 | /** 15 | * An object that represents an arbitrary amount of binary data§ 16 | */ 17 | class KROLL_API VoidPtr : public StaticBoundObject 18 | { 19 | public: 20 | VoidPtr(void* pointer) : 21 | StaticBoundObject("VoidPtr"), 22 | pointer(pointer) {} 23 | void* GetPtr() { return pointer; } 24 | 25 | private: 26 | void* pointer; 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libkroll/osx/nslog_channel.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KROLL_OSX_NSLOG_CHANNEL_ 8 | #define _KROLL_OSX_NSLOG_CHANNEL_ 9 | 10 | #include 11 | #include 12 | #include "Poco/Mutex.h" 13 | //#include "Poco/UnWindows.h" 14 | 15 | namespace kroll 16 | { 17 | class NSLogChannel : public Poco::Channel 18 | { 19 | public: 20 | NSLogChannel(); 21 | void log(const Poco::Message& msg); 22 | 23 | protected: 24 | ~NSLogChannel() {}; 25 | 26 | private: 27 | Poco::PatternFormatter formatter; 28 | }; 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /modules/ruby/ruby_interpreter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _RUBY_INTERPRETER_H_ 8 | #define _RUBY_INTERPRETER_H_ 9 | 10 | #include 11 | 12 | namespace kroll { 13 | 14 | class RubyInterpreter : public Interpreter { 15 | public: 16 | RubyInterpreter(); 17 | 18 | KValueRef EvaluateFile(const char* filepath, KObjectRef context); 19 | 20 | private: 21 | std::string GetContextId(KObjectRef global); 22 | VALUE GetContext(KObjectRef global); 23 | void ContextToGlobal(VALUE ctx, KObjectRef o); 24 | }; 25 | 26 | } // namespace kroll 27 | 28 | #endif -------------------------------------------------------------------------------- /libkroll/api/environment_binding.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _ENVIRONMENT_BINDING_H_ 7 | #define _ENVIRONMENT_BINDING_H_ 8 | 9 | #include 10 | 11 | namespace kroll 12 | { 13 | class EnvironmentBinding : public KObject 14 | { 15 | public: 16 | EnvironmentBinding() : KObject("API.Environment") {} 17 | 18 | virtual KValueRef Get(const char *name); 19 | virtual SharedStringList GetPropertyNames(); 20 | virtual void Set(const char *name, KValueRef value); 21 | virtual SharedString DisplayString(int levels=3); 22 | }; 23 | } 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /modules/php/php_module_instance.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _PHP_MODULE_INSTANCE_H_ 7 | #define _PHP_MODULE_INSTANCE_H_ 8 | 9 | #include "php_module.h" 10 | 11 | namespace kroll 12 | { 13 | class PHPModuleInstance : public Module 14 | { 15 | public: 16 | PHPModuleInstance(Host *host, std::string path, std::string dir, std::string name); 17 | void Initialize(); 18 | void Destroy(); 19 | 20 | protected: 21 | virtual ~PHPModuleInstance(); 22 | 23 | private: 24 | std::string path; 25 | DISALLOW_EVIL_CONSTRUCTORS(PHPModuleInstance); 26 | }; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /libkroll/api/api_module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _API_PLUGIN_H 7 | #define _API_PLUGIN_H 8 | 9 | #include 10 | #include "api_binding.h" 11 | 12 | namespace kroll 13 | { 14 | class KROLL_API APIModule : public Module 15 | { 16 | public: 17 | APIModule(Host* host, const char* path) : 18 | Module(host, path, STRING(MODULE_NAME), STRING(MODULE_VERSION)) 19 | { 20 | 21 | } 22 | 23 | ~APIModule() 24 | { 25 | 26 | } 27 | 28 | void Initialize(); 29 | void Stop(); 30 | 31 | protected: 32 | AutoPtr binding; 33 | }; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /modules/ruby/ruby_module_instance.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _RUBY_MODULE_INSTANCE_H 7 | #define _RUBY_MODULE_INSTANCE_H 8 | 9 | #include "ruby_module.h" 10 | 11 | namespace kroll 12 | { 13 | class RubyModuleInstance : public Module 14 | { 15 | public: 16 | RubyModuleInstance(Host *host, std::string path, std::string dir, std::string name); 17 | protected: 18 | virtual ~RubyModuleInstance(); 19 | public: 20 | void Initialize (); 21 | void Destroy (); 22 | private: 23 | std::string path; 24 | DISALLOW_EVIL_CONSTRUCTORS(RubyModuleInstance); 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libkroll/binding/k_accessor_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_ACCESSOR_BOUND_OBJECT_H_ 8 | #define _KR_ACCESSOR_BOUND_OBJECT_H_ 9 | 10 | namespace kroll 11 | { 12 | class KROLL_API KAccessorObject : public StaticBoundObject, public KAccessor 13 | { 14 | public: 15 | KAccessorObject(const char* name = "KAccessorObject"); 16 | virtual void Set(const char* name, KValueRef value); 17 | virtual KValueRef Get(const char* name); 18 | virtual bool HasProperty(const char* name); 19 | 20 | private: 21 | DISALLOW_EVIL_CONSTRUCTORS(KAccessorObject); 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libkroll/javascript/javascript_module_instance.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _JAVASCRIPT_MODULE_INSTANCE_H_ 7 | #define _JAVASCRIPT_MODULE_INSTANCE_H_ 8 | 9 | namespace kroll 10 | { 11 | class KROLL_API JavaScriptModuleInstance : public Module 12 | { 13 | public: 14 | JavaScriptModuleInstance(Host *host, std::string path, 15 | std::string dir, std::string name); 16 | void Initialize () {} 17 | void Stop(); 18 | void Run(); 19 | static void GarbageCollect(); 20 | 21 | protected: 22 | std::string path; 23 | JSGlobalContextRef context; 24 | JSObjectRef global; 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /modules/python/python_module_instance.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _PYTHON_MODULE_INSTANCE_H 7 | #define _PYTHON_MODULE_INSTANCE_H 8 | 9 | #include "python_module.h" 10 | 11 | namespace kroll 12 | { 13 | class PythonModuleInstance : public Module 14 | { 15 | public: 16 | PythonModuleInstance(Host *host, std::string path, std::string dir, std::string name); 17 | protected: 18 | virtual ~PythonModuleInstance(); 19 | public: 20 | void Initialize (); 21 | void Destroy (); 22 | private: 23 | std::string path; 24 | DISALLOW_EVIL_CONSTRUCTORS(PythonModuleInstance); 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libkroll/memory/README.md: -------------------------------------------------------------------------------- 1 | Memory Management Helpers 2 | ========================= 3 | A collection of memory management helper classes 4 | derived from Chromium base/memory. 5 | 6 | scoped_ptr 7 | ---------- 8 | Scopers help you manage ownership of a pointer, helping you easily manage the 9 | a pointer within a scope, and automatically destroying the pointer at the 10 | end of a scope. There are two main classes you will use, which correspond 11 | to the operators new/delete and new[]/delete[]. 12 | 13 | Should be used when ownership is linked to a single object or function. 14 | 15 | Example: 16 | ``` C++ 17 | // Pointer is released once foo goes out of scope. 18 | scoped_ptr foo(new Foo("wee")); 19 | ``` 20 | 21 | Credit 22 | ------ 23 | Thanks to the Chromium project! 24 | 25 | http://www.chromium.org/ 26 | 27 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # --Common SConscripts-- 3 | # Things below here will be shared between Kroll and 4 | # any parent builds (ie Titanium) -- so basically no 5 | # Kroll-specific stuff below here 6 | import os.path as path 7 | Import('build') 8 | Import('debug') 9 | 10 | SConscript('boot/SConscript', variant_dir=path.join(build.dir, 'objs', 'boot'), duplicate=0) 11 | SConscript('libkroll/SConscript', variant_dir=path.join(build.dir,'objs','libkroll'), duplicate=0) 12 | 13 | # Now that libkroll is built add it as a default for 14 | # all the following build steps. This means that things 15 | # that should not depend on libkroll should be built 16 | # before here. 17 | build.env.Append(LIBS=['khost']) 18 | build.env.Append(LIBPATH=[build.runtime_build_dir]) 19 | 20 | SConscript('modules/SConscript') 21 | -------------------------------------------------------------------------------- /modules/ruby/ruby_module_instance.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "ruby_module_instance.h" 7 | 8 | namespace kroll 9 | { 10 | // TODO: Implement real method metadata and lifecycle events for 11 | // scripting language-based modules 12 | RubyModuleInstance::RubyModuleInstance(Host* host, std::string path, std::string dir, std::string name) : 13 | Module(host, dir.c_str(), name.c_str(), "0.1"), path(path) 14 | { 15 | } 16 | 17 | RubyModuleInstance::~RubyModuleInstance() 18 | { 19 | } 20 | 21 | void RubyModuleInstance::Initialize () 22 | { 23 | } 24 | 25 | void RubyModuleInstance::Destroy () 26 | { 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /modules/python/python_module_instance.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "python_module_instance.h" 7 | 8 | namespace kroll 9 | { 10 | // TODO: Implement real method metadata and lifecycle events for 11 | // scripting language-based modules 12 | PythonModuleInstance::PythonModuleInstance(Host *host, std::string path, std::string dir, std::string name) : 13 | Module(host, dir.c_str(), name.c_str(), "0.1"), 14 | path(path) 15 | { 16 | } 17 | 18 | PythonModuleInstance::~PythonModuleInstance() 19 | { 20 | } 21 | 22 | void PythonModuleInstance::Initialize () 23 | { 24 | } 25 | 26 | void PythonModuleInstance::Destroy () 27 | { 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /modules/python/k_python_dict.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PYTHON_DICT_H_ 8 | #define _K_PYTHON_DICT_H_ 9 | 10 | #include "python_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPythonDict : public KObject 15 | { 16 | public: 17 | KPythonDict(PyObject *obj); 18 | virtual ~KPythonDict(); 19 | 20 | virtual void Set(const char *name, KValueRef value); 21 | virtual KValueRef Get(const char *name); 22 | virtual bool Equals(KObjectRef); 23 | virtual SharedStringList GetPropertyNames(); 24 | 25 | PyObject* ToPython(); 26 | 27 | private: 28 | PyObject *object; 29 | DISALLOW_EVIL_CONSTRUCTORS(KPythonDict); 30 | }; 31 | } 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /libkroll/reference_counted.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_REFERENCE_COUNTED_H_ 7 | #define _KR_REFERENCE_COUNTED_H_ 8 | 9 | namespace kroll 10 | { 11 | class KROLL_API ReferenceCounted 12 | { 13 | private: 14 | Poco::AtomicCounter count; 15 | 16 | public: 17 | ReferenceCounted() : count(1) { } 18 | virtual ~ReferenceCounted() { } 19 | 20 | virtual void duplicate() 21 | { 22 | ++count; 23 | } 24 | 25 | virtual void release() 26 | { 27 | int value = --count; 28 | if (value <= 0) { 29 | delete this; 30 | } 31 | } 32 | 33 | virtual int referenceCount() const 34 | { 35 | return count.value(); 36 | } 37 | }; 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /libkroll/binding/k_accessor_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_ACCESSOR_BOUND_LIST_H_ 8 | #define _KR_ACCESSOR_BOUND_LIST_H_ 9 | 10 | namespace kroll 11 | { 12 | /** 13 | * The KAccessorList allows you to expose getters and setters as property access. 14 | * @see KAccessorObject 15 | */ 16 | class KROLL_API KAccessorList : public StaticBoundList, public KAccessor 17 | { 18 | public: 19 | KAccessorList(const char* type = "KAccessorList"); 20 | virtual void Set(const char* name, KValueRef value); 21 | virtual KValueRef Get(const char* name); 22 | virtual bool HasProperty(const char* name); 23 | 24 | private: 25 | DISALLOW_EVIL_CONSTRUCTORS(KAccessorList); 26 | }; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /modules/php/k_php_object.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _K_PHP_OBJECT_H_ 7 | #define _K_PHP_OBJECT_H_ 8 | 9 | namespace kroll 10 | { 11 | class KPHPObject : public KObject 12 | { 13 | public: 14 | KPHPObject(zval* object); 15 | virtual ~KPHPObject(); 16 | 17 | virtual void Set(const char *name, KValueRef value); 18 | virtual KValueRef Get(const char *name); 19 | virtual SharedStringList GetPropertyNames(); 20 | virtual SharedString DisplayString(int); 21 | virtual bool Equals(KObjectRef); 22 | bool PropertyExists(const char* property TSRMLS_DC); 23 | bool MethodExists(const char* methodName TSRMLS_DC); 24 | zval* ToPHP(); 25 | 26 | private: 27 | zval* object; 28 | 29 | }; 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /libkroll/binding/k_accessor_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_ACCESSOR_BOUND_METHOD_H_ 8 | #define _KR_ACCESSOR_BOUND_METHOD_H_ 9 | 10 | namespace kroll 11 | { 12 | /** 13 | * The KAccessorMethod allows you to expose getters and setters as property access. 14 | * @see KAccessorObject 15 | */ 16 | class KROLL_API KAccessorMethod : public StaticBoundMethod, public KAccessor 17 | { 18 | public: 19 | KAccessorMethod(MethodCallback* callback, const char* type = "KAccessorMethod"); 20 | virtual void Set(const char* name, KValueRef value); 21 | virtual KValueRef Get(const char* name); 22 | virtual bool HasProperty(const char* name); 23 | 24 | private: 25 | DISALLOW_EVIL_CONSTRUCTORS(KAccessorMethod); 26 | }; 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /libkroll/binding/global_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_GLOBAL_OBJECT_H_ 8 | #define _KR_GLOBAL_OBJECT_H_ 9 | 10 | namespace kroll 11 | { 12 | class KROLL_API GlobalObject : public KEventObject 13 | { 14 | public: 15 | GlobalObject(); 16 | ~GlobalObject(); 17 | static void TurnOnProfiling(); 18 | 19 | inline static AutoPtr GetInstance() 20 | { 21 | return GlobalObject::instance; 22 | } 23 | 24 | inline static void Initialize() 25 | { 26 | instance = new GlobalObject(); 27 | } 28 | 29 | private: 30 | static AutoPtr instance; 31 | 32 | void GetVersion(const ValueList& args, KValueRef result); 33 | void GetPlatform(const ValueList& args, KValueRef result); 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /libkroll/binding/k_accessor_list.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | 11 | namespace kroll 12 | { 13 | KAccessorList::KAccessorList(const char* type) 14 | : StaticBoundList(type) 15 | { 16 | } 17 | 18 | bool KAccessorList::HasProperty(const char* name) 19 | { 20 | return StaticBoundList::HasProperty(name) || this->HasGetterFor(name); 21 | } 22 | 23 | void KAccessorList::Set(const char* name, KValueRef value) 24 | { 25 | if (!this->UseSetter(name, value, StaticBoundList::Get(name))) 26 | StaticBoundList::Set(name, value); 27 | } 28 | 29 | KValueRef KAccessorList::Get(const char* name) 30 | { 31 | return this->UseGetter(name, StaticBoundList::Get(name)); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /libkroll/binding/profiled_global_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_PROFILED_GLOBAL_OBJECT_H_ 8 | #define _KR_PROFILED_GLOBAL_OBJECT_H_ 9 | 10 | namespace kroll 11 | { 12 | class KROLL_API ProfiledGlobalObject : public GlobalObject 13 | { 14 | public: 15 | ProfiledGlobalObject(KObjectRef delegate); 16 | virtual ~ProfiledGlobalObject(); 17 | 18 | virtual void Set(const char *name, KValueRef value); 19 | virtual KValueRef Get(const char *name); 20 | virtual SharedStringList GetPropertyNames(); 21 | virtual SharedString DisplayString(int levels=3); 22 | virtual bool Equals(KObjectRef other); 23 | bool HasProperty(const char* name); 24 | 25 | protected: 26 | AutoPtr profiledObject; 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libkroll/Interpreter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Appcelerator, Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef Interpreter_h 18 | #define Interpreter_h 19 | 20 | namespace kroll { 21 | 22 | class Interpreter { 23 | public: 24 | virtual KValueRef EvaluateFile(const char* filepath, KObjectRef context) = 0; 25 | }; 26 | 27 | } // namespace kroll 28 | 29 | #endif -------------------------------------------------------------------------------- /libkroll/api/dependency_binding.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _DEPENDENCY_BINDING_H_ 7 | #define _DEPENDENCY_BINDING_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace kroll 15 | { 16 | class DependencyBinding : public KAccessorObject 17 | { 18 | public: 19 | DependencyBinding(SharedDependency dependency); 20 | SharedDependency GetDependency(); 21 | 22 | private: 23 | SharedDependency dependency; 24 | 25 | void _GetType(const ValueList& args, KValueRef value); 26 | void _GetName(const ValueList& args, KValueRef value);; 27 | void _GetVersion(const ValueList& args, KValueRef value); 28 | void _GetRequirement(const ValueList& args, KValueRef value); 29 | }; 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /modules/python/k_python_object.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PYTHON_OBJECT_H_ 8 | #define _K_PYTHON_OBJECT_H_ 9 | 10 | #include "python_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPythonObject : public KObject 15 | { 16 | public: 17 | KPythonObject(PyObject *obj); 18 | KPythonObject(PyObject *obj, bool readOnly); 19 | virtual ~KPythonObject(); 20 | 21 | virtual void Set(const char *name, KValueRef value); 22 | virtual KValueRef Get(const char *name); 23 | virtual bool Equals(KObjectRef); 24 | virtual SharedStringList GetPropertyNames(); 25 | PyObject* ToPython(); 26 | 27 | private: 28 | PyObject *object; 29 | bool readOnly; 30 | KObjectRef delegate; 31 | DISALLOW_EVIL_CONSTRUCTORS(KPythonObject); 32 | }; 33 | } 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /libkroll/binding/k_accessor_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | 11 | namespace kroll 12 | { 13 | KAccessorObject::KAccessorObject(const char* name) 14 | : StaticBoundObject(name) 15 | { 16 | } 17 | 18 | bool KAccessorObject::HasProperty(const char* name) 19 | { 20 | return StaticBoundObject::HasProperty(name) || this->HasGetterFor(name); 21 | } 22 | 23 | void KAccessorObject::Set(const char* name, KValueRef value) 24 | { 25 | if (!this->UseSetter(name, value, StaticBoundObject::Get(name))) 26 | StaticBoundObject::Set(name, value); 27 | } 28 | 29 | KValueRef KAccessorObject::Get(const char* name) 30 | { 31 | return this->UseGetter(name, StaticBoundObject::Get(name)); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /modules/python/k_python_method.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PYTHON_METHOD_H_ 8 | #define _K_PYTHON_METHOD_H_ 9 | 10 | #include "python_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPythonObject; 15 | class KPythonMethod : public KMethod 16 | { 17 | public: 18 | KPythonMethod(PyObject *obj); 19 | virtual ~KPythonMethod(); 20 | 21 | KValueRef Call(const ValueList& args); 22 | virtual void Set(const char *name, KValueRef value); 23 | virtual KValueRef Get(const char *name); 24 | virtual bool Equals(KObjectRef); 25 | virtual SharedStringList GetPropertyNames(); 26 | PyObject* ToPython(); 27 | 28 | private: 29 | PyObject* method; 30 | AutoPtr object; 31 | DISALLOW_EVIL_CONSTRUCTORS(KPythonMethod); 32 | }; 33 | } 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /libkroll/main_thread_job.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _MAIN_THREAD_JOB_H 7 | #define _MAIN_THREAD_JOB_H 8 | 9 | #include 10 | 11 | namespace kroll 12 | { 13 | class KROLL_API MainThreadJob 14 | { 15 | public: 16 | MainThreadJob(KMethodRef method, KObjectRef thisObject, 17 | const ValueList& args, bool waitForCompletion); 18 | void Lock(); 19 | void Wait(); 20 | void Execute(); 21 | KValueRef GetResult(); 22 | ValueException GetException(); 23 | bool ShouldWaitForCompletion(); 24 | void PrintException(); 25 | 26 | private: 27 | KMethodRef method; 28 | KObjectRef thisObject; 29 | const ValueList args; 30 | bool waitForCompletion; 31 | KValueRef returnValue; 32 | ValueException exception; 33 | Poco::Semaphore semaphore; 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /modules/python/python_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef PYTHON_TYPES_H_ 7 | #define PYTHON_TYPES_H_ 8 | 9 | #include 10 | #include "python_module.h" 11 | 12 | namespace kroll 13 | { 14 | class PythonUtils 15 | { 16 | public: 17 | static void InitializePythonKClasses(); 18 | static KValueRef ToKrollValue(PyObject* value); 19 | static PyObject* ToPyObject(KValueRef value); 20 | static PyObject* ToPyObject(const ValueList& list); 21 | static const char* ToString(PyObject* value); 22 | static PyObject* KObjectToPyObject(KValueRef o); 23 | static PyObject* KMethodToPyObject(KValueRef o); 24 | static PyObject* KListToPyObject(KValueRef o); 25 | static std::string PythonErrorToString(); 26 | 27 | private: 28 | PythonUtils() {} 29 | ~PythonUtils () {} 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libkroll/binding/k_accessor_method.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | 11 | namespace kroll 12 | { 13 | KAccessorMethod::KAccessorMethod(MethodCallback* callback, const char *type) 14 | : StaticBoundMethod(callback, type) 15 | { 16 | } 17 | 18 | bool KAccessorMethod::HasProperty(const char* name) 19 | { 20 | return StaticBoundMethod::HasProperty(name) || this->HasGetterFor(name); 21 | } 22 | 23 | void KAccessorMethod::Set(const char* name, KValueRef value) 24 | { 25 | if (!this->UseSetter(name, value, StaticBoundMethod::Get(name))) 26 | StaticBoundMethod::Set(name, value); 27 | } 28 | 29 | KValueRef KAccessorMethod::Get(const char* name) 30 | { 31 | return this->UseGetter(name, StaticBoundMethod::Get(name)); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /libkroll/win32/event_window.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _HOST_EVENT_WINDOW_H 7 | #define _HOST_EVENT_WINDOW_H 8 | 9 | #include 10 | #include 11 | 12 | typedef bool (*MessageHandler)(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam); 13 | 14 | namespace kroll 15 | { 16 | class Logger; 17 | class EventWindow 18 | { 19 | public: 20 | EventWindow(); 21 | virtual ~EventWindow(); 22 | void DestroyWindow(); 23 | HWND AddMessageHandler(MessageHandler handler); 24 | LRESULT CALLBACK Handler( 25 | HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam); 26 | HWND GetHandle() { return handle; } 27 | 28 | private: 29 | HWND handle; 30 | Logger* logger; 31 | std::vector handlers; 32 | Poco::Mutex handlersMutex; 33 | }; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /modules/php/k_php_function.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _K_PHP_FUNCTION_H_ 7 | #define _K_PHP_FUNCTION_H_ 8 | 9 | namespace kroll 10 | { 11 | class KPHPFunction : public KMethod 12 | { 13 | public: 14 | KPHPFunction(const char *functionName); 15 | 16 | virtual ~KPHPFunction(); 17 | KValueRef Call(const ValueList& args); 18 | virtual void Set(const char *name, KValueRef value); 19 | virtual KValueRef Get(const char *name); 20 | virtual SharedStringList GetPropertyNames(); 21 | virtual SharedString DisplayString(int); 22 | virtual bool Equals(KObjectRef); 23 | bool PropertyExists(const char* property); 24 | 25 | inline std::string& GetMethodName() { return methodName; } 26 | 27 | private: 28 | std::string methodName; 29 | zval* zMethodName; 30 | KObjectRef globalObject; 31 | }; 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /modules/php/k_php_method.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _K_PHP_METHOD_H_ 7 | #define _K_PHP_METHOD_H_ 8 | 9 | namespace kroll 10 | { 11 | class KPHPMethod : public KMethod 12 | { 13 | public: 14 | KPHPMethod(zval* object, const char* methodName); 15 | KPHPMethod(const char *functionName); 16 | 17 | virtual ~KPHPMethod(); 18 | KValueRef Call(const ValueList& args); 19 | virtual void Set(const char *name, KValueRef value); 20 | virtual KValueRef Get(const char *name); 21 | virtual SharedStringList GetPropertyNames(); 22 | virtual SharedString DisplayString(int); 23 | virtual bool Equals(KObjectRef); 24 | bool PropertyExists(const char* property); 25 | zval* ToPHP(); 26 | 27 | private: 28 | zval* object; 29 | char* methodName; 30 | zval* zMethodName; 31 | KObjectRef globalObject; 32 | }; 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /libkroll/api/component_binding.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _COMPONENT_BINDING_H_ 8 | #define _COMPONENT_BINDING_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace kroll 16 | { 17 | class ComponentBinding : public KAccessorObject 18 | { 19 | public: 20 | ComponentBinding(SharedComponent component); 21 | 22 | private: 23 | SharedComponent component; 24 | 25 | void _GetType(const ValueList& args, KValueRef value); 26 | void _GetName(const ValueList& args, KValueRef value); 27 | void _GetVersion(const ValueList& args, KValueRef value); 28 | void _GetPath(const ValueList& args, KValueRef value); 29 | void _IsBundled(const ValueList& args, KValueRef value); 30 | void _IsLoaded(const ValueList& args, KValueRef value); 31 | }; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /modules/python/SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os import path 3 | Import('build env module') 4 | 5 | env.Append(CPPDEFINES=('KROLL_PYTHON_API_EXPORT', 1)) 6 | 7 | build.add_thirdparty(env, 'poco') 8 | if build.is_osx(): 9 | env.Append(CPPPATH=['/System/Library/Frameworks/Python.framework/Versions/Current/Headers',build.kroll_include_dir]) 10 | env.Append(FRAMEWORKS=['Python']) 11 | 12 | elif build.is_linux(): 13 | env.Append(CPPPATH=[ 14 | '${PYTHON_INCLUDE}', 15 | #'/usr/lib/python/2.5/i386-linux', 16 | #'/usr/include/python2.5', 17 | build.kroll_include_dir]) 18 | env.Append(LIBS=['python${PYTHON_VERSION}']) 19 | 20 | elif build.is_win32(): 21 | env.Append(CPPPATH=[build.tp('python', 'include')]) 22 | env.Append(LIBPATH=[build.tp('python', 'libs')]) 23 | env.Append(LIBS=['python25']) 24 | env.Append(CCFLAGS = ['/MD']) 25 | 26 | build.mark_build_target(env.SharedLibrary( 27 | path.join(module.dir, 'pythonmodule'), Glob('*.cpp'))) 28 | if build.is_win32(): 29 | build.utils.LightWeightCopy(build.tp('python'), module.dir) 30 | -------------------------------------------------------------------------------- /libkroll/binding/k_function_ptr_method.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | 9 | namespace kroll 10 | { 11 | KFunctionPtrMethod::KFunctionPtrMethod(KFunctionPtrCallback callback) : 12 | callback(callback) 13 | { 14 | this->object = new StaticBoundObject(); 15 | } 16 | 17 | KFunctionPtrMethod::~KFunctionPtrMethod() 18 | { 19 | } 20 | 21 | KValueRef KFunctionPtrMethod::Call(const ValueList& args) 22 | { 23 | return this->callback(args); 24 | } 25 | 26 | void KFunctionPtrMethod::Set(const char *name, KValueRef value) 27 | { 28 | this->object->Set(name, value); 29 | } 30 | 31 | KValueRef KFunctionPtrMethod::Get(const char *name) 32 | { 33 | return this->object->Get(name); 34 | } 35 | 36 | SharedStringList KFunctionPtrMethod::GetPropertyNames() 37 | { 38 | return this->object->GetPropertyNames(); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /modules/ruby/ruby_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef RUBY_TYPES_H_ 7 | #define RUBY_TYPES_H_ 8 | 9 | #include 10 | #include "ruby_module.h" 11 | 12 | namespace kroll 13 | { 14 | class RubyUtils 15 | { 16 | public: 17 | static KValueRef ToKrollValue(VALUE value); 18 | static VALUE ToRubyValue(KValueRef value); 19 | static VALUE KObjectToRubyValue(KValueRef value); 20 | static VALUE KMethodToRubyValue(KValueRef value); 21 | static VALUE KListToRubyValue(KValueRef value); 22 | static bool KindOf(VALUE value, VALUE klass); 23 | 24 | static ValueException GetException(); 25 | static VALUE GenericKMethodCall(KMethodRef method, VALUE args); 26 | 27 | private: 28 | static VALUE KObjectClass; 29 | static VALUE KMethodClass; 30 | static VALUE KListClass; 31 | RubyUtils(){} 32 | ~RubyUtils(){} 33 | }; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /modules/python/k_python_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PYTHON_LIST_H_ 8 | #define _K_PYTHON_LIST_H_ 9 | 10 | #include "python_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPythonList : public KList 15 | { 16 | public: 17 | KPythonList(PyObject *obj); 18 | virtual ~KPythonList(); 19 | 20 | KValueRef Get(const char* name); 21 | void Set(const char* name, KValueRef value); 22 | virtual bool Equals(KObjectRef); 23 | SharedStringList GetPropertyNames(); 24 | 25 | unsigned int Size(); 26 | void Append(KValueRef value); 27 | virtual void SetAt(unsigned int index, KValueRef value); 28 | bool Remove(unsigned int index); 29 | KValueRef At(unsigned int index); 30 | 31 | PyObject* ToPython(); 32 | 33 | protected: 34 | PyObject *list; 35 | AutoPtr object; 36 | DISALLOW_EVIL_CONSTRUCTORS(KPythonList); 37 | }; 38 | } 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /modules/ruby/k_ruby_object.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_RUBY_OBJECT_H_ 8 | #define _K_RUBY_OBJECT_H_ 9 | 10 | namespace kroll { 11 | 12 | class KRubyObject : public KObject { 13 | public: 14 | KRubyObject(VALUE object); 15 | virtual ~KRubyObject(); 16 | 17 | virtual void Set(const char *name, KValueRef value); 18 | virtual KValueRef Get(const char *name); 19 | 20 | virtual SharedStringList GetPropertyNames(); 21 | virtual SharedString DisplayString(int); 22 | VALUE ToRuby(); 23 | 24 | /* 25 | * Determine if the given Ruby object equals this one 26 | * by comparing these objects's identity e.g. equals?() 27 | * @param other the object to test 28 | * @returns true if objects have reference equality, false otherwise 29 | */ 30 | virtual bool Equals(KObjectRef); 31 | 32 | private: 33 | VALUE object; 34 | 35 | }; 36 | 37 | } 38 | 39 | #endif /* RUBY_BOUND_OBJECT_H_ */ 40 | -------------------------------------------------------------------------------- /modules/python/k_python_tuple.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PYTHON_TUPLE_H_ 8 | #define _K_PYTHON_TUPLE_H_ 9 | 10 | #include "python_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPythonTuple : public KList 15 | { 16 | public: 17 | KPythonTuple(PyObject *obj); 18 | virtual ~KPythonTuple(); 19 | 20 | KValueRef Get(const char *name); 21 | void Set(const char *name, KValueRef value); 22 | virtual bool Equals(KObjectRef); 23 | SharedStringList GetPropertyNames(); 24 | 25 | unsigned int Size(); 26 | void Append(KValueRef value); 27 | virtual void SetAt(unsigned int index, KValueRef value); 28 | bool Remove(unsigned int index); 29 | KValueRef At(unsigned int index); 30 | 31 | PyObject* ToPython(); 32 | 33 | protected: 34 | PyObject *tuple; 35 | AutoPtr object; 36 | DISALLOW_EVIL_CONSTRUCTORS(KPythonTuple); 37 | }; 38 | } 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /libkroll/binding/global_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | 9 | namespace kroll 10 | { 11 | AutoPtr GlobalObject::instance; 12 | 13 | GlobalObject::GlobalObject() : 14 | KEventObject(PRODUCT_NAME) 15 | { 16 | this->SetMethod("getVersion", &GlobalObject::GetVersion); 17 | this->SetMethod("getPlatform", &GlobalObject::GetPlatform); 18 | 19 | Event::SetEventConstants(this); 20 | } 21 | 22 | GlobalObject::~GlobalObject() 23 | { 24 | 25 | } 26 | 27 | void GlobalObject::GetVersion(const ValueList& args, KValueRef result) 28 | { 29 | result->SetString(PRODUCT_VERSION); 30 | } 31 | 32 | void GlobalObject::GetPlatform(const ValueList& args, KValueRef result) 33 | { 34 | result->SetString(OS_NAME); 35 | } 36 | 37 | /*static*/ 38 | void GlobalObject::TurnOnProfiling() 39 | { 40 | instance = new ProfiledGlobalObject(instance); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /modules/ruby/k_ruby_hash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_RUBY_HASH_H_ 8 | #define _K_RUBY_HASH_H_ 9 | 10 | namespace kroll { 11 | 12 | class KRubyHash : public KObject { 13 | public: 14 | KRubyHash(VALUE object); 15 | virtual ~KRubyHash(); 16 | 17 | virtual void Set(const char *name, KValueRef value); 18 | virtual KValueRef Get(const char *name); 19 | virtual SharedStringList GetPropertyNames(); 20 | virtual SharedString DisplayString(int); 21 | VALUE ToRuby(); 22 | 23 | /* 24 | * Determine if the given Ruby object equals this one 25 | * by comparing these objects's identity e.g. equals?() 26 | * @param other the object to test 27 | * @returns true if objects have reference equality, false otherwise 28 | */ 29 | virtual bool Equals(KObjectRef); 30 | 31 | private: 32 | VALUE hash; 33 | AutoPtr object; 34 | 35 | }; 36 | 37 | } 38 | 39 | #endif /* RUBY_BOUND_OBJECT_H_ */ 40 | -------------------------------------------------------------------------------- /tools/upload_thirdparty.py: -------------------------------------------------------------------------------- 1 | from boto.s3.connection import S3Connection 2 | from boto.s3.key import Key 3 | from progressbar import ProgressBar 4 | import sys 5 | import os 6 | import time 7 | 8 | acctid = None 9 | secret = None 10 | if len(sys.argv) < 2: 11 | print "Usage: upload_thirdparty.py [ ]" 12 | exit() 13 | else: 14 | fname = sys.argv[1] 15 | if len(sys.argv) >= 4: 16 | acctid = sys.argv[2] 17 | secret = sys.argv[3] 18 | 19 | if acctid is None: 20 | acctid = raw_input("AWS_ACCESS_KEY_ID: ").strip() 21 | 22 | if secret is None: 23 | secret = raw_input("AWS_SECRET_ACCESS_KEY: ").strip() 24 | 25 | bucket = "kroll.appcelerator.com" 26 | key = os.path.basename(fname) 27 | conn = S3Connection(acctid, secret) 28 | bucket = conn.get_bucket(bucket) 29 | k = bucket.new_key(key) 30 | 31 | pbar = ProgressBar().start() 32 | try: 33 | def progress_callback(current, total): 34 | pbar.update(int(100 * (float(current) / float(total)))) 35 | k.set_contents_from_filename(fname, cb=progress_callback, num_cb=100, policy='public-read') 36 | finally: 37 | pbar.finish() 38 | -------------------------------------------------------------------------------- /libkroll/javascript/k_kjs_object.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KJS_KOBJECT_H_ 8 | #define _KJS_KOBJECT_H_ 9 | 10 | #include "javascript_module.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace kroll 17 | { 18 | class KROLL_API KKJSObject : public KObject 19 | { 20 | public: 21 | KKJSObject(JSContextRef context, JSObjectRef js_object); 22 | ~KKJSObject(); 23 | 24 | virtual void Set(const char *name, KValueRef value); 25 | virtual KValueRef Get(const char *name); 26 | virtual SharedStringList GetPropertyNames(); 27 | virtual bool HasProperty(const char* name); 28 | virtual bool Equals(KObjectRef); 29 | 30 | bool SameContextGroup(JSContextRef c); 31 | JSObjectRef GetJSObject(); 32 | 33 | protected: 34 | JSGlobalContextRef context; 35 | JSObjectRef jsobject; 36 | 37 | private: 38 | DISALLOW_EVIL_CONSTRUCTORS(KKJSObject); 39 | }; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libkroll/utils/platform_utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "utils.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace UTILS_NS 13 | { 14 | namespace PlatformUtils 15 | { 16 | std::string GetFirstMACAddress() 17 | { 18 | MACAddress address; 19 | memset(&address, 0, sizeof(MACAddress)); 20 | 21 | try 22 | { 23 | PlatformUtils::GetFirstMACAddressImpl(address); 24 | } 25 | catch(...) 26 | { 27 | // Just return zeros. 28 | } 29 | 30 | char result[18]; 31 | std::sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x", 32 | address[0], address[1], address[2], address[3], 33 | address[4], address[5]); 34 | return std::string(result); 35 | } 36 | 37 | std::string GetMachineId() 38 | { 39 | static std::string machineID; 40 | if (machineID.empty()) 41 | machineID = DataUtils::HexMD5(GetFirstMACAddress()); 42 | return machineID; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /libkroll/binding/static_bound_method.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | 9 | namespace kroll 10 | { 11 | StaticBoundMethod::StaticBoundMethod(MethodCallback* callback, const char *type) 12 | : KMethod(type), callback(callback) 13 | { 14 | this->object = new StaticBoundObject(); 15 | } 16 | 17 | StaticBoundMethod::~StaticBoundMethod() 18 | { 19 | } 20 | 21 | KValueRef StaticBoundMethod::Call(const ValueList& args) 22 | { 23 | KValueRef tv = Value::NewUndefined(); 24 | if (this->callback) 25 | { 26 | this->callback->Run(args, tv); 27 | } 28 | return tv; 29 | } 30 | 31 | void StaticBoundMethod::Set(const char *name, KValueRef value) 32 | { 33 | this->object->Set(name, value); 34 | } 35 | 36 | KValueRef StaticBoundMethod::Get(const char *name) 37 | { 38 | return this->object->Get(name); 39 | } 40 | 41 | SharedStringList StaticBoundMethod::GetPropertyNames() 42 | { 43 | return this->object->GetPropertyNames(); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /libkroll/binding/stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Appcelerator, Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef Stream_h 18 | #define Stream_h 19 | 20 | namespace kroll { 21 | 22 | class KROLL_API Stream : public StaticBoundObject { 23 | public: 24 | Stream(const char* type = "Stream"); 25 | virtual ~Stream(); 26 | 27 | virtual void Write(const char* buffer, size_t size); 28 | virtual bool IsWritable() const; 29 | virtual size_t Read(const char* buffer, size_t size); 30 | virtual bool IsReadable() const; 31 | }; 32 | 33 | } // namespace kroll 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /libkroll/binding/value_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_VALUE_EXCEPTION_H_ 8 | #define _KR_VALUE_EXCEPTION_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace kroll 15 | { 16 | 17 | #ifndef OS_WIN32 18 | #pragma GCC visibility push(default) 19 | #endif 20 | 21 | class KROLL_API ValueException : public std::exception 22 | { 23 | public: 24 | ValueException(KValueRef v); 25 | ~ValueException() throw (); 26 | 27 | public: 28 | static ValueException FromString(const char* s); 29 | static ValueException FromString(std::string s); 30 | static ValueException FromFormat(const char* format, ...); 31 | static ValueException FromObject(KObjectRef o); 32 | KValueRef GetValue(); 33 | SharedString DisplayString(); 34 | std::string& ToString(); 35 | 36 | private: 37 | KValueRef value; 38 | std::string displayString; 39 | }; 40 | 41 | #ifndef OS_WIN32 42 | #pragma GCC visibility pop 43 | #endif 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libkroll/win32/com_reference_counted.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_COM_REFERENCE_COUNTED_H_ 7 | #define _KR_COM_REFERENCE_COUNTED_H_ 8 | #include 9 | /* 10 | * This is a COM-specific wrapper of ReferenceCounted. 11 | */ 12 | namespace kroll 13 | { 14 | class KROLL_API COMReferenceCounted : public ReferenceCounted, public IUnknown 15 | { 16 | public: 17 | // IUnknown 18 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) 19 | { 20 | *ppvObject = 0; 21 | if (IsEqualGUID(riid, IID_IUnknown)) 22 | { 23 | *ppvObject = static_cast(this); 24 | } 25 | else 26 | { 27 | return E_NOINTERFACE; 28 | } 29 | return S_OK; 30 | } 31 | 32 | virtual ULONG STDMETHODCALLTYPE AddRef(void) 33 | { 34 | duplicate(); 35 | return referenceCount(); 36 | } 37 | 38 | virtual ULONG STDMETHODCALLTYPE Release(void) 39 | { 40 | release(); 41 | return referenceCount(); 42 | } 43 | }; 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /libkroll/utils/environment_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_ENVIRONMENT_UTILS_H_ 7 | #define _KR_ENVIRONMENT_UTILS_H_ 8 | #include 9 | 10 | namespace UTILS_NS 11 | { 12 | 13 | namespace EnvironmentUtils 14 | { 15 | /* 16 | * @returns whether or not the named environment variable exists. 17 | */ 18 | KROLL_API bool Has(std::string name); 19 | 20 | /* 21 | * @returns the given environment variable or empty string if it does 22 | * not exist. 23 | */ 24 | KROLL_API std::string Get(std::string name); 25 | 26 | /* 27 | * Set an environment variable given a value and a name 28 | */ 29 | KROLL_API void Set(std::string name, std::string value); 30 | 31 | /* 32 | * Unset an environment variable given a name 33 | */ 34 | KROLL_API void Unset(std::string name); 35 | 36 | #if defined(KROLL_API_EXPORT) || defined(_KROLL_H_) 37 | /* 38 | * Get the environment 39 | */ 40 | KROLL_API std::map GetEnvironment(); 41 | #endif 42 | }; 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /libkroll/binding/k_function_ptr_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_FUNCTION_PTR_METHOD_H_ 8 | #define _KR_FUNCTION_PTR_METHOD_H_ 9 | 10 | namespace kroll 11 | { 12 | 13 | typedef KValueRef (*KFunctionPtrCallback) (const ValueList& args); 14 | class KROLL_API KFunctionPtrMethod : public KMethod 15 | { 16 | public: 17 | KFunctionPtrMethod(KFunctionPtrCallback); 18 | virtual ~KFunctionPtrMethod(); 19 | 20 | /** 21 | * @see KMethod::Call 22 | */ 23 | virtual KValueRef Call(const ValueList& args); 24 | 25 | /** 26 | * @see KObject::Set 27 | */ 28 | virtual void Set(const char *name, KValueRef value); 29 | 30 | /** 31 | * @see KObject::Get 32 | */ 33 | virtual KValueRef Get(const char *name); 34 | 35 | /** 36 | * @see KObject::GetPropertyNames 37 | */ 38 | virtual SharedStringList GetPropertyNames(); 39 | 40 | 41 | protected: 42 | KFunctionPtrCallback callback; 43 | KObjectRef object; 44 | 45 | private: 46 | DISALLOW_EVIL_CONSTRUCTORS(KFunctionPtrMethod); 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /modules/ruby/k_ruby_method.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_RUBY_METHOD_H_ 8 | #define _K_RUBY_METHOD_H_ 9 | 10 | namespace kroll { 11 | 12 | class KRubyMethod : public KMethod 13 | { 14 | public: 15 | KRubyMethod(VALUE method); 16 | KRubyMethod(VALUE method, const char*); 17 | KRubyMethod(VALUE method, VALUE arg); 18 | virtual ~KRubyMethod(); 19 | KValueRef Call(const ValueList& args); 20 | virtual void Set(const char *name, KValueRef value); 21 | virtual KValueRef Get(const char *name); 22 | virtual SharedStringList GetPropertyNames(); 23 | virtual SharedString DisplayString(int); 24 | VALUE ToRuby(); 25 | 26 | /* 27 | * Determine if the given Ruby object equals this one 28 | * by comparing these objects's identity e.g. equals?() 29 | * @param other the object to test 30 | * @returns true if objects have reference equality, false otherwise 31 | */ 32 | virtual bool Equals(KObjectRef); 33 | 34 | private: 35 | VALUE method; 36 | VALUE arg; 37 | AutoPtr object; 38 | char* name; 39 | }; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /modules/php/k_php_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PHP_LIST_H_ 8 | #define _K_PHP_LIST_H_ 9 | 10 | #include "php_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPHPList : public KList 15 | { 16 | public: 17 | KPHPList(zval *list); 18 | virtual ~KPHPList(); 19 | 20 | KValueRef Get(const char* name); 21 | void Set(const char* name, KValueRef value); 22 | virtual bool Equals(KObjectRef); 23 | SharedStringList GetPropertyNames(); 24 | 25 | unsigned int Size(); 26 | void Append(KValueRef value); 27 | virtual void SetAt(unsigned int index, KValueRef value); 28 | bool Remove(unsigned int index); 29 | KValueRef At(unsigned int index); 30 | 31 | zval* ToPHP(); 32 | 33 | protected: 34 | zval *list; 35 | 36 | static void AddKrollValueToPHPArray(KValueRef value, zval *phpArray, const char* key); 37 | static void AddKrollValueToPHPArray(KValueRef value, zval *phpArray, unsigned int index); 38 | static void AddKrollValueToPHPArray(KValueRef value, zval *phpArray); 39 | DISALLOW_EVIL_CONSTRUCTORS(KPHPList); 40 | }; 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /modules/ruby/SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os import path 3 | Import('build env module') 4 | 5 | env.Append(CPPDEFINES=('KROLL_RUBY_API_EXPORT', 1)) 6 | build.add_thirdparty(env, 'poco') 7 | 8 | if build.is_osx(): 9 | env.Append(CPPPATH=[ 10 | '/usr/lib/ruby/1.8/universal-darwin10.0', 11 | '/usr/lib/ruby/1.8/universal-darwin9.0', 12 | '/usr/lib/ruby/1.8/universal-darwin8.0', 13 | build.kroll_include_dir]) 14 | env.Append(LIBS=['libruby']) 15 | 16 | 17 | elif build.is_linux(): 18 | env.Append(CPPPATH=[ 19 | '/usr/lib/ruby/1.8/i386-linux', 20 | '/usr/lib/ruby/1.8/i486-linux', 21 | '/usr/lib/ruby/1.8/i686-linux', 22 | '/usr/lib/ruby/1.8/x86_64-linux', 23 | '/usr/lib/ruby/1.8/powerpc-linux', 24 | build.kroll_include_dir]) 25 | 26 | if path.exists('/usr/lib/libruby1.8.so'): 27 | env.Append(LIBS=['ruby1.8']) 28 | else: 29 | env.Append(LIBS=['ruby']) 30 | 31 | elif build.is_win32(): 32 | env.Append(CPPPATH=[build.tp('ruby', 'lib', 'ruby', '1.8', 'i386-mswin32')]) 33 | env.Append(LIBPATH=[build.tp('ruby', 'lib')]) 34 | env.Append(LIBS=['msvcrt-ruby18']) 35 | 36 | build.mark_build_target(env.SharedLibrary( 37 | path.join(module.dir, 'rubymodule'), Glob('*.cpp'))) 38 | 39 | if build.is_win32(): 40 | build.utils.LightWeightCopy(build.tp('ruby'), module.dir) 41 | 42 | -------------------------------------------------------------------------------- /libkroll/javascript/k_kjs_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KJS_KLIST_H_ 8 | #define _KJS_KLIST_H_ 9 | 10 | #include "javascript_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KROLL_API KKJSList : public KList 15 | { 16 | 17 | public: 18 | KKJSList(JSContextRef context, JSObjectRef jsObject); 19 | ~KKJSList(); 20 | 21 | virtual void Set(const char* name, KValueRef value); 22 | virtual void SetAt(unsigned int index, KValueRef value); 23 | virtual KValueRef Get(const char* name); 24 | virtual SharedStringList GetPropertyNames(); 25 | virtual bool HasProperty(const char* name); 26 | virtual bool Equals(KObjectRef); 27 | virtual void Append(KValueRef value); 28 | virtual unsigned int Size(); 29 | virtual KValueRef At(unsigned int index); 30 | virtual bool Remove(unsigned int index); 31 | 32 | bool SameContextGroup(JSContextRef c); 33 | JSObjectRef GetJSObject(); 34 | 35 | protected: 36 | JSGlobalContextRef context; 37 | JSObjectRef jsobject; 38 | AutoPtr kobject; 39 | 40 | private: 41 | DISALLOW_EVIL_CONSTRUCTORS(KKJSList); 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /modules/php/k_php_array_object.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_PHP_ARRAY_OBJECT_H_ 8 | #define _K_PHP_ARRAY_OBJECT_H_ 9 | 10 | #include "php_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KPHPArrayObject : public KList 15 | { 16 | public: 17 | KPHPArrayObject(zval *list); 18 | virtual ~KPHPArrayObject(); 19 | 20 | KValueRef Get(const char *name); 21 | void Set(const char *name, KValueRef value); 22 | virtual bool Equals(KObjectRef); 23 | SharedStringList GetPropertyNames(); 24 | 25 | unsigned int Size(); 26 | void Append(KValueRef value); 27 | virtual void SetAt(unsigned int index, KValueRef value); 28 | bool Remove(unsigned int index); 29 | KValueRef At(unsigned int index); 30 | 31 | zval* ToPHP(); 32 | 33 | protected: 34 | zval *list; 35 | 36 | static void AddKrollValueToPHPArray(KValueRef value, zval *phpArray, const char *key); 37 | static void AddKrollValueToPHPArray(KValueRef value, zval *phpArray, unsigned int index); 38 | static void AddKrollValueToPHPArray(KValueRef value, zval *phpArray); 39 | DISALLOW_EVIL_CONSTRUCTORS(KPHPArrayObject); 40 | }; 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /modules/ruby/k_ruby_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_RUBY_LIST_H_ 8 | #define _K_RUBY_LIST_H_ 9 | 10 | #include "ruby_module.h" 11 | 12 | namespace kroll 13 | { 14 | class KRubyList : public KList 15 | { 16 | public: 17 | KRubyList(VALUE); 18 | virtual ~KRubyList(); 19 | 20 | void Append(KValueRef value); 21 | unsigned int Size(); 22 | KValueRef At(unsigned int index); 23 | void SetAt(unsigned int index, KValueRef value); 24 | bool Remove(unsigned int index); 25 | void Set(const char* name, KValueRef value); 26 | KValueRef Get(const char* name); 27 | SharedStringList GetPropertyNames(); 28 | SharedString DisplayString(int); 29 | VALUE ToRuby(); 30 | 31 | /* 32 | * Determine if the given Ruby object equals this one 33 | * by comparing these objects's identity e.g. equals?() 34 | * @param other the object to test 35 | * @returns true if objects have reference equality, false otherwise 36 | */ 37 | virtual bool Equals(KObjectRef); 38 | 39 | protected: 40 | VALUE list; 41 | AutoPtr object; 42 | DISALLOW_EVIL_CONSTRUCTORS(KRubyList); 43 | }; 44 | } 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /libkroll/binding/stream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Appcelerator, Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "../kroll.h" 18 | 19 | namespace kroll { 20 | 21 | Stream::Stream(const char* type) : StaticBoundObject(type) 22 | { 23 | } 24 | 25 | Stream::~Stream() 26 | { 27 | } 28 | 29 | void Stream::Write(const char* buffer, size_t size) 30 | { 31 | throw ValueException::FromString("Stream is not writable."); 32 | } 33 | 34 | bool Stream::IsWritable() const 35 | { 36 | return false; 37 | } 38 | 39 | size_t Stream::Read(const char* buffer, size_t size) 40 | { 41 | throw ValueException::FromString("Stream is not readable."); 42 | } 43 | 44 | bool Stream::IsReadable() const 45 | { 46 | return false; 47 | } 48 | 49 | } // namespace kroll 50 | -------------------------------------------------------------------------------- /libkroll/utils/platform_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_PLATFORM_UTILS_H_ 7 | #define _KR_PLATFORM_UTILS_H_ 8 | 9 | #include 10 | #include "poco/KTypes.h" 11 | 12 | #define MAC_ADDRESS_SIZE 6 13 | 14 | namespace UTILS_NS 15 | { 16 | typedef KPoco::KUInt8 MACAddress[MAC_ADDRESS_SIZE]; /// Ethernet address. 17 | 18 | namespace PlatformUtils 19 | { 20 | /* 21 | * Get the first MAC address of this computer 22 | * @returns the first MAC address in standard dotted format 23 | */ 24 | KROLL_API std::string GetFirstMACAddress(); 25 | 26 | /* 27 | * Get the first MAC address of this computer 28 | * @returns the first MAC address in standard dotted format 29 | */ 30 | KROLL_API void GetFirstMACAddressImpl(MACAddress&); 31 | 32 | /** 33 | * Generate an ID for this machine based on it's MAC Address. 34 | */ 35 | KROLL_API std::string GetMachineId(); 36 | 37 | /** 38 | * Get the username of the current user. 39 | */ 40 | KROLL_API std::string GetUsername(); 41 | 42 | /** 43 | * Get the number of processors on this machine. 44 | */ 45 | KROLL_API int GetProcessorCount(); 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /libkroll/win32/string_util_win.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef BASE_STRING_UTIL_WIN_H_ 6 | #define BASE_STRING_UTIL_WIN_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace base { 14 | 15 | inline int strcasecmp(const char* s1, const char* s2) { 16 | return _stricmp(s1, s2); 17 | } 18 | 19 | inline int strncasecmp(const char* s1, const char* s2, size_t count) { 20 | return _strnicmp(s1, s2, count); 21 | } 22 | 23 | inline int vsnprintf(char* buffer, size_t size, 24 | const char* format, va_list arguments) { 25 | int length = vsnprintf_s(buffer, size, size - 1, format, arguments); 26 | if (length < 0) 27 | return _vscprintf(format, arguments); 28 | return length; 29 | } 30 | 31 | inline int vswprintf(wchar_t* buffer, size_t size, 32 | const wchar_t* format, va_list arguments) { 33 | //DCHECK(IsWprintfFormatPortable(format)); 34 | 35 | int length = _vsnwprintf_s(buffer, size, size - 1, format, arguments); 36 | if (length < 0) 37 | return _vscwprintf(format, arguments); 38 | return length; 39 | } 40 | 41 | } // namespace base 42 | 43 | #endif // BASE_STRING_UTIL_WIN_H_ 44 | 45 | -------------------------------------------------------------------------------- /libkroll/javascript/k_kjs_method.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KJS_KMETHOD_H_ 8 | #define _KJS_KMETHOD_H_ 9 | 10 | #include "javascript_module.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace kroll 17 | { 18 | class KROLL_API KKJSMethod : public KMethod 19 | { 20 | public: 21 | KKJSMethod(JSContextRef, JSObjectRef, JSObjectRef); 22 | ~KKJSMethod(); 23 | 24 | virtual void Set(const char *name, KValueRef value); 25 | virtual KValueRef Get(const char *name); 26 | KValueRef Call(JSObjectRef thisObject, const ValueList& args); 27 | virtual KValueRef Call(const ValueList& args); 28 | virtual KValueRef Call(KObjectRef thisObject, const ValueList& args); 29 | virtual SharedStringList GetPropertyNames(); 30 | virtual bool HasProperty(const char* name); 31 | virtual bool Equals(KObjectRef); 32 | 33 | virtual bool SameContextGroup(JSContextRef c); 34 | JSObjectRef GetJSObject(); 35 | 36 | protected: 37 | JSGlobalContextRef context; 38 | JSObjectRef jsobject; 39 | JSObjectRef thisObject; 40 | AutoPtr kobject; 41 | 42 | private: 43 | DISALLOW_EVIL_CONSTRUCTORS(KKJSMethod); 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /libkroll/binding/binding.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_BINDING_H_ 8 | #define _KR_BINDING_H_ 9 | 10 | #include "../kroll.h" 11 | 12 | namespace kroll 13 | { 14 | class Event; 15 | class EventListener; 16 | class KEventObject; 17 | class ProfiledGlobalObject; 18 | } 19 | 20 | #include "kobject.h" 21 | #include "kmethod.h" 22 | #include "klist.h" 23 | #include "value.h" 24 | #include "static_bound_list.h" 25 | #include "static_bound_method.h" 26 | #include "static_bound_object.h" 27 | #include "k_function_ptr_method.h" 28 | #include "arg_list.h" 29 | #include "value_exception.h" 30 | #include "callback.h" 31 | #include "k_delegating_object.h" 32 | #include "k_accessor.h" 33 | #include "k_accessor_object.h" 34 | #include "k_accessor_list.h" 35 | #include "k_accessor_method.h" 36 | #include "scope_method_delegate.h" 37 | #include "bytes.h" 38 | #include "void_ptr.h" 39 | #include "event.h" 40 | #include "read_event.h" 41 | #include "k_event_object.h" 42 | #include "k_event_method.h" 43 | #include "profiled_bound_object.h" 44 | #include "profiled_bound_list.h" 45 | #include "profiled_bound_method.h" 46 | #include "global_object.h" 47 | #include "profiled_global_object.h" 48 | #include "stream.h" 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libkroll/ScriptController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Appcelerator, Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ScriptController_h 18 | #define ScriptController_h 19 | 20 | #include 21 | 22 | #include "kroll.h" 23 | 24 | namespace kroll { 25 | 26 | class Interpreter; 27 | 28 | class KROLL_API ScriptController { 29 | public: 30 | ScriptController(); 31 | 32 | void AddInterpreter(Interpreter* interpreter, const char* supportedScriptTypes[]); 33 | void RemoveInterpreter(Interpreter* interpreter); 34 | 35 | KValueRef EvaluateFile(const char* filepath, KObjectRef context); 36 | 37 | private: 38 | Interpreter* findInterpreterForType(const char* scriptType); 39 | 40 | typedef std::map InterpreterMapping; 41 | InterpreterMapping interpreters; 42 | }; 43 | 44 | } // namespace kroll 45 | 46 | #endif -------------------------------------------------------------------------------- /libkroll/binding/profiled_global_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace kroll 16 | { 17 | ProfiledGlobalObject::ProfiledGlobalObject(KObjectRef global) : 18 | profiledObject(new ProfiledBoundObject(global)) 19 | { 20 | } 21 | 22 | ProfiledGlobalObject::~ProfiledGlobalObject() 23 | { 24 | } 25 | 26 | void ProfiledGlobalObject::Set(const char* name, KValueRef value) 27 | { 28 | profiledObject->Set(name, value); 29 | } 30 | 31 | KValueRef ProfiledGlobalObject::Get(const char* name) 32 | { 33 | return profiledObject->Get(name); 34 | } 35 | 36 | SharedStringList ProfiledGlobalObject::GetPropertyNames() 37 | { 38 | return profiledObject->GetPropertyNames(); 39 | } 40 | 41 | SharedString ProfiledGlobalObject::DisplayString(int levels) 42 | { 43 | return profiledObject->DisplayString(levels); 44 | } 45 | 46 | bool ProfiledGlobalObject::HasProperty(const char* name) 47 | { 48 | return profiledObject->HasProperty(name); 49 | } 50 | 51 | bool ProfiledGlobalObject::Equals(KObjectRef other) 52 | { 53 | return profiledObject->Equals(other); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /libkroll/api/environment_binding.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "environment_binding.h" 8 | 9 | namespace kroll 10 | { 11 | KValueRef EnvironmentBinding::Get(const char *name) 12 | { 13 | return Value::NewString(EnvironmentUtils::Get(name)); 14 | } 15 | 16 | SharedStringList EnvironmentBinding::GetPropertyNames() 17 | { 18 | std::map env = EnvironmentUtils::GetEnvironment(); 19 | SharedStringList keys = new StringList(); 20 | 21 | std::map::iterator iter = env.begin(); 22 | for (; iter != env.end(); iter++) 23 | { 24 | keys->push_back(new std::string(iter->first)); 25 | } 26 | return keys; 27 | } 28 | 29 | void EnvironmentBinding::Set(const char *name, KValueRef value) 30 | { 31 | if (value->IsString()) 32 | { 33 | EnvironmentUtils::Set(name, value->ToString()); 34 | } 35 | } 36 | 37 | SharedString EnvironmentBinding::DisplayString(int levels) 38 | { 39 | std::map env = EnvironmentUtils::GetEnvironment(); 40 | std::map::iterator iter = env.begin(); 41 | SharedString str = new std::string(); 42 | 43 | for (; iter != env.end(); iter++) 44 | { 45 | (*str) += iter->first + "=" + iter->second + ","; 46 | } 47 | return str; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libkroll/javascript/kjs_util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KJS_UTIL_H_ 8 | #define _KJS_UTIL_H_ 9 | 10 | namespace kroll 11 | { 12 | namespace KJSUtil 13 | { 14 | 15 | KROLL_API KValueRef ToKrollValue(JSValueRef, JSContextRef, JSObjectRef); 16 | KROLL_API JSValueRef ToJSValue(KValueRef, JSContextRef); 17 | KROLL_API JSValueRef KObjectToJSValue(KValueRef, JSContextRef); 18 | KROLL_API JSValueRef KMethodToJSValue(KValueRef, JSContextRef); 19 | KROLL_API JSValueRef KListToJSValue(KValueRef, JSContextRef); 20 | KROLL_API std::string ToChars(JSStringRef); 21 | KROLL_API bool IsArrayLike(JSObjectRef, JSContextRef); 22 | KROLL_API JSGlobalContextRef CreateGlobalContext(); 23 | KROLL_API void RegisterGlobalContext(JSObjectRef, JSGlobalContextRef); 24 | KROLL_API void UnregisterGlobalContext(JSGlobalContextRef); 25 | KROLL_API JSGlobalContextRef GetGlobalContext(JSObjectRef); 26 | KROLL_API void ProtectGlobalContext(JSGlobalContextRef); 27 | KROLL_API void UnprotectGlobalContext(JSGlobalContextRef); 28 | KROLL_API KValueRef Evaluate(JSContextRef context, const char* script, 29 | const char* url = "string"); 30 | KROLL_API KValueRef EvaluateFile(JSContextRef context, 31 | const std::string& fullPath); 32 | KROLL_API KValueRef GetProperty(JSObjectRef, std::string name); 33 | 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /boot/popup_dialog_win32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef KRBOOT_POPUP_DIALOG_H_ 7 | #define KRBOOT_POPUP_DIALOG_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #define MAX_INPUT_LENGTH 1024 14 | 15 | namespace KrollBoot { 16 | 17 | class Win32PopupDialog { 18 | public: 19 | Win32PopupDialog(HWND _windowHandle); 20 | virtual ~Win32PopupDialog(); 21 | 22 | void SetShowInputText(bool flag) { this->showInputText = flag; } 23 | void SetTitle(std::string _title) { this->title = _title; } 24 | void SetMessage(std::string _message) { this->message = _message; } 25 | void SetInputText(std::string _inputText) { this->inputText = _inputText; } 26 | std::string GetInputText() { return this->inputText; } 27 | void SetShowCancelButton(bool flag) { this->showCancelButton = flag; } 28 | 29 | int Show(); 30 | private: 31 | HWND windowHandle; 32 | 33 | bool showInputText; 34 | std::string title; 35 | std::string message; 36 | std::string inputText; 37 | bool showCancelButton; 38 | int result; 39 | 40 | BOOL ShowMessageBox(HWND hwnd); 41 | 42 | static std::map popups; 43 | 44 | static void HandleOKClick(HWND hDlg); 45 | static INT_PTR CALLBACK CALLBACK Callback(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam); 46 | }; 47 | 48 | } 49 | 50 | #endif /* TI_POPUP_DIALOG_H_ */ 51 | -------------------------------------------------------------------------------- /libkroll/binding/profiled_bound_list.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | 11 | namespace kroll 12 | { 13 | ProfiledBoundList::ProfiledBoundList(KListRef delegate) : 14 | ProfiledBoundObject(delegate), 15 | list(delegate), 16 | count(1) 17 | { 18 | } 19 | 20 | ProfiledBoundList::~ProfiledBoundList() 21 | { 22 | } 23 | 24 | void ProfiledBoundList::Append(KValueRef value) 25 | { 26 | list->Append(value); 27 | } 28 | 29 | unsigned int ProfiledBoundList::Size() 30 | { 31 | return list->Size(); 32 | } 33 | 34 | KValueRef ProfiledBoundList::At(unsigned int index) 35 | { 36 | return list->At(index); 37 | } 38 | 39 | void ProfiledBoundList::SetAt(unsigned int index, KValueRef value) 40 | { 41 | list->SetAt(index,value); 42 | } 43 | 44 | bool ProfiledBoundList::Remove(unsigned int index) 45 | { 46 | return list->Remove(index); 47 | } 48 | 49 | void ProfiledBoundList::Set(const char *name, KValueRef value) 50 | { 51 | list->Set(name, value); 52 | } 53 | 54 | KValueRef ProfiledBoundList::Get(const char *name) 55 | { 56 | return list->Get(name); 57 | } 58 | 59 | SharedStringList ProfiledBoundList::GetPropertyNames() 60 | { 61 | return list->GetPropertyNames(); 62 | } 63 | 64 | bool ProfiledBoundList::HasProperty(const char* name) 65 | { 66 | return list->HasProperty(name); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /libkroll/utils/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008-2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_UTILS_H_ 7 | #define _KR_UTILS_H_ 8 | #include "../base.h" 9 | 10 | // If this is a version of the utils which doesn't 11 | // include libkroll, we should use our simple version 12 | // of SharedPtr -- if not use Poco's which is thread-safe. 13 | #if defined(KROLL_API_EXPORT) || defined(_KROLL_H_) 14 | #ifdef OS_WIN32 15 | #include 16 | #include 17 | #endif 18 | 19 | #include "../kroll.h" 20 | using Poco::SharedPtr; 21 | #define UTILS_NS kroll 22 | #else 23 | #define UTILS_NS KrollUtils 24 | #include "poco/KSharedPtr.h" 25 | using KPoco::SharedPtr; 26 | 27 | namespace KrollUtils 28 | { 29 | class KComponent; 30 | class Application; 31 | class Dependency; 32 | typedef SharedPtr SharedComponent; 33 | typedef SharedPtr SharedApplication; 34 | typedef SharedPtr SharedDependency; 35 | } 36 | #endif 37 | 38 | #include "application.h" 39 | #include "file_utils.h" 40 | #include "data_utils.h" 41 | #include "platform_utils.h" 42 | #include "environment_utils.h" 43 | #include "boot_utils.h" 44 | #include "url_utils.h" 45 | 46 | // Platform specific utilities 47 | #ifdef OS_WIN32 48 | #include "win32/win32_utils.h" 49 | #endif 50 | 51 | #ifdef OS_OSX 52 | #include "osx/osx_utils.h" 53 | #endif 54 | 55 | #ifndef OS_WIN32 56 | #include "posix/posix_utils.h" 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /libkroll/net/proxy_config_linux.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "../kroll.h" 7 | #include "net.h" 8 | #include 9 | using std::string; 10 | using std::wstring; 11 | using std::vector; 12 | using Poco::URI; 13 | using Poco::StringTokenizer; 14 | 15 | namespace kroll 16 | { 17 | static pxProxyFactory* GetProxyFactory() 18 | { 19 | // TODO: We should free this on exit. 20 | static pxProxyFactory* factory = NULL; 21 | if (!factory) 22 | { 23 | factory = px_proxy_factory_new(); 24 | } 25 | return factory; 26 | } 27 | 28 | namespace ProxyConfig 29 | { 30 | SharedPtr GetProxyForURLImpl(Poco::URI& uri) 31 | { 32 | std::string url(uri.toString()); 33 | char* urlC = strdup(url.c_str()); 34 | char** proxies = px_proxy_factory_get_proxies(GetProxyFactory(), urlC); 35 | free(urlC); 36 | 37 | // TODO(mrobinson): Instead of just returning the first applicable proxy, this 38 | // should return a list of them. 39 | const char* proxyChars = proxies[0]; 40 | if (!proxyChars) 41 | return 0; 42 | 43 | // Do not pass in an entryScheme here (third argument), because it will 44 | // override the host scheme, which is the most important in this case. 45 | SharedProxy proxy(ProxyConfig::ParseProxyEntry( 46 | proxyChars, uri.getScheme(), string())); 47 | 48 | for (int i = 0; proxies[i]; i++) 49 | free(proxies[i]); 50 | free(proxies); 51 | 52 | return proxy; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /libkroll/javascript/javascript_module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _JAVASCRIPT_MODULE_H 7 | #define _JAVASCRIPT_MODULE_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* KJS <-> Kroll bindings */ 17 | namespace kroll 18 | { 19 | class KKJSObject; 20 | class KKJSMethod; 21 | class KKJSList; 22 | class JavaScriptModule; 23 | class JavaScriptModuleInstance; 24 | } 25 | 26 | #include "k_kjs_object.h" 27 | #include "k_kjs_method.h" 28 | #include "k_kjs_list.h" 29 | #include "kjs_util.h" 30 | #include "javascript_module_instance.h" 31 | #include "javascript_methods.h" 32 | 33 | namespace kroll 34 | { 35 | class KROLL_API JavaScriptModule : public Module, public ModuleProvider 36 | { 37 | public: 38 | JavaScriptModule(Host* host, const char* path) : 39 | Module(host, path, STRING(MODULE_NAME), STRING(MODULE_VERSION)) 40 | { 41 | 42 | } 43 | 44 | ~JavaScriptModule() 45 | { 46 | 47 | } 48 | 49 | void Initialize(); 50 | void Stop(); 51 | virtual bool IsModule(std::string& path); 52 | virtual Module* CreateModule(std::string& path); 53 | 54 | Host* GetHost() 55 | { 56 | return host; 57 | } 58 | 59 | static JavaScriptModule* Instance() 60 | { 61 | return instance; 62 | } 63 | 64 | 65 | private: 66 | static JavaScriptModule *instance; 67 | }; 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /libkroll/utils/posix/posix_utils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009-2010 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "../utils.h" 7 | 8 | namespace UTILS_NS 9 | { 10 | std::wstring UTF8ToWide(const std::string& in) 11 | { 12 | // TODO: Eventually we want this function to convert to a non-UTF8 13 | // wide string, but do this for now, just so that on non-Win32 platforms 14 | // we can use the same code. 15 | std::wstring result(in.length(), L' '); 16 | std::copy(in.begin(), in.end(), result.begin()); 17 | return result; 18 | } 19 | 20 | std::wstring UTF8ToWide(const char* in) 21 | { 22 | std::string inString(in); 23 | return UTF8ToWide(inString); 24 | } 25 | 26 | std::string WideToUTF8(const std::wstring& in) 27 | { 28 | // TODO: Eventually we want this function to convert from Unicode 29 | // characters to UTF-8 characters, but do this for now, just so 30 | // that on non-Win32 platforms we can use the same code. 31 | std::string result(in.length(), ' '); 32 | std::copy(in.begin(), in.end(), result.begin()); 33 | return result; 34 | } 35 | 36 | std::string WideToUTF8(const wchar_t* in) 37 | { 38 | std::wstring inString(in); 39 | return WideToUTF8(inString); 40 | } 41 | 42 | KROLL_API std::string UTF8ToSystem(const std::string& in) 43 | { 44 | // Assume the system character set is UTF-8 for now. 45 | return in; 46 | } 47 | 48 | KROLL_API std::string UTF8ToSystem(const char* in) 49 | { 50 | // Assume the system character set is UTF-8 for now. 51 | return in; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /libkroll/net/proxy_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_PROXY_CONFIG_H_ 7 | #define _KR_PROXY_CONFIG_H_ 8 | namespace kroll 9 | { 10 | class KROLL_API BypassEntry 11 | { 12 | public: 13 | BypassEntry() : port(0) {} 14 | std::string scheme; 15 | std::string host; 16 | unsigned short port; 17 | }; 18 | 19 | enum ProxyType { HTTP, HTTPS, FTP, SOCKS }; 20 | class KROLL_API Proxy 21 | { 22 | public: 23 | ProxyType type; 24 | std::string host; 25 | unsigned port; 26 | std::string username; 27 | std::string password; 28 | std::string ToString(); 29 | static ProxyType SchemeToProxyType(std::string); 30 | }; 31 | 32 | namespace ProxyConfig 33 | { 34 | KROLL_API void SetHTTPProxyOverride(SharedProxy); 35 | KROLL_API void SetHTTPSProxyOverride(SharedProxy); 36 | KROLL_API SharedProxy GetHTTPProxyOverride(); 37 | KROLL_API SharedProxy GetHTTPSProxyOverride(); 38 | KROLL_API SharedProxy GetProxyForURL(std::string& url); 39 | KROLL_API SharedProxy ParseProxyEntry(std::string proxyEntry, 40 | const std::string& urlScheme, const std::string& entryScheme); 41 | 42 | SharedProxy GetProxyForURLImpl(Poco::URI& uri); 43 | bool ShouldBypass(Poco::URI& uri, 44 | std::vector >& bypassList); 45 | SharedPtr ParseBypassEntry(std::string entry); 46 | void ParseProxyList(std::string proxyListString, 47 | std::vector& proxyList, const std::string& scheme=""); 48 | Logger* GetLogger(); 49 | }; 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /libkroll/binding/value_exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | 10 | namespace kroll 11 | { 12 | ValueException::ValueException(KValueRef v) : std::exception(), value(v) 13 | { 14 | } 15 | 16 | ValueException::~ValueException() throw () 17 | { 18 | } 19 | 20 | ValueException ValueException::FromString(const char* s) 21 | { 22 | return ValueException(Value::NewString(s)); 23 | } 24 | 25 | ValueException ValueException::FromString(std::string s) 26 | { 27 | return ValueException(Value::NewString(s)); 28 | } 29 | 30 | ValueException ValueException::FromFormat(const char* format, ...) 31 | { 32 | 33 | va_list args; 34 | va_start(args, format); 35 | std::string text = Logger::Format(format, args); 36 | va_end(args); 37 | 38 | return ValueException(Value::NewString(text)); 39 | } 40 | 41 | ValueException ValueException::FromObject(KObjectRef o) 42 | { 43 | return ValueException(Value::NewObject(o)); 44 | } 45 | 46 | KValueRef ValueException::GetValue() 47 | { 48 | return this->value; 49 | } 50 | 51 | SharedString ValueException::DisplayString() 52 | { 53 | if (!this->value.isNull()) 54 | { 55 | return this->value->DisplayString(); 56 | } 57 | else 58 | { 59 | SharedString s = new std::string(""); 60 | return s; 61 | } 62 | } 63 | 64 | std::string& ValueException::ToString() 65 | { 66 | this->displayString = *this->DisplayString(); 67 | return this->displayString; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /libkroll/binding/profiled_bound_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_PROFILED_BOUND_METHOD_H_ 8 | #define _KR_PROFILED_BOUND_METHOD_H_ 9 | 10 | namespace kroll 11 | { 12 | /** 13 | * The ProfiledBoundMethod is a wrapped KMethod that does profiling 14 | */ 15 | class ProfiledBoundMethod : public ProfiledBoundObject, public KMethod 16 | { 17 | public: 18 | ProfiledBoundMethod(KMethodRef delegate, std::string& parentType); 19 | virtual ~ProfiledBoundMethod(); 20 | 21 | // @see KMethod::Call 22 | virtual KValueRef Call(const ValueList& args); 23 | // @see KMethod::Set 24 | virtual void Set(const char *name, KValueRef value); 25 | // @see KMethod::Get 26 | virtual KValueRef Get(const char *name); 27 | // @see KMethod::GetPropertyNames 28 | virtual SharedStringList GetPropertyNames(); 29 | // @see KObject::GetType 30 | virtual std::string& GetType(); 31 | 32 | bool HasProperty(const char* name); 33 | 34 | /** 35 | * @return the delegate of this profiled bound method 36 | */ 37 | KMethodRef GetDelegate() { return method; } 38 | virtual void duplicate() 39 | { 40 | ++count; 41 | } 42 | 43 | virtual void release() 44 | { 45 | int value = --count; 46 | if (value <= 0) { 47 | delete this; 48 | } 49 | } 50 | 51 | virtual int referenceCount() const 52 | { 53 | return count.value(); 54 | } 55 | 56 | private: 57 | KMethodRef method; 58 | std::string fullType; 59 | Poco::AtomicCounter count; 60 | 61 | }; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /libkroll/utils/kashmir/devrandom.h: -------------------------------------------------------------------------------- 1 | /********************************************************************\ 2 | * devrandom.h -- UNIX random number generator * 3 | * * 4 | * Copyright (C) 2009 Kenneth Laskoski * 5 | * * 6 | \********************************************************************/ 7 | /** @file devrandom.h 8 | @brief UNIX random number generator 9 | @author Copyright (C) 2009 Kenneth Laskoski 10 | based on work by 11 | @author Copyright (C) 1996, 1997, 1998 Theodore Ts'o 12 | @author Copyright (C) 2004-2008 Ralf S. Engelschall 13 | 14 | Use, modification, and distribution are subject 15 | to the Boost Software License, Version 1.0. (See accompanying file 16 | LICENSE_1_0.txt or a copy at .) 17 | */ 18 | 19 | #ifndef KL_DEVRANDOM_H 20 | #define KL_DEVRANDOM_H 21 | 22 | #include "randomstream.h" 23 | #include "noncopyable.h" 24 | 25 | #include 26 | #include 27 | 28 | namespace kashmir { 29 | namespace system { 30 | 31 | class DevRandom : public user::randomstream, noncopyable 32 | { 33 | public: 34 | DevRandom() : file("/dev/urandom", std::ios::in | std::ios::binary) 35 | { 36 | if (!file) 37 | throw std::runtime_error("failed to open random device."); 38 | } 39 | 40 | void read(char* buffer, std::size_t count) 41 | { 42 | file.read(buffer, count); 43 | } 44 | 45 | private: 46 | std::ifstream file; 47 | }; 48 | 49 | }} 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libkroll/binding/profiled_bound_method.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace kroll 13 | { 14 | ProfiledBoundMethod::ProfiledBoundMethod(KMethodRef delegate, std::string& type) : 15 | ProfiledBoundObject(delegate), 16 | method(delegate), 17 | fullType(type), 18 | count(1) 19 | { 20 | } 21 | 22 | ProfiledBoundMethod::~ProfiledBoundMethod() 23 | { 24 | } 25 | 26 | KValueRef ProfiledBoundMethod::Call(const ValueList& args) 27 | { 28 | std::string type = this->GetType(); 29 | 30 | KValueRef value; 31 | Poco::Stopwatch sw; 32 | sw.start(); 33 | try { 34 | value = method->Call(args); 35 | } catch (...) { 36 | sw.stop(); 37 | this->Log("call", type, sw.elapsed()); 38 | throw; 39 | } 40 | 41 | sw.stop(); 42 | this->Log("call", type, sw.elapsed()); 43 | return this->Wrap(value, type); 44 | } 45 | 46 | void ProfiledBoundMethod::Set(const char *name, KValueRef value) 47 | { 48 | method->Set(name,value); 49 | } 50 | 51 | KValueRef ProfiledBoundMethod::Get(const char *name) 52 | { 53 | return method->Get(name); 54 | } 55 | 56 | SharedStringList ProfiledBoundMethod::GetPropertyNames() 57 | { 58 | return method->GetPropertyNames(); 59 | } 60 | 61 | bool ProfiledBoundMethod::HasProperty(const char* name) 62 | { 63 | return method->HasProperty(name); 64 | } 65 | 66 | std::string& ProfiledBoundMethod::GetType() 67 | { 68 | return fullType; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /libkroll/utils/kashmir/noncopyable.h: -------------------------------------------------------------------------------- 1 | /********************************************************************\ 2 | * noncopyable.h -- prevents copy of derived classes * 3 | * * 4 | * Copyright (C) 2008 Kenneth Laskoski * 5 | * * 6 | \********************************************************************/ 7 | /** @file noncopyable.h 8 | @brief prevents copy of derived classes 9 | @author Copyright (C) 2008 Kenneth Laskoski 10 | shameless copy of work by 11 | @author Copyright (C) 1999-2003 Beman Dawes 12 | 13 | Use, modification, and distribution are subject 14 | to the Boost Software License, Version 1.0. (See accompanying file 15 | LICENSE_1_0.txt or a copy at .) 16 | 17 | See http://www.boost.org/libs/utility for documentation. 18 | */ 19 | 20 | #ifndef KL_NONCOPYABLE_H 21 | #define KL_NONCOPYABLE_H 22 | 23 | namespace kashmir { 24 | 25 | // Private copy constructor and copy assignment ensure classes derived from 26 | // class noncopyable cannot be copied. 27 | 28 | // Contributed by Dave Abrahams 29 | 30 | namespace noncopyable_ // protection from unintended ADL 31 | { 32 | class noncopyable 33 | { 34 | protected: 35 | noncopyable() {} 36 | ~noncopyable() {} 37 | private: // emphasize the following members are private 38 | noncopyable( const noncopyable& ); 39 | const noncopyable& operator=( const noncopyable& ); 40 | }; 41 | } 42 | 43 | typedef noncopyable_::noncopyable noncopyable; 44 | 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /libkroll/javascript/javascript_module.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include 7 | #include 8 | #include "javascript_module.h" 9 | #include 10 | 11 | namespace kroll 12 | { 13 | JavaScriptModule* JavaScriptModule::instance = NULL; 14 | void JavaScriptModule::Initialize() 15 | { 16 | JavaScriptModule::instance = this; 17 | host->AddModuleProvider(this); 18 | 19 | KObjectRef global(Host::GetInstance()->GetGlobalObject()); 20 | JavaScriptMethods::Bind(global); 21 | } 22 | 23 | void JavaScriptModule::Stop() 24 | { 25 | JavaScriptModule::instance = NULL; 26 | } 27 | 28 | const static std::string jsSuffix = "module.js"; 29 | bool JavaScriptModule::IsModule(std::string& path) 30 | { 31 | int plength = path.length(); 32 | int slength = jsSuffix.length(); 33 | if (path.length() > jsSuffix.length()) 34 | { 35 | return (path.substr(plength - slength) == jsSuffix); 36 | } 37 | else 38 | { 39 | return false; 40 | } 41 | } 42 | 43 | Module* JavaScriptModule::CreateModule(std::string& path) 44 | { 45 | Poco::Path p(path); 46 | std::string basename = p.getBaseName(); 47 | std::string name = basename.substr(0,basename.length()-jsSuffix.length()+3); 48 | std::string moduledir = path.substr(0,path.length()-basename.length()-3); 49 | 50 | Logger *logger = Logger::Get("JavaScript"); 51 | logger->Info("Loading JS path=%s", path.c_str()); 52 | 53 | JavaScriptModuleInstance* instance = new JavaScriptModuleInstance(this->host, path, moduledir, name); 54 | return instance; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libkroll/utils/url_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_URL_UTILS_H_ 7 | #define _KR_URL_UTILS_H_ 8 | #include 9 | namespace UTILS_NS 10 | { 11 | namespace URLUtils 12 | { 13 | /** 14 | * Encodes a URI value 15 | */ 16 | KROLL_API std::string EncodeURIComponent(std::string value); 17 | 18 | /** 19 | * Decodes a URI value 20 | */ 21 | KROLL_API std::string DecodeURIComponent(std::string value); 22 | 23 | /** 24 | * Convert a file URL to an absolute path 25 | */ 26 | KROLL_API std::string FileURLToPath(std::string url); 27 | 28 | /** 29 | * Convert an path to a file URL 30 | */ 31 | KROLL_API std::string PathToFileURL(std::string path); 32 | 33 | // These functions are not available outside a Kroll application 34 | #if defined(KROLL_API_EXPORT) || defined(_KROLL_H_) 35 | /** 36 | * Normalize a URL. If this url is an app:// URL, ensure that it 37 | * has the app id as the hostname 38 | */ 39 | KROLL_API std::string NormalizeURL(const std::string& url); 40 | 41 | /** 42 | * Convert a URL to a path if it is an app://, ti:// or file:// 43 | * URL. If this URL cannot be converted to a path, return the original URL 44 | */ 45 | KROLL_API std::string URLToPath(const string& url); 46 | 47 | /** 48 | * Path portion of URL which is guauranteed to be a local and * blank file. 49 | */ 50 | KROLL_API std::string& BlankPageURL(); 51 | 52 | KROLL_API std::string TiURLToPath(const std::string& url); 53 | KROLL_API std::string AppURLToPath(const std::string& url); 54 | #endif 55 | }; 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /boot/boot.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008-2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #define _KROLL_BOOT_ 1 8 | #ifndef _BOOT_H_ 9 | 10 | // ensure that Kroll API is never included to create 11 | // an artificial dependency on kroll shared library 12 | #ifdef _KROLL_H_ 13 | #error You should not have included the kroll api! 14 | #endif 15 | 16 | #define BOOTSTRAP_ENV "KR_BOOTSTRAPPED" 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace KrollUtils; 26 | using KrollUtils::Application; 27 | using KrollUtils::Dependency; 28 | using KrollUtils::KComponent; 29 | using KrollUtils::SharedApplication; 30 | using KrollUtils::SharedDependency; 31 | using KrollUtils::SharedComponent; 32 | using std::string; 33 | using std::vector; 34 | using std::map; 35 | 36 | #ifdef OS_WIN32 37 | #define MODULE_SEPARATOR ";" 38 | #else 39 | #define MODULE_SEPARATOR ":" 40 | #endif 41 | 42 | namespace KrollBoot 43 | { 44 | /** 45 | * Implemented platform independently 46 | */ 47 | int Bootstrap(); 48 | void FindUpdate(); 49 | 50 | /** 51 | * Implemented platform specifically 52 | */ 53 | void ShowError(std::string error, bool fatal=false); 54 | std::string GetApplicationHomePath(); 55 | bool RunInstaller(vector missing, bool forceInstall=false); 56 | void BootstrapPlatformSpecific(string moduleList); 57 | int StartHost(); 58 | string Blastoff(); 59 | vector FilterForSDKInstall( 60 | vector dependencies); 61 | string GetApplicationName(); 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /libkroll/binding/scope_method_delegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_SCOPE_METHOD_DELEGATE_H_ 8 | #define _KR_BOUND_METHOD_DELEGATE_H_ 9 | 10 | namespace kroll { 11 | 12 | enum MethodDelegateType 13 | { 14 | GET, /**< Getter method */ 15 | SET /**< Setter method */ 16 | }; 17 | 18 | /** 19 | * class that can be used to change the delegation of a method 20 | * call's Get or Set method to first check to see if the key has 21 | * namespace dots (such as ti.foo.bar) and if so, delegate to a 22 | * differently supplied scope object for delegation. 23 | */ 24 | class KROLL_API ScopeMethodDelegate : public KMethod 25 | { 26 | public: 27 | 28 | ScopeMethodDelegate(MethodDelegateType type, KObjectRef global, 29 | KObjectRef scope, KMethodRef delegate); 30 | virtual ~ScopeMethodDelegate(); 31 | 32 | 33 | void Set(const char *name, KValueRef value); 34 | KValueRef Get(const char *name); 35 | SharedStringList GetPropertyNames(); 36 | 37 | 38 | bool IsGlobalKey(std::string& key); 39 | KValueRef Call(const ValueList& args); 40 | 41 | /** 42 | * create a delegate from a KObject to a wrapped 43 | * StaticBoundObject and delegate set/get to the new 44 | * static bound object 45 | */ 46 | static AutoPtr CreateDelegate(KObjectRef global, KObjectRef bo); 47 | 48 | 49 | private: 50 | MethodDelegateType type; 51 | KObjectRef global; 52 | KObjectRef scope; 53 | KMethodRef delegate; 54 | 55 | 56 | private: 57 | DISALLOW_EVIL_CONSTRUCTORS(ScopeMethodDelegate); 58 | }; 59 | 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libkroll/module_provider.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_MODULE_PROVIDER_H_ 8 | #define _KR_MODULE_PROVIDER_H_ 9 | #include 10 | 11 | namespace kroll 12 | { 13 | class Module; 14 | class Host; 15 | 16 | typedef Module* ModuleCreator(const Host *host, const char *path); 17 | 18 | /** 19 | * Module Provider implementations are responsible for determining if a file 20 | * contains a supportable module, and for constructing them if they 21 | * determine that the file is supported. 22 | * 23 | * In general, module providers will be a part of the system, but they are meant 24 | * as a way to provide extension points to 3rd party languages such as Python, Ruby, etc. 25 | * 26 | * Currently any language supported by Kroll includes it's own ModuleProvider 27 | */ 28 | class EXPORT ModuleProvider 29 | { 30 | public: 31 | ModuleProvider() {} 32 | virtual ~ModuleProvider() {}; 33 | 34 | /** 35 | * @param filename an absolute path to a file in the filesystem 36 | * @return if the passed-in absolute file path is a supported module or not 37 | */ 38 | virtual bool IsModule(std::string& filename) = 0; 39 | 40 | /** 41 | * Create a module based on a path that was signified as "supported" by 42 | * ModuleProvider::IsModule. Most implementations will load this file into 43 | * their interpreter, or dynamically load it's contents in some way. 44 | * 45 | * @param path an absolute path to a module file in the filesystem 46 | * @return The module that represents this path. 47 | */ 48 | virtual Module* CreateModule(std::string& path) = 0; 49 | }; 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /libkroll/binding/profiled_bound_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_PROFILED_BOUND_LIST_H_ 8 | #define _KR_PROFILED_BOUND_LIST_H_ 9 | 10 | namespace kroll 11 | { 12 | /** 13 | * The ProfiledBoundList is a wrapped KList that does profiling 14 | */ 15 | class ProfiledBoundList : public ProfiledBoundObject, public KList 16 | { 17 | public: 18 | ProfiledBoundList(KListRef delegate); 19 | virtual ~ProfiledBoundList(); 20 | 21 | // @see KList::Append 22 | virtual void Append(KValueRef value); 23 | // @see KList::Size 24 | virtual unsigned int Size(); 25 | // @see KList::At 26 | virtual KValueRef At(unsigned int index); 27 | // @see KList::SetAt 28 | virtual void SetAt(unsigned int index, KValueRef value); 29 | // @see KList::Remove 30 | virtual bool Remove(unsigned int index); 31 | // @See KList::Set 32 | virtual void Set(const char *name, KValueRef value); 33 | // @see KList::Get 34 | virtual KValueRef Get(const char *name); 35 | // @see KList::GetPropertyNames 36 | virtual SharedStringList GetPropertyNames(); 37 | 38 | bool HasProperty(const char* name); 39 | 40 | /** 41 | * @return the delegate of this profiled bound object 42 | */ 43 | KListRef GetDelegate() { return list; } 44 | virtual void duplicate() 45 | { 46 | ++count; 47 | } 48 | 49 | virtual void release() 50 | { 51 | int value = --count; 52 | if (value <= 0) { 53 | delete this; 54 | } 55 | } 56 | 57 | virtual int referenceCount() const 58 | { 59 | return count.value(); 60 | } 61 | 62 | private: 63 | KListRef list; 64 | Poco::AtomicCounter count; 65 | 66 | }; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libkroll/binding/static_bound_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | 10 | namespace kroll 11 | { 12 | StaticBoundObject::StaticBoundObject(const char* type) 13 | : KObject(type) 14 | { 15 | } 16 | 17 | StaticBoundObject::~StaticBoundObject() 18 | { 19 | } 20 | 21 | bool StaticBoundObject::HasProperty(const char* name) 22 | { 23 | return properties.find(name) != properties.end(); 24 | } 25 | 26 | KValueRef StaticBoundObject::Get(const char* name) 27 | { 28 | Poco::Mutex::ScopedLock lock(mutex); 29 | std::map::iterator iter = 30 | properties.find(std::string(name)); 31 | 32 | if (iter == properties.end()) 33 | return Value::Undefined; 34 | return iter->second; 35 | } 36 | 37 | void StaticBoundObject::Set(const char* name, KValueRef value) 38 | { 39 | Poco::Mutex::ScopedLock lock(mutex); 40 | this->properties[std::string(name)] = value; 41 | } 42 | 43 | void StaticBoundObject::Unset(const char* name) 44 | { 45 | Poco::Mutex::ScopedLock lock(mutex); 46 | std::map::iterator iter = 47 | properties.find(std::string(name)); 48 | 49 | if (this->properties.end() == iter) 50 | return; 51 | this->properties.erase(iter); 52 | } 53 | 54 | SharedStringList StaticBoundObject::GetPropertyNames() 55 | { 56 | SharedStringList list(new StringList()); 57 | Poco::Mutex::ScopedLock lock(mutex); 58 | std::map::iterator iter = properties.begin(); 59 | 60 | while (iter != properties.end()) 61 | list->push_back(new std::string((iter++)->first)); 62 | 63 | return list; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os, re, sys, inspect, os.path as path 3 | from kroll import BuildConfig 4 | 5 | debug = False 6 | Import('*') 7 | 8 | # this will ensure that you're using the right version of scons 9 | EnsureSConsVersion(1,2,0) 10 | # this will ensure that you're using the right version of python 11 | EnsurePythonVersion(2,5) 12 | 13 | 14 | build = BuildConfig( 15 | PRODUCT_VERSION = '0.1', 16 | PRODUCT_NAME = 'Kroll', 17 | GLOBAL_NS_VARNAME = 'kroll', 18 | CONFIG_FILENAME = 'tiapp.xml', 19 | BUILD_DIR = path.abspath('build'), 20 | THIRD_PARTY_DIR = path.abspath('thirdparty'), 21 | DISTRIBUTION_URL = 'api.appcelerator.net', 22 | CRASH_REPORT_URL = 'api.appcelerator.net/p/v1/app-crash-report', 23 | ) 24 | build.set_kroll_source_dir(path.abspath('.')) 25 | 26 | # This should only be used for accessing various 27 | # scripts in the kroll build directory. All resources 28 | # should instead be built to build.dir 29 | build.kroll_build_dir = path.join(build.kroll_source_dir, 'build') 30 | build.env.Append(CPPPATH=[ 31 | build.kroll_source_dir, 32 | build.kroll_include_dir]) 33 | 34 | # debug build flags 35 | debug = ARGUMENTS.get('debug', 0) 36 | if debug: 37 | build.env.Append(CPPDEFINES = ('DEBUG', 1)) 38 | if build.is_win32(): 39 | build.env.Append(CCFLAGS=['/Z7']) # max debug 40 | build.env.Append(CPPDEFINES=('WIN32_CONSOLE', 1)) 41 | else: 42 | build.env.Append(CPPFLAGS=['-g']) # debug 43 | else: 44 | build.env.Append(CPPDEFINES = ('NDEBUG', 1 )) 45 | if not build.is_win32(): 46 | build.env.Append(CPPFLAGS = ['-O9']) # max optimizations 47 | 48 | if build.is_win32(): 49 | build.env.Append(CCFLAGS=['/EHsc', '/GR', '/MD']) 50 | build.env.Append(LINKFLAGS=['/DEBUG', '/PDB:${TARGET}.pdb']) 51 | 52 | Export('build') 53 | SConscript('SConscript.thirdparty', duplicate=0) 54 | SConscript('SConscript', exports='debug') 55 | -------------------------------------------------------------------------------- /modules/php/SConscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os import path 3 | Import('build env module') 4 | 5 | env.Append(CPPDEFINES=('KROLL_PHP_API_EXPORT', 1)) 6 | build.add_thirdparty(env, 'poco') 7 | 8 | # PHP's headers are so messy that they flood the build with warnings 9 | # unless we turn off -Werror and try to suprress most warnings. This 10 | # is bad news. At some point we should turn warnings back on. 11 | if 'CPPFLAGS' in env: 12 | env['CPPFLAGS'] = env['CPPFLAGS'][:] 13 | if '-Werror' in env['CPPFLAGS']: 14 | env['CPPFLAGS'].remove('-Werror') 15 | if '-Wall' in env['CPPFLAGS']: 16 | env['CPPFLAGS'].remove('-Wall') 17 | env['CPPFLAGS'].append('-w') 18 | 19 | env.Append(CPPPATH=[ 20 | build.tp('php', 'include'), 21 | build.tp('php', 'include', 'TSRM'), 22 | build.tp('php', 'include', 'Zend'), 23 | build.tp('php', 'include', 'ext'), 24 | build.tp('php', 'include', 'main'), 25 | build.tp('php', 'include', 'sapi'), 26 | ]) 27 | env.Append(LIBPATH=[build.tp('php', 'lib')]) 28 | env.Append(CPPDEFINES=('ZTS', 1)) 29 | 30 | # On OS X PHP can only build for i386 31 | if build.is_osx(): 32 | env.Replace(CXX=['g++', '-arch', 'i386']) 33 | 34 | if build.is_osx() or build.is_linux(): 35 | env.Append(LIBS=['php5']) 36 | env.Append(CPPDEFINES=('PTHREADS', 1)) 37 | 38 | elif build.is_win32(): 39 | env.Append(CPPDEFINES=('PHP_WIN32', 1)) 40 | env.Append(CPPDEFINES=('ZEND_WIN32', 1)) 41 | env.Append(CPPDEFINES=('_USE_32BIT_TIME_T', 1)) 42 | env.Append(CPPDEFINES=('TSRM_WIN32', 1)) 43 | #env.Append(CPPDEFINES=('ZEND_DEBUG', 0)) 44 | env.Append(LIBS=['php5embed', 'php5ts']) 45 | 46 | build.mark_build_target(env.SharedLibrary( 47 | path.join(module.dir, 'phpmodule'), Glob('*.cpp'))) 48 | 49 | if build.is_win32(): 50 | build.utils.LightWeightCopy(build.tp('php', 'bin'), module.dir) 51 | if build.is_osx() or build.is_linux(): 52 | build.utils.LightWeightCopy(build.tp('php', 'lib'), module.dir) 53 | -------------------------------------------------------------------------------- /modules/ruby/ruby_module.cpp: -------------------------------------------------------------------------------- 1 | /** Appcelerator Kroll - licensed under the Apache Public License 2 see LICENSE 2 | * in the root folder for details on the license. Copyright (c) 2008 3 | * Appcelerator, Inc. All Rights Reserved. 4 | */ 5 | #include 6 | #include "ruby_module.h" 7 | #include 8 | 9 | extern "C" EXPORT RubyModule* CreateModule(Host *host, const char* path) 10 | { 11 | return new RubyModule(host, path); 12 | } 13 | 14 | static const char* supportedScriptTypes[3] = {"rb", "ruby", NULL}; 15 | 16 | namespace kroll 17 | { 18 | RubyModule* RubyModule::instance_ = NULL; 19 | 20 | void RubyModule::Initialize() 21 | { 22 | RubyModule::instance_ = this; 23 | 24 | ruby_init(); 25 | ruby_init_loadpath(); 26 | 27 | // Add the application directoy to the Ruby include path so 28 | // that includes work in a intuitive way for application developers. 29 | ruby_incpush(UTF8ToSystem(host->GetApplication()->GetResourcesPath()).c_str()); 30 | 31 | host->script()->AddInterpreter(&interpreter, supportedScriptTypes); 32 | 33 | host->AddModuleProvider(this); 34 | } 35 | 36 | void RubyModule::Stop() 37 | { 38 | host->script()->RemoveInterpreter(&interpreter); 39 | 40 | RubyModule::instance_ = NULL; 41 | ruby_cleanup(0); 42 | } 43 | 44 | const static std::string ruby_suffix = "module.rb"; 45 | bool RubyModule::IsModule(std::string& path) 46 | { 47 | return (path.substr(path.length()-ruby_suffix.length()) == ruby_suffix); 48 | } 49 | 50 | Module* RubyModule::CreateModule(std::string& path) 51 | { 52 | path = UTF8ToSystem(path); 53 | rb_load_file(path.c_str()); 54 | ruby_exec(); 55 | // TODO: Do we need to call ruby_cleanup() here? 56 | 57 | Poco::Path p(path); 58 | std::string basename = p.getBaseName(); 59 | std::string name = basename.substr(0,basename.length()-ruby_suffix.length()+3); 60 | std::string moduledir = path.substr(0,path.length()-basename.length()-3); 61 | 62 | return new RubyModuleInstance(host, path, moduledir, name); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /libkroll/binding/k_delegating_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_K_DELEGATING_OBJECT_H_ 7 | #define _KR_K_DELEGATING_OBJECT_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace kroll 16 | { 17 | /** 18 | * The KDelegatingObject lets you wrap a globally accessible 19 | * object in such a way as it appears to have special properties in 20 | * in local contexts. When a Get(...) occurs, the object searches a local 21 | * delegate and then a global one. When a Set(...) occurs, the object 22 | * performs it on both the local and the global version. Thus this object 23 | * is most useful if the local properties are assigned to the local object 24 | * in an initial setup phase. 25 | */ 26 | class KROLL_API KDelegatingObject : public KObject 27 | { 28 | public: 29 | KDelegatingObject(KObjectRef global); 30 | KDelegatingObject(KObjectRef global, KObjectRef local); 31 | virtual ~KDelegatingObject(); 32 | virtual KValueRef Get(const char *name); 33 | virtual SharedStringList GetPropertyNames(); 34 | virtual void Set(const char *name, KValueRef value); 35 | virtual bool HasProperty(const char* name); 36 | 37 | virtual inline KObjectRef GetGlobal() { return this->global; } 38 | virtual inline KObjectRef GetLocal() { return this->local; } 39 | 40 | private: 41 | /** 42 | * The global part of this delegate object. This object 43 | * is used to find properties if they are not found in 44 | * the local object. 45 | */ 46 | KObjectRef global; 47 | 48 | /** 49 | * The local part of this delegate object. This object 50 | * is the first in line for property retrieval. 51 | */ 52 | KObjectRef local; 53 | 54 | DISALLOW_EVIL_CONSTRUCTORS(KDelegatingObject); 55 | 56 | protected: 57 | Poco::Mutex mutex; 58 | }; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /libkroll/binding/profiled_bound_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_PROFILED_BOUND_OBJECT_H_ 8 | #define _KR_PROFILED_BOUND_OBJECT_H_ 9 | #include 10 | #include 11 | 12 | namespace kroll 13 | { 14 | /** 15 | * The ProfiledBoundObject is a wrapped KObject that does profiling on a 16 | * wrapped KObject 17 | */ 18 | class KROLL_API ProfiledBoundObject : public KObject 19 | { 20 | public: 21 | ProfiledBoundObject(KObjectRef delegate); 22 | virtual ~ProfiledBoundObject(); 23 | static void SetStream(Poco::FileOutputStream*); 24 | 25 | public: 26 | // @see KObject::Set 27 | virtual void Set(const char *name, KValueRef value); 28 | // @see KObject::Get 29 | virtual KValueRef Get(const char *name); 30 | // @see KObject::GetPropertyNames 31 | virtual SharedStringList GetPropertyNames(); 32 | // @see KObject::DisplayString 33 | virtual SharedString DisplayString(int levels=3); 34 | // @see KObject::Equals 35 | virtual bool Equals(KObjectRef other); 36 | 37 | bool HasProperty(const char* name); 38 | 39 | /** 40 | * @return the delegate of this profiled bound object 41 | */ 42 | KObjectRef GetDelegate() { return delegate; } 43 | virtual void duplicate() 44 | { 45 | ++count; 46 | } 47 | 48 | virtual void release() 49 | { 50 | int value = --count; 51 | if (value <= 0) { 52 | delete this; 53 | } 54 | } 55 | 56 | virtual int referenceCount() const 57 | { 58 | return count.value(); 59 | } 60 | 61 | protected: 62 | KObjectRef delegate; 63 | KValueRef Wrap(KValueRef value, std::string type); 64 | std::string GetSubType(std::string name); 65 | void Log(const char* eventType, std::string& name, Poco::Timestamp::TimeDiff); 66 | static bool AlreadyWrapped(KValueRef); 67 | static Poco::FileOutputStream *stream; 68 | static Poco::Mutex logMutex; 69 | Poco::AtomicCounter count; 70 | }; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /tools/alloy/modules/alloy/alloymodule.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | Titanium.API.setLogLevel(Titanium.API.ERROR); 3 | 4 | var stdout = Titanium.App.stdout; 5 | var stdin = Titanium.App.stdin; 6 | 7 | String.prototype.rtrim=function(){return this.replace(/\s+$/,'');} 8 | String.prototype.endsWith = function endsWith(pattern) 9 | { 10 | var d = this.length - pattern.length; 11 | return d >= 0 && this.lastIndexOf(pattern) === d; 12 | } 13 | 14 | stdout("~~~~~Alloy~~~~~"); 15 | stdout("Type / to switch languages"); 16 | stdout("Supported languages: javascript, python, ruby"); 17 | stdout("For multi-line blocks of code, use a \\ to continue on a newline"); 18 | stdout("Type /exit to quit"); 19 | stdout(""); 20 | 21 | var langEvals = { 22 | javascript: function(mimeType, scriptName, code, globals) 23 | { 24 | try 25 | { 26 | eval(code); 27 | } 28 | catch(e) 29 | { 30 | stdout("Javascript error: " + e); 31 | } 32 | }, 33 | python: Titanium.Python.evaluate, 34 | ruby: Titanium.Ruby.evaluate, 35 | }; 36 | 37 | var activeEval = langEvals["javascript"]; 38 | var activeMime = "text/javascript"; 39 | var command = ""; 40 | while (true) 41 | { 42 | command += stdin(">>> ").rtrim(); 43 | if (command == "/exit") 44 | { 45 | break; 46 | } 47 | else if (command.charAt(0) == '/') 48 | { 49 | // Switch languages 50 | var lang = command.substr(1).toLowerCase(); 51 | var langEval = langEvals[lang]; 52 | if (langEval != undefined) 53 | { 54 | activeMime = "text/" + lang; 55 | activeEval = langEvals[lang]; 56 | } 57 | else 58 | { 59 | stdout("Invalid language: " + lang); 60 | } 61 | } 62 | else if (command.endsWith("\\")) 63 | { 64 | // multi-line code 65 | command = command.substring(0, command.length - 1) + "\n"; 66 | continue; 67 | } 68 | else 69 | { 70 | // evalute it as code 71 | var result = activeEval(activeMime, "alloy", command, this); 72 | if (result != undefined) 73 | { 74 | stdout(result); 75 | } 76 | } 77 | command = ""; 78 | } 79 | 80 | Titanium.App.exit(); 81 | })(); 82 | -------------------------------------------------------------------------------- /libkroll/win32/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef BASE_PORT_H_ 6 | #define BASE_PORT_H_ 7 | 8 | #include 9 | #define COMPILER_MSVC 10 | 11 | #ifdef COMPILER_MSVC 12 | #define GG_LONGLONG(x) x##I64 13 | #define GG_ULONGLONG(x) x##UI64 14 | #else 15 | #define GG_LONGLONG(x) x##LL 16 | #define GG_ULONGLONG(x) x##ULL 17 | #endif 18 | 19 | // Per C99 7.8.14, define __STDC_CONSTANT_MACROS before including 20 | // to get the INTn_C and UINTn_C macros for integer constants. It's difficult 21 | // to guarantee any specific ordering of header includes, so it's difficult to 22 | // guarantee that the INTn_C macros can be defined by including at 23 | // any specific point. Provide GG_INTn_C macros instead. 24 | 25 | #define GG_INT8_C(x) (x) 26 | #define GG_INT16_C(x) (x) 27 | #define GG_INT32_C(x) (x) 28 | #define GG_INT64_C(x) GG_LONGLONG(x) 29 | 30 | #define GG_UINT8_C(x) (x ## U) 31 | #define GG_UINT16_C(x) (x ## U) 32 | #define GG_UINT32_C(x) (x ## U) 33 | #define GG_UINT64_C(x) GG_ULONGLONG(x) 34 | 35 | namespace base { 36 | 37 | // It's possible for functions that use a va_list, such as StringPrintf, to 38 | // invalidate the data in it upon use. The fix is to make a copy of the 39 | // structure before using it and use that copy instead. va_copy is provided 40 | // for this purpose. MSVC does not provide va_copy, so define an 41 | // implementation here. It is not guaranteed that assignment is a copy, so the 42 | // StringUtil.VariableArgsFunc unit test tests this capability. 43 | inline void va_copy(va_list& a, va_list& b) { 44 | #if defined(COMPILER_GCC) 45 | ::va_copy(a, b); 46 | #elif defined(COMPILER_MSVC) 47 | a = b; 48 | #endif 49 | } 50 | 51 | } // namespace base 52 | 53 | // Define an OS-neutral wrapper for shared library entry points 54 | #if defined(OS_WIN32) 55 | #define API_CALL __stdcall 56 | #elif defined(OS_LINUX) || defined(OS_OSX) 57 | #define API_CALL 58 | #endif 59 | 60 | #endif // BASE_PORT_H_ 61 | 62 | -------------------------------------------------------------------------------- /libkroll/binding/arg_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_ARG_LISTT_H_ 8 | #define _K_ARG_LISTT_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include "callback.h" 14 | 15 | namespace kroll 16 | { 17 | /** 18 | * An argument list 19 | * 20 | * This class is only used for argument lists. For a list implementation to be 21 | * used as a value in the binding layer, take a look at KList and StaticBoundList. 22 | */ 23 | class KROLL_API ArgList 24 | { 25 | public: 26 | ArgList(); 27 | ArgList(KValueRef); 28 | ArgList(KValueRef, KValueRef); 29 | ArgList(KValueRef, KValueRef, KValueRef); 30 | ArgList(KValueRef, KValueRef, KValueRef, KValueRef); 31 | ArgList(const ArgList&); 32 | ~ArgList() {}; 33 | 34 | bool Verify(std::string& argSpec) const; 35 | void VerifyException(const char* name, std::string argSpec) const; 36 | 37 | public: 38 | void push_back(KValueRef value); 39 | size_t size() const; 40 | const KValueRef& at(size_t) const; 41 | const KValueRef& operator[](size_t) const; 42 | 43 | KValueRef GetValue(size_t index, KValueRef defaultValue=Value::Undefined) const; 44 | int GetInt(size_t index, int defaultValue=0) const; 45 | double GetDouble(size_t index, double defaultValue=0.0) const; 46 | double GetNumber(size_t index, double defaultValue=0.0) const; 47 | bool GetBool(size_t index, bool defaultValue=false) const; 48 | std::string GetString(size_t index, std::string defaultValue="") const; 49 | KObjectRef GetObject(size_t index, KObjectRef defaultValue=NULL) const; 50 | KMethodRef GetMethod(size_t index, KMethodRef defaultValue=NULL) const; 51 | KListRef GetList(size_t index, KListRef defaultValue=NULL) const; 52 | 53 | private: 54 | SharedPtr > args; 55 | 56 | static inline bool VerifyArg(KValueRef arg, char t); 57 | static std::string GenerateSignature(const char* name, std::string& argSpec); 58 | }; 59 | 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /libkroll/binding/k_event_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009-2010 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_EVENT_OBJECT_H_ 8 | #define _KR_EVENT_OBJECT_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace kroll 14 | { 15 | class EventListener; 16 | typedef std::list EventListenerList; 17 | 18 | class KROLL_API KEventObject : public KAccessorObject 19 | { 20 | public: 21 | KEventObject(const char* name = "KEventObject"); 22 | virtual ~KEventObject(); 23 | 24 | AutoPtr CreateEvent(const std::string& eventName); 25 | 26 | virtual void AddEventListener(const char* event, KMethodRef listener); 27 | virtual void AddEventListener(std::string& event, KMethodRef listener); 28 | virtual void RemoveEventListener(std::string& event, KMethodRef listener); 29 | virtual void RemoveAllEventListeners(); 30 | 31 | void FireEvent(const char* event); 32 | virtual void FireEvent(const char* event, const ValueList& args); 33 | virtual bool FireEvent(std::string& event, bool synchronous=true); 34 | virtual bool FireEvent(AutoPtr, bool synchronous=true); 35 | void FireErrorEvent(std::exception& e); 36 | 37 | void _AddEventListener(const ValueList&, KValueRef result); 38 | void _RemoveEventListener(const ValueList&, KValueRef result); 39 | void _RemoveAllEventListeners(const ValueList&, KValueRef result); 40 | 41 | private: 42 | void ReportDispatchError(std::string& reason); 43 | 44 | EventListenerList listeners; 45 | Poco::FastMutex listenersMutex; 46 | }; 47 | 48 | class EventListener 49 | { 50 | public: 51 | EventListener(std::string& targetedEvent, KMethodRef callback); 52 | EventListener(const char* targetedEvent, KMethodRef callback); 53 | 54 | bool Handles(const char* event); 55 | bool Dispatch(KObjectRef thisObject, const ValueList& args, bool synchronous); 56 | KMethodRef Callback(); 57 | 58 | private: 59 | std::string targetedEvent; 60 | KMethodRef callback; 61 | }; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /modules/php/php_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _PHP_TYPES_H_ 7 | #define _PHP_TYPES_H_ 8 | 9 | #include "php_module.h" 10 | 11 | namespace kroll 12 | { 13 | typedef struct 14 | { 15 | zend_object std; 16 | KValueRef kvalue; 17 | } PHPKObject; 18 | extern zend_class_entry *PHPKObjectClassEntry; 19 | extern zend_class_entry *PHPKMethodClassEntry; 20 | extern zend_class_entry *PHPKListClassEntry; 21 | extern zend_object_handlers PHPKObjectHandlers; 22 | 23 | namespace PHPUtils 24 | { 25 | KValueRef ToKrollValue(zval* value TSRMLS_DC); 26 | zval* ToPHPValue(KValueRef value); 27 | void ToPHPValue(KValueRef value, zval** returnValue); 28 | std::string ZvalToPropertyName(zval* property); 29 | KListRef PHPArrayToKList(zval* array TSRMLS_DC, 30 | bool ignoreGlobals=false); 31 | KListRef PHPHashTableToKList(HashTable* hashtable TSRMLS_DC, 32 | bool ignoreGlobals=false); 33 | SharedStringList GetHashKeys(HashTable* hash); 34 | void KObjectToKPHPObject(KValueRef objectValue, zval** returnValue); 35 | void KMethodToKPHPMethod(KValueRef methodValue, zval** returnValue); 36 | void KListToKPHPArray(KValueRef listValue, zval** returnValue); 37 | void InitializePHPKrollClasses(); 38 | bool PHPObjectsEqual(zval* val1, zval* val2 TSRMLS_DC); 39 | int HashZvalCompareCallback(const zval** one, const zval** two TSRMLS_DC); 40 | SharedStringList GetClassMethods(zend_class_entry* ce TSRMLS_DC); 41 | KListRef GetClassVars(zend_class_entry* ce TSRMLS_DC); 42 | zend_function* GetGlobalFunction(const char *name TSRMLS_DC); 43 | void GenerateCaseMap(string code TSRMLS_DC); 44 | 45 | KObjectRef GetCurrentGlobalObject(); 46 | void PushPHPSymbolsIntoGlobalObject(HashTable* symbolTable, KObjectRef global TSRMLS_DC); 47 | void PushGlobalObjectMembersIntoPHPSymbolTable(HashTable* symbolTable, KObjectRef global TSRMLS_DC); 48 | void SwapGlobalObject(KObjectRef newGlobal, HashTable* symbolTable TSRMLS_DC); 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /libkroll/binding/static_bound_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_STATIC_BOUND_METHOD_H_ 8 | #define _KR_STATIC_BOUND_METHOD_H_ 9 | 10 | namespace kroll 11 | { 12 | 13 | class KROLL_API StaticBoundMethod : public KMethod 14 | { 15 | public: 16 | 17 | StaticBoundMethod(MethodCallback* callback, const char *type = "StaticBoundMethod"); 18 | virtual ~StaticBoundMethod(); 19 | 20 | /** 21 | * @see KMethod::Call 22 | */ 23 | virtual KValueRef Call(const ValueList& args); 24 | 25 | /** 26 | * @see KObject::Set 27 | */ 28 | virtual void Set(const char *name, KValueRef value); 29 | 30 | /** 31 | * @see KObject::Get 32 | */ 33 | virtual KValueRef Get(const char *name); 34 | 35 | /** 36 | * @see KObject::GetPropertyNames 37 | */ 38 | virtual SharedStringList GetPropertyNames(); 39 | 40 | /** 41 | * Set a property on this object to the given method. When an error 42 | * occurs will throw an exception of type ValueException. 43 | */ 44 | template 45 | void SetMethod(const char *name, void (T::*method)(const ValueList&, KValueRef)) 46 | { 47 | MethodCallback* callback = NewCallback(static_cast(this), method); 48 | 49 | KMethodRef bound_method = new StaticBoundMethod(callback); 50 | KValueRef method_value = Value::NewMethod(bound_method); 51 | this->Set(name, method_value); 52 | } 53 | 54 | template 55 | static AutoPtr FromMethod(T* owner, void (T::*method)(const ValueList&, KValueRef)) 56 | { 57 | MethodCallback* callback = NewCallback(static_cast(owner), method); 58 | return new StaticBoundMethod(callback); 59 | } 60 | 61 | protected: 62 | SharedPtr callback; 63 | AutoPtr object; 64 | std::map properties; 65 | 66 | private: 67 | DISALLOW_EVIL_CONSTRUCTORS(StaticBoundMethod); 68 | }; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /libkroll/binding/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_EVENT_H_ 8 | #define _KR_EVENT_H_ 9 | 10 | namespace kroll 11 | { 12 | class KROLL_API Event : public KAccessorObject 13 | { 14 | public: 15 | Event(AutoPtr target, const std::string& eventName); 16 | void _GetTarget(const ValueList&, KValueRef result); 17 | void _GetType(const ValueList&, KValueRef result); 18 | void _GetTimestamp(const ValueList&, KValueRef result); 19 | void _StopPropagation(const ValueList&, KValueRef result); 20 | void _PreventDefault(const ValueList&, KValueRef result); 21 | static void SetEventConstants(KObject* target); 22 | 23 | AutoPtr target; 24 | std::string eventName; 25 | Poco::Timestamp timestamp; 26 | bool stopped; 27 | bool preventedDefault; 28 | static std::string ALL; 29 | static std::string FOCUSED; 30 | static std::string UNFOCUSED; 31 | static std::string OPEN; 32 | static std::string OPENED; 33 | static std::string CLOSE; 34 | static std::string CLOSED; 35 | static std::string HIDDEN; 36 | static std::string SHOWN; 37 | static std::string REOPEN; 38 | static std::string FULLSCREENED; 39 | static std::string UNFULLSCREENED; 40 | static std::string MAXIMIZED; 41 | static std::string MINIMIZED; 42 | static std::string RESIZED; 43 | static std::string MOVED; 44 | static std::string PAGE_INITIALIZED; 45 | static std::string PAGE_LOADED; 46 | static std::string CREATED; 47 | static std::string ACTIVATE; 48 | static std::string CLICKED; 49 | static std::string DOUBLE_CLICKED; 50 | static std::string EXIT; 51 | static std::string APP_EXIT; 52 | static std::string READ; 53 | static std::string HTTP_DONE; 54 | static std::string HTTP_STATE_CHANGED; 55 | static std::string HTTP_TIMEOUT; 56 | static std::string HTTP_REDIRECT; 57 | static std::string HTTP_ABORT; 58 | static std::string HTTP_DATA_SENT; 59 | static std::string HTTP_DATA_RECEIVED; 60 | static std::string OPEN_REQUEST; 61 | }; 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /modules/python/k_python_method.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "k_python_method.h" 7 | 8 | namespace kroll 9 | { 10 | KPythonMethod::KPythonMethod(PyObject *method) : 11 | KMethod("Python.KMethod"), 12 | method(method), 13 | object(new KPythonObject(method)) 14 | { 15 | PyLockGIL lock; 16 | Py_INCREF(this->method); 17 | } 18 | 19 | KPythonMethod::~KPythonMethod() 20 | { 21 | PyLockGIL lock; 22 | Py_DECREF(this->method); 23 | } 24 | 25 | KValueRef KPythonMethod::Call(const ValueList& args) 26 | { 27 | PyLockGIL lock; 28 | PyObject *arglist = NULL; 29 | 30 | if (args.size() > 0) 31 | { 32 | arglist = PyTuple_New(args.size()); 33 | for (size_t i = 0; i < args.size(); i++) 34 | { 35 | PyObject *pv = PythonUtils::ToPyObject(args[i]); 36 | PyTuple_SetItem(arglist, i, pv); 37 | } 38 | } 39 | 40 | PyObject *response = PyObject_CallObject(this->method, arglist); 41 | Py_XDECREF(arglist); 42 | 43 | KValueRef value = Value::Undefined; 44 | if (response == NULL && PyErr_Occurred() != NULL) 45 | { 46 | THROW_PYTHON_EXCEPTION 47 | } 48 | else if (response != NULL) 49 | { 50 | value = PythonUtils::ToKrollValue(response); 51 | Py_DECREF(response); 52 | } 53 | 54 | return value; 55 | } 56 | 57 | void KPythonMethod::Set(const char *name, KValueRef value) 58 | { 59 | this->object->Set(name, value); 60 | } 61 | 62 | KValueRef KPythonMethod::Get(const char *name) 63 | { 64 | return this->object->Get(name); 65 | } 66 | 67 | SharedStringList KPythonMethod::GetPropertyNames() 68 | { 69 | return this->object->GetPropertyNames(); 70 | } 71 | 72 | PyObject* KPythonMethod::ToPython() 73 | { 74 | return this->object->ToPython(); 75 | } 76 | 77 | bool KPythonMethod::Equals(KObjectRef other) 78 | { 79 | AutoPtr pyOther = other.cast(); 80 | 81 | // This is not a Python object 82 | if (pyOther.isNull()) 83 | return false; 84 | 85 | return pyOther->ToPython() == this->ToPython(); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /libkroll/utils/win32/win32_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_WIN32_UTILS_H_ 7 | #define _KR_WIN32_UTILS_H_ 8 | #include 9 | namespace UTILS_NS 10 | { 11 | namespace Win32Utils 12 | { 13 | /* 14 | * Easily get the result of a FormatMessage 15 | * @param errorCode the error code to get the message for 16 | * @returns a normal, all-American std::string for once 17 | */ 18 | KROLL_API std::string QuickFormatMessage( 19 | DWORD errorCode, 20 | DWORD flags=FORMAT_MESSAGE_FROM_SYSTEM | 21 | FORMAT_MESSAGE_ALLOCATE_BUFFER | 22 | FORMAT_MESSAGE_IGNORE_INSERTS); 23 | }; 24 | 25 | namespace FileUtils 26 | { 27 | KROLL_API void CopyRecursive(const std::string &dir, 28 | const std::string &dest, const std::string& exclude = ""); 29 | 30 | /* Some wchar versions of popular FileUtils functions */ 31 | KROLL_API bool IsFile(const std::wstring& path); 32 | KROLL_API std::string ReadFile(const std::wstring& path); 33 | 34 | /** 35 | * Delete the file at the given path 36 | */ 37 | KROLL_API bool DeleteFile(const std::string &path); 38 | } 39 | 40 | KROLL_API std::wstring UTF8ToWide(const std::string& in); 41 | KROLL_API std::wstring UTF8ToWide(const char* in); 42 | KROLL_API std::string WideToUTF8(const std::wstring& in); 43 | KROLL_API std::string WideToUTF8(const wchar_t* in); 44 | KROLL_API std::string UTF8ToSystem(const std::string& in); 45 | KROLL_API std::string UTF8ToSystem(const char* in); 46 | KROLL_API std::string WideToSystem(const std::wstring& in); 47 | KROLL_API std::string WideToSystem(const wchar_t* in); 48 | 49 | KROLL_API std::wstring MultiByteToWide(const std::string& in, UINT codePage); 50 | KROLL_API std::wstring MultiByteToWide(const char* in, size_t length, UINT codePage); 51 | KROLL_API std::string WideToMultiByte(const std::wstring& in, UINT codePage); 52 | KROLL_API std::string WideToMultiByte(const wchar_t* in, size_t length, UINT codePage); 53 | KROLL_API std::string MultiByteToMultiByte(const std::string& in, UINT codePageIn, 54 | UINT codePageOut); 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /libkroll/utils/kashmir/winundocrand.h: -------------------------------------------------------------------------------- 1 | /********************************************************************\ 2 | * winundocrand.h -- Windows random number generator * 3 | * * 4 | * Copyright (C) 2008 Kenneth Laskoski * 5 | * * 6 | \********************************************************************/ 7 | /** @file winundocrand.h 8 | @brief Windows random number generator 9 | @author Copyright (C) 2008 Kenneth Laskoski 10 | based on work by 11 | @author Copyright (C) 1996, 1997, 1998 Theodore Ts'o 12 | @author Copyright (C) 2004-2008 Ralf S. Engelschall 13 | 14 | Use, modification, and distribution are subject 15 | to the Boost Software License, Version 1.0. (See accompanying file 16 | LICENSE_1_0.txt or a copy at .) 17 | */ 18 | 19 | #ifndef KL_WINUNDOCRAND_H 20 | #define KL_WINUNDOCRAND_H 21 | 22 | #include "randomstream.h" 23 | #include "noncopyable.h" 24 | 25 | #include 26 | 27 | #define WINVER 0x0501 28 | #define _WIN32_WINNT 0x0501 29 | #include 30 | 31 | namespace kashmir { 32 | namespace system { 33 | 34 | class WinUndocRand : public user::randomstream, noncopyable 35 | { 36 | public: 37 | WinUndocRand() : hLib(LoadLibrary("ADVAPI32.DLL")), pfn(0) 38 | { 39 | if (!hLib) 40 | throw std::runtime_error("failed to load ADVAPI32.DLL."); 41 | 42 | pfn = (BOOLEAN (APIENTRY *)(void*,ULONG)) GetProcAddress(hLib,"SystemFunction036"); 43 | if (!pfn) 44 | { 45 | FreeLibrary(hLib); 46 | throw std::runtime_error("failed to get ADVAPI32!RtlGenRandom address."); 47 | } 48 | } 49 | 50 | ~WinUndocRand() 51 | { 52 | FreeLibrary(hLib); 53 | } 54 | 55 | void read(char* buffer, std::size_t count) 56 | { 57 | if (!pfn(buffer, count)) 58 | throw std::runtime_error("system failed to generate random data."); 59 | } 60 | 61 | private: 62 | HMODULE hLib; 63 | BOOLEAN (APIENTRY *pfn)(void*, ULONG); 64 | }; 65 | 66 | }} 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /libkroll/utils/osx/boot_utils_osx.mm: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "../utils.h" 7 | 8 | namespace UTILS_NS 9 | { 10 | namespace BootUtils 11 | { 12 | vector& GetComponentSearchPaths() 13 | { 14 | static std::vector componentSearchPaths; 15 | if (componentSearchPaths.empty()) 16 | { 17 | // Allow the user to force an override to the runtime home by setting the 18 | // appropriate environment variable -- this will be the first path searched 19 | if (EnvironmentUtils::Has("KR_SEARCH_PATH")) 20 | { 21 | componentSearchPaths.push_back(EnvironmentUtils::Get("KR_SEARCH_PATH")); 22 | } 23 | 24 | componentSearchPaths.push_back(FileUtils::GetUserRuntimeHomeDirectory()); 25 | componentSearchPaths.push_back(FileUtils::GetSystemRuntimeHomeDirectory()); 26 | } 27 | return componentSearchPaths; 28 | } 29 | 30 | bool RunInstaller( 31 | vector missing, 32 | SharedApplication application, 33 | std::string updateFile, 34 | std::string installerPath, 35 | bool quiet, 36 | bool forceInstall) 37 | { 38 | if (installerPath.empty()) 39 | { 40 | installerPath = application->path; 41 | } 42 | 43 | string exec = FileUtils::Join( 44 | installerPath.c_str(), 45 | "installer", 46 | "Installer App.app", 47 | "Contents", 48 | "MacOS", 49 | "Installer App", NULL); 50 | 51 | if (!FileUtils::IsFile(exec)) 52 | { 53 | return false; 54 | } 55 | 56 | vector args; 57 | args.push_back("-appPath"); 58 | args.push_back(application->path); 59 | 60 | if (!updateFile.empty()) 61 | { 62 | args.push_back("-updateFile"); 63 | args.push_back(updateFile); 64 | } 65 | 66 | if (quiet) 67 | { 68 | args.push_back("-quiet"); 69 | } 70 | 71 | std::vector::iterator di = missing.begin(); 72 | while (di != missing.end()) 73 | { 74 | SharedDependency d = *di++; 75 | string url = application->GetURLForDependency(d); 76 | args.push_back(url); 77 | } 78 | 79 | FileUtils::RunAndWait(exec, args); 80 | return true; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /libkroll/utils/kashmir/winrandom.h: -------------------------------------------------------------------------------- 1 | /********************************************************************\ 2 | * winrandom.h -- Windows random number generator * 3 | * * 4 | * Copyright (C) 2008 Kenneth Laskoski * 5 | * * 6 | \********************************************************************/ 7 | /** @file winrandom.h 8 | @brief Windows random number generator 9 | @author Copyright (C) 2008 Kenneth Laskoski 10 | based on work by 11 | @author Copyright (C) 1996, 1997, 1998 Theodore Ts'o 12 | @author Copyright (C) 2004-2008 Ralf S. Engelschall 13 | 14 | Use, modification, and distribution are subject 15 | to the Boost Software License, Version 1.0. (See accompanying file 16 | LICENSE_1_0.txt or a copy at .) 17 | */ 18 | 19 | #ifndef KL_WINRANDOM_H 20 | #define KL_WINRANDOM_H 21 | 22 | #include "randomstream.h" 23 | #include "noncopyable.h" 24 | 25 | #include 26 | 27 | #define WINVER 0x0500 28 | #define _WIN32_WINNT 0x0500 29 | #include 30 | #include 31 | 32 | namespace kashmir { 33 | namespace system { 34 | 35 | class WinRandom : public user::randomstream, noncopyable 36 | { 37 | public: 38 | WinRandom() 39 | { 40 | //always initialize member variables. 41 | hProv = NULL; 42 | 43 | // grab the default cryptographic context to verify the machine. 44 | // we don't need access to the private keys, so we use CRYPT_VERIFYCONTEXT 45 | if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) 46 | throw std::runtime_error("failed to acquire cryptographic context."); 47 | } 48 | 49 | ~WinRandom() 50 | { 51 | if ( hProv ) 52 | CryptReleaseContext(hProv, 0); 53 | } 54 | 55 | void read(char* buffer, std::size_t count) 56 | { 57 | if (hProv && !CryptGenRandom(hProv, count, (BYTE*)buffer)) 58 | throw std::runtime_error("system failed to generate random data."); 59 | } 60 | 61 | private: 62 | HCRYPTPROV hProv; 63 | }; 64 | 65 | }} 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /libkroll/utils/linux/file_utils_linux.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "../utils.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using std::string; 22 | 23 | namespace UTILS_NS 24 | { 25 | namespace FileUtils 26 | { 27 | std::string GetUserRuntimeHomeDirectory() 28 | { 29 | string pname = PRODUCT_NAME; 30 | std::transform(pname.begin(), pname.end(), pname.begin(), tolower); 31 | pname = std::string(".") + pname; 32 | 33 | passwd *user = getpwuid(getuid()); 34 | return Join(user->pw_dir, pname.c_str(), NULL); 35 | } 36 | 37 | std::string GetSystemRuntimeHomeDirectory() 38 | { 39 | // Try to be a little smart about where the system runtime home 40 | // is. If we can't find it, just give up and use the /opt location 41 | string pname = PRODUCT_NAME; 42 | std::transform(pname.begin(), pname.end(), pname.begin(), tolower); 43 | string path = Join("/opt", pname.c_str(), NULL); 44 | if (!IsDirectory(path)) 45 | path = Join("/usr/local/lib", pname.c_str(), NULL); 46 | if (!IsDirectory(path)) 47 | path = Join("/usr/lib", pname.c_str(), NULL); 48 | if (!IsDirectory(path)) 49 | path = Join("/opt", pname.c_str(), NULL); 50 | return path; 51 | } 52 | 53 | void WriteFile(const std::string& path, const std::string& content) 54 | { 55 | std::ofstream f(path.c_str()); 56 | f << content; 57 | f.close(); 58 | } 59 | 60 | std::string ReadFile(const std::string& path) 61 | { 62 | std::ostringstream inputStream; 63 | 64 | std::ifstream inputFile(path.c_str()); 65 | 66 | if (!inputFile.is_open()) 67 | return inputStream.str(); 68 | 69 | std::string line; 70 | while (!inputFile.eof()) 71 | { 72 | getline(inputFile, line); 73 | inputStream << line << std::endl; 74 | } 75 | 76 | inputFile.close(); 77 | return inputStream.str(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /modules/ruby/ruby_module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _RUBY_MODULE_H 7 | #define _RUBY_MODULE_H 8 | 9 | #if defined(OS_OSX) || defined(OS_LINUX) 10 | #define EXPORT __attribute__((visibility("default"))) 11 | #define KROLL_RUBY_API EXPORT 12 | #elif defined(OS_WIN32) 13 | # ifdef KROLL_RUBY_API_EXPORT 14 | # define KROLL_RUBY_API __declspec(dllexport) 15 | # else 16 | # define KROLL_RUBY_API __declspec(dllimport) 17 | # endif 18 | #endif 19 | 20 | #ifdef RUBY_METHOD_FUNC 21 | # define VALUEFUNC(f) RUBY_METHOD_FUNC(f) 22 | # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) 23 | #else 24 | # if defined(OS_WIN32) 25 | # define VALUEFUNC(f) ((VALUE (*) (...))f) 26 | # define VOIDFUNC(f) ((void (*)(void *))f) 27 | # else 28 | # define VALUEFUNC(f) ((VALUE (*)(...))f) 29 | # define VOIDFUNC(f) ((void (*)(...))f) 30 | # endif 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #ifndef RARRAY_LEN 39 | # define RARRAY_LEN(x) (RARRAY(x)->len) 40 | #endif 41 | 42 | #undef sleep 43 | #undef close 44 | #undef shutdown 45 | 46 | #include 47 | #include "k_ruby_object.h" 48 | #include "k_ruby_hash.h" 49 | #include "k_ruby_method.h" 50 | #include "k_ruby_list.h" 51 | #include "ruby_utils.h" 52 | #include "ruby_interpreter.h" 53 | #include "ruby_module_instance.h" 54 | 55 | namespace kroll 56 | { 57 | class KROLL_RUBY_API RubyModule : public Module, public ModuleProvider 58 | { 59 | public: 60 | RubyModule(Host* host, const char* path) : 61 | Module(host, path, STRING(MODULE_NAME), STRING(MODULE_VERSION)) 62 | { 63 | } 64 | 65 | ~RubyModule() 66 | { 67 | } 68 | void Initialize(); 69 | void Stop(); 70 | 71 | virtual bool IsModule(std::string& path); 72 | virtual Module* CreateModule(std::string& path); 73 | 74 | Host* GetHost() 75 | { 76 | return host; 77 | } 78 | static RubyModule* Instance() 79 | { 80 | return instance_; 81 | } 82 | 83 | private: 84 | RubyInterpreter interpreter; 85 | static RubyModule *instance_; 86 | DISALLOW_EVIL_CONSTRUCTORS(RubyModule); 87 | }; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /libkroll/ScriptController.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Appcelerator, Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "ScriptController.h" 18 | 19 | #include 20 | 21 | #include "Interpreter.h" 22 | 23 | namespace kroll { 24 | 25 | ScriptController::ScriptController() 26 | { 27 | } 28 | 29 | void ScriptController::AddInterpreter(Interpreter* interpreter, const char* supportedScriptTypes[]) 30 | { 31 | const char* type; 32 | int i = 0; 33 | 34 | while ((type = supportedScriptTypes[i++])) { 35 | interpreters[type] = interpreter; 36 | } 37 | } 38 | 39 | void ScriptController::RemoveInterpreter(Interpreter* interpreter) 40 | { 41 | InterpreterMapping::iterator i = interpreters.begin(); 42 | while (i != interpreters.end()) { 43 | if (i->second == interpreter) 44 | interpreters.erase(i++); 45 | else 46 | ++i; 47 | } 48 | } 49 | 50 | KValueRef ScriptController::EvaluateFile(const char* filepath, KObjectRef context) 51 | { 52 | const char* scriptType = strrchr(filepath, '.'); 53 | if (!scriptType) 54 | throw ValueException::FromFormat("Invalid script path, missing extension: %s", filepath); 55 | ++scriptType; 56 | 57 | Interpreter* interpreter = findInterpreterForType(scriptType); 58 | return interpreter->EvaluateFile(filepath, context); 59 | } 60 | 61 | Interpreter* ScriptController::findInterpreterForType(const char* scriptType) 62 | { 63 | InterpreterMapping::iterator i = interpreters.find(scriptType); 64 | if (i == interpreters.end()) 65 | throw ValueException::FromFormat("Cannot evalute file, invalid script type: %s", scriptType); 66 | 67 | return i->second; 68 | } 69 | 70 | } // namespace kroll 71 | -------------------------------------------------------------------------------- /libkroll/binding/klist.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | #include 11 | 12 | namespace kroll 13 | { 14 | 15 | void KList::ResizeTo(unsigned int size) 16 | { 17 | if (size < 0 || size == this->Size()) 18 | { 19 | return; 20 | } 21 | 22 | while (size < this->Size()) 23 | { 24 | this->Remove(this->Size() - 1); 25 | } 26 | 27 | while (size > this->Size()) 28 | { 29 | this->Append(Value::Undefined); 30 | } 31 | } 32 | 33 | SharedString KList::DisplayString(int levels) 34 | { 35 | std::ostringstream oss; 36 | oss << "(" << this->GetType() << ")" << " ["; 37 | for (unsigned int i = 0; i < this->Size(); i++) 38 | { 39 | KValueRef list_val = this->At(i); 40 | SharedString list_str = list_val->DisplayString(levels-1); 41 | oss << " " << *list_str << ","; 42 | } 43 | //int before_last_comma = oss.tellp() - 1; 44 | //oss.seekp(before_last_comma); 45 | oss << " ]"; 46 | 47 | return new std::string(oss.str()); 48 | } 49 | 50 | /*static*/ 51 | std::string KList::IntToChars(unsigned int value) 52 | { 53 | std::stringstream ss; 54 | ss << value; 55 | return ss.str(); 56 | } 57 | 58 | /*static*/ 59 | bool KList::IsInt(const std::string& name) 60 | { 61 | for (size_t i = 0; i < strlen(name.c_str()); i++) 62 | { 63 | if (!isdigit(name[i])) 64 | return false; 65 | } 66 | return true; 67 | } 68 | 69 | /*static*/ 70 | unsigned int KList::ToIndex(const std::string& str) 71 | { 72 | char* endPointer = 0; 73 | unsigned long result = strtoul(str.c_str(), &endPointer, 10); 74 | 75 | if ((endPointer == str.c_str() && result == 0) || result > UINT_MAX) 76 | { 77 | throw ValueException::FromFormat("Could not convert %s to an unsigned int", 78 | str.c_str()); 79 | } 80 | 81 | return result; 82 | } 83 | 84 | /*static*/ 85 | KListRef KList::Unwrap(KListRef o) 86 | { 87 | AutoPtr plist = o.cast(); 88 | if (plist.isNull()) 89 | { 90 | return o; 91 | } 92 | else 93 | { 94 | return plist->GetDelegate(); 95 | } 96 | } 97 | } 98 | 99 | -------------------------------------------------------------------------------- /libkroll/api/dependency_binding.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008-2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include 7 | #include "dependency_binding.h" 8 | 9 | namespace kroll 10 | { 11 | DependencyBinding::DependencyBinding(SharedDependency dependency) : 12 | KAccessorObject("API.Dependency"), 13 | dependency(dependency) 14 | { 15 | /** 16 | * @tiapi(method=True,name=API.Dependency.getType,since=0.4) 17 | * @tiapi Get the type of this dependency (eg API.MODULE) 18 | * @tiresult[Number] The type of this dependency 19 | */ 20 | this->SetMethod("getType", &DependencyBinding::_GetType); 21 | 22 | /** 23 | * @tiapi(method=True,name=API.Dependency.getName,since=0.4) 24 | * @tiapi Get the name of this dependency 25 | * @tiresult[String] The name of this dependency 26 | */ 27 | this->SetMethod("getName", &DependencyBinding::_GetName); 28 | 29 | /** 30 | * @tiapi(method=True,name=API.Dependency.getVersion,since=0.4) 31 | * @tiapi Get the version of this dependency 32 | * @tiresult[String] The version of this dependency 33 | */ 34 | this->SetMethod("getVersion", &DependencyBinding::_GetVersion); 35 | 36 | /** 37 | * @tiapi(method=True,name=API.Dependency.getRequirement,since=0.4) 38 | * @tiapi Get the requirement for this dependency (eg API.LTE) 39 | * @tiresult[String] The requirement for this dependency 40 | */ 41 | this->SetMethod("getRequirement", &DependencyBinding::_GetRequirement); 42 | } 43 | 44 | SharedDependency DependencyBinding::GetDependency() 45 | { 46 | return dependency; 47 | } 48 | 49 | void DependencyBinding::_GetType(const ValueList& args, KValueRef result) 50 | { 51 | result->SetInt((int) this->dependency->type); 52 | } 53 | 54 | void DependencyBinding::_GetName(const ValueList& args, KValueRef result) 55 | { 56 | result->SetString(this->dependency->name); 57 | } 58 | 59 | void DependencyBinding::_GetVersion(const ValueList& args, KValueRef result) 60 | { 61 | result->SetString(this->dependency->version); 62 | } 63 | 64 | void DependencyBinding::_GetRequirement(const ValueList& args, KValueRef result) 65 | { 66 | result->SetInt(this->dependency->requirement); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /libkroll/binding/k_delegating_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008, 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | 10 | namespace kroll 11 | { 12 | KDelegatingObject::KDelegatingObject(KObjectRef global) : 13 | global(global), 14 | local(new StaticBoundObject()) 15 | { 16 | } 17 | 18 | KDelegatingObject::KDelegatingObject( 19 | KObjectRef global, KObjectRef local) : 20 | global(global), 21 | local(local) 22 | { 23 | } 24 | 25 | KDelegatingObject::~KDelegatingObject() 26 | { 27 | } 28 | 29 | KValueRef KDelegatingObject::Get(const char *name) 30 | { 31 | Poco::Mutex::ScopedLock lock(mutex); 32 | 33 | KValueRef val = local->Get(name); 34 | if (!val->IsUndefined()) 35 | { 36 | // We want properties of the local object to 37 | // override // properties set on the global object. 38 | return val; 39 | } 40 | else 41 | { 42 | // If the property isn't found on the local object, search 43 | // for it in the global object. 44 | return this->global->Get(name); 45 | } 46 | 47 | } 48 | 49 | void KDelegatingObject::Set(const char *name, KValueRef value) 50 | { 51 | // We want to set the property on both 52 | // the local and the global object. 53 | Poco::Mutex::ScopedLock lock(mutex); 54 | local->Set(name, value); 55 | global->Set(name, value); 56 | } 57 | 58 | bool KDelegatingObject::HasProperty(const char* name) 59 | { 60 | return global->HasProperty(name) || local->HasProperty(name); 61 | } 62 | 63 | SharedStringList KDelegatingObject::GetPropertyNames() 64 | { 65 | Poco::Mutex::ScopedLock lock(mutex); 66 | 67 | SharedStringList globalList = global->GetPropertyNames(); 68 | SharedStringList localList = local->GetPropertyNames(); 69 | 70 | for (size_t i = 0; i < globalList->size(); i++) 71 | { 72 | bool found = false; 73 | for (size_t j = 0; j < localList->size(); j++) 74 | { 75 | if (globalList->at(i).get() == localList->at(j).get()) 76 | { 77 | found = true; 78 | break; 79 | } 80 | } 81 | 82 | if (!found) 83 | { 84 | localList->push_back(globalList->at(i)); 85 | } 86 | } 87 | 88 | return localList; 89 | } 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /libkroll/binding/static_bound_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_STATIC_BOUND_LIST_H_ 8 | #define _KR_STATIC_BOUND_LIST_H_ 9 | 10 | namespace kroll 11 | { 12 | 13 | class KROLL_API StaticBoundList : public KList 14 | { 15 | public: 16 | 17 | StaticBoundList(const char *type = "StaticBoundList"); 18 | virtual ~StaticBoundList(); 19 | static KListRef FromStringVector(std::vector&); 20 | 21 | /** 22 | * Append a value to this list 23 | * Errors will result in a thrown ValueException 24 | */ 25 | virtual void Append(KValueRef value); 26 | 27 | /** 28 | * Get the length of this list. 29 | */ 30 | virtual unsigned int Size(); 31 | 32 | /** 33 | * @return the value at the given index. 34 | * Errors will result in a thrown ValueException 35 | */ 36 | virtual KValueRef At(unsigned int index); 37 | 38 | /** 39 | * Set a property on this object to the given value 40 | * Errors will result in a thrown ValueException 41 | */ 42 | virtual void Set(const char *name, KValueRef value); 43 | 44 | /** 45 | * Remove the list entry at the given index. 46 | * Errors will result in a thrown ValueException 47 | * @return true if found and removed, false otherwise 48 | */ 49 | virtual bool Remove(unsigned int index); 50 | 51 | /** 52 | * Set the value at the given index. If the index is greater 53 | * than the current list length, the list will be lengenthed 54 | * by appending Value::Undefined; 55 | * Errors will result in a thrown ValueException 56 | */ 57 | virtual void SetAt(unsigned int index, KValueRef value); 58 | 59 | /** 60 | * @return the property with the given name or Value::Undefined 61 | * if the property is not found. 62 | * Errors will result in a thrown ValueException 63 | */ 64 | virtual KValueRef Get(const char *name); 65 | 66 | /** 67 | * @return a list of this object's property names. 68 | */ 69 | virtual SharedStringList GetPropertyNames(); 70 | 71 | protected: 72 | AutoPtr object; 73 | unsigned int length; 74 | 75 | private: 76 | DISALLOW_EVIL_CONSTRUCTORS(StaticBoundList); 77 | }; 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /libkroll/javascript/javascript_module_instance.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "javascript_module.h" 7 | #include 8 | #include 9 | #include 10 | 11 | namespace kroll 12 | { 13 | static std::vector instanceContexts; 14 | 15 | JavaScriptModuleInstance::JavaScriptModuleInstance(Host* host, std::string path, std::string dir, std::string name) : 16 | Module(host, dir.c_str(), name.c_str(), "0.1"), 17 | path(path), 18 | context(0) 19 | { 20 | this->context = KJSUtil::CreateGlobalContext(); 21 | KJSUtil::ProtectGlobalContext(context); 22 | 23 | try 24 | { 25 | this->Run(); 26 | } 27 | catch (ValueException& e) 28 | { 29 | SharedString ss = e.GetValue()->DisplayString(); 30 | Logger *logger = Logger::Get("JavaScript"); 31 | logger->Error("Could not execute %s because %s", path.c_str(), (*ss).c_str()); 32 | } 33 | 34 | instanceContexts.push_back(this->context); 35 | } 36 | 37 | void JavaScriptModuleInstance::Stop() 38 | { 39 | KJSUtil::UnregisterGlobalContext(context); 40 | KJSUtil::UnprotectGlobalContext(context); 41 | 42 | std::vector::iterator i = instanceContexts.begin(); 43 | while (i != instanceContexts.end()) 44 | { 45 | if (*i == this->context) 46 | { 47 | instanceContexts.erase(i); 48 | break; 49 | } 50 | i++; 51 | } 52 | 53 | this->context = 0; 54 | } 55 | 56 | void JavaScriptModuleInstance::Run() 57 | { 58 | std::string code(FileUtils::ReadFile(this->path)); 59 | 60 | // Check the script's syntax. 61 | JSValueRef exception; 62 | JSStringRef jsCode = JSStringCreateWithUTF8CString(code.c_str()); 63 | bool syntax = JSCheckScriptSyntax(context, jsCode, NULL, 0, &exception); 64 | if (!syntax) 65 | { 66 | KValueRef e = KJSUtil::ToKrollValue(exception, context, NULL); 67 | JSStringRelease(jsCode); 68 | throw ValueException(e); 69 | } 70 | 71 | KJSUtil::Evaluate(context, code.c_str()); 72 | } 73 | 74 | /*static*/ 75 | void JavaScriptModuleInstance::GarbageCollect() 76 | { 77 | for (size_t i = 0; i < instanceContexts.size(); i++) 78 | JSGarbageCollect(instanceContexts[i]); 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /libkroll/binding/k_event_method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_EVENT_METHOD_H_ 8 | #define _KR_EVENT_METHOD_H_ 9 | 10 | 11 | namespace kroll 12 | { 13 | class KROLL_API KEventMethod : public KEventObject, public KMethod 14 | { 15 | public: 16 | KEventMethod(const char* name = "") : 17 | KEventObject(name), 18 | count(1) {} 19 | 20 | // @see KMethod::Call 21 | virtual KValueRef Call(const ValueList& args) = 0; 22 | 23 | // @see KMethod::Set 24 | virtual void Set(const char *name, KValueRef value) 25 | { 26 | KEventObject::Set(name, value); 27 | } 28 | 29 | // @see KMethod::Get 30 | virtual KValueRef Get(const char *name) 31 | { 32 | return KEventObject::Get(name); 33 | } 34 | 35 | // @see KMethod::GetPropertyNames 36 | virtual SharedStringList GetPropertyNames() 37 | { 38 | return KEventObject::GetPropertyNames(); 39 | } 40 | 41 | // @see KMethod::HasProperty 42 | virtual bool HasProperty(const char *name) 43 | { 44 | return KEventObject::HasProperty(name); 45 | } 46 | 47 | // @see KMethod::DisplayString 48 | SharedString DisplayString(int levels) 49 | { 50 | return KEventObject::DisplayString(levels); 51 | } 52 | 53 | /** 54 | * Set a property on this object to the given method. When an error 55 | * occurs will throw an exception of type ValueException. 56 | */ 57 | template 58 | void SetMethod(const char *name, void (T::*method)(const ValueList&, KValueRef)) 59 | { 60 | MethodCallback* callback = NewCallback(static_cast(this), method); 61 | 62 | KMethodRef bound_method = new StaticBoundMethod(callback); 63 | KValueRef method_value = Value::NewMethod(bound_method); 64 | KEventObject::Set(name, method_value); 65 | } 66 | 67 | virtual void duplicate() 68 | { 69 | ++count; 70 | } 71 | 72 | virtual void release() 73 | { 74 | int value = --count; 75 | if (value <= 0) { 76 | delete this; 77 | } 78 | } 79 | 80 | virtual int referenceCount() const 81 | { 82 | return count.value(); 83 | } 84 | 85 | private: 86 | Poco::AtomicCounter count; 87 | 88 | }; 89 | 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /libkroll/main_thread_job.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include 8 | #include "kroll.h" 9 | 10 | namespace kroll 11 | { 12 | 13 | MainThreadJob::MainThreadJob(KMethodRef method, KObjectRef thisObject, 14 | const ValueList& args, bool waitForCompletion) : 15 | method(method), 16 | thisObject(thisObject), 17 | args(args), 18 | waitForCompletion(waitForCompletion), 19 | returnValue(NULL), 20 | exception(ValueException(NULL)), 21 | semaphore(0, 1) 22 | { 23 | // The semaphore starts at 0, meaning that the calling 24 | // thread can wait for the value to become >0 using wait() 25 | // and the main thread can call set() after job execution 26 | // which meets this condition. 27 | } 28 | 29 | void MainThreadJob::Wait() 30 | { 31 | if (this->waitForCompletion) 32 | this->semaphore.wait(); 33 | } 34 | 35 | void MainThreadJob::Execute() 36 | { 37 | try 38 | { 39 | if (thisObject.isNull()) 40 | this->returnValue = this->method->Call(this->args); 41 | else 42 | this->returnValue = this->method->Call(thisObject, this->args); 43 | } 44 | catch (ValueException& e) 45 | { 46 | this->exception = e; 47 | } 48 | catch (Poco::SystemException& e) 49 | { 50 | this->exception = ValueException::FromString(e.displayText()); 51 | } 52 | catch (std::exception& e) 53 | { 54 | this->exception = ValueException::FromString(e.what()); 55 | } 56 | catch (...) 57 | { 58 | this->exception = ValueException::FromString("Unknown Exception from job queue"); 59 | } 60 | 61 | if (this->waitForCompletion) 62 | this->semaphore.set(); 63 | } 64 | 65 | KValueRef MainThreadJob::GetResult() 66 | { 67 | return this->returnValue; 68 | } 69 | 70 | ValueException MainThreadJob::GetException() 71 | { 72 | return this->exception; 73 | } 74 | 75 | bool MainThreadJob::ShouldWaitForCompletion() 76 | { 77 | return this->waitForCompletion; 78 | } 79 | 80 | void MainThreadJob::PrintException() 81 | { 82 | static Logger* logger = Logger::Get("Host"); 83 | if (this->returnValue.isNull()) 84 | { 85 | logger->Error("Error in the job queue: %s", 86 | this->exception.ToString().c_str()); 87 | } 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /libkroll/binding/static_bound_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _KR_STATIC_BOUND_OBJECT_H_ 8 | #define _KR_STATIC_BOUND_OBJECT_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace kroll 17 | { 18 | /** 19 | * Extending this class is the easiest way to get started with your own 20 | * KObject implementation. In your sub-class' constructor, you can bind 21 | * properties and methods, i.e: 22 | * \code 23 | * MyObject::MyObject() { 24 | * this->Set("x", Value::NewInt(100)); 25 | * this->Set("description", Value::NewString("my object")); 26 | * this->SetMethod("add", &MyObject::Add); 27 | * } 28 | * 29 | * void MyObject::Add(const ValueList& args, KValueRef result) { 30 | * result->SetInt(args[0]->ToInt() + args[1]->ToInt()); 31 | * } 32 | * \endcode 33 | * 34 | * And a supported language would access your object ala: 35 | * \code 36 | * var myObject = //.. 37 | * alert(myObject.x); // 100 38 | * alert(myObject.description); // "my object" 39 | * alert(myObject.add(10, 15)); // 25 40 | * \endcode 41 | */ 42 | class KROLL_API StaticBoundObject : public KObject 43 | { 44 | public: 45 | StaticBoundObject(const char* type = "StaticBoundObject"); 46 | virtual ~StaticBoundObject(); 47 | 48 | virtual bool HasProperty(const char* name); 49 | virtual KValueRef Get(const char* name); 50 | virtual SharedStringList GetPropertyNames(); 51 | virtual void Set(const char* name, KValueRef value); 52 | virtual void Unset(const char* name); 53 | 54 | /** 55 | * Set a property on this object to the given method. When an error 56 | * occurs will throw an exception of type ValueException. 57 | */ 58 | template 59 | void SetMethod(const char* name, void (T::*method)(const ValueList&, KValueRef)) 60 | { 61 | this->Set(name, Value::NewMethod(new StaticBoundMethod( 62 | NewCallback(static_cast(this), method)))); 63 | } 64 | 65 | 66 | protected: 67 | std::map properties; 68 | Poco::Mutex mutex; 69 | 70 | private: 71 | DISALLOW_EVIL_CONSTRUCTORS(StaticBoundObject); 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /libkroll/api/application_binding.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _APPLICATION_BINDING_H_ 8 | #define _APPLICATION_BINDING_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace kroll 16 | { 17 | class ApplicationBinding : public KAccessorObject 18 | { 19 | public: 20 | ApplicationBinding(SharedApplication application, bool current = false); 21 | 22 | private: 23 | SharedApplication application; 24 | bool current; 25 | 26 | void _GetID(const ValueList& args, KValueRef value); 27 | void _GetGUID(const ValueList& args, KValueRef value); 28 | void _GetName(const ValueList& args, KValueRef result); 29 | void _GetVersion(const ValueList& args, KValueRef value); 30 | void _GetPath(const ValueList& args, KValueRef value); 31 | void _GetExecutablePath(const ValueList& args, KValueRef value); 32 | void _GetResourcesPath(const ValueList& args, KValueRef value); 33 | void _GetDataPath(const ValueList& args, KValueRef value); 34 | void _GetManifestPath(const ValueList& args, KValueRef value); 35 | void _GetManifest(const ValueList& args, KValueRef value); 36 | void _GetProperties(const ValueList& args, KValueRef value); 37 | void _IsCurrent(const ValueList& args, KValueRef value); 38 | void _GetPID(const ValueList& args, KValueRef value); 39 | void _GetArguments(const ValueList& args, KValueRef value); 40 | void _HasArgument(const ValueList& args, KValueRef value); 41 | void _GetArgumentValue(const ValueList& args, KValueRef value); 42 | void _GetDependencies(const ValueList& args, KValueRef value); 43 | void _ResolveDependencies(const ValueList& args, KValueRef value); 44 | void _GetComponents(const ValueList& args, KValueRef value); 45 | void _GetModules(const ValueList& args, KValueRef value); 46 | void _GetRuntime(const ValueList& args, KValueRef value); 47 | void _GetAvailableComponents(const ValueList& args, KValueRef value); 48 | void _GetAvailableModules(const ValueList& args, KValueRef value); 49 | void _GetAvailableRuntimes(const ValueList& args, KValueRef value); 50 | void _GetBundledComponents(const ValueList& args, KValueRef value); 51 | void _GetBundledModules(const ValueList& args, KValueRef value); 52 | void _GetBundledRuntimes(const ValueList& args, KValueRef value); 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /libkroll/utils/osx/osx_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _KR_OSX_UTILS_H_ 7 | #define _KR_OSX_UTILS_H_ 8 | 9 | #include 10 | #include 11 | 12 | // Most of the code was adapted from code in Chromium's src/base/... 13 | namespace UTILS_NS 14 | { 15 | KROLL_API std::string CFStringToUTF8(CFStringRef cfstring); 16 | KROLL_API CFStringRef UTF8ToCFString(const std::string& input); 17 | KROLL_API std::string CFErrorToString(CFErrorRef cferror); 18 | 19 | // CFRef<> is patterned after scoped_ptr<>, but maintains ownership 20 | // of a CoreFoundation object: any object that can be represented as a 21 | // CFTypeRef. Style deviations here are solely for compatibility with 22 | // scoped_ptr<>'s interface, with which everyone is already familiar. 23 | // 24 | // When CFRef<> takes ownership of an object (in the constructor or 25 | // in reset()), it takes over the caller's existing ownership claim. The 26 | // caller must own the object it gives to CFRef<>, and relinquishes 27 | // an ownership claim to that object. CFRef<> does not call 28 | // CFRetain(). 29 | template 30 | class CFRef { 31 | public: 32 | typedef CFT element_type; 33 | explicit CFRef(CFT object = NULL) : 34 | object_(object) { } 35 | 36 | ~CFRef() 37 | { 38 | if (object_) 39 | CFRelease(object_); 40 | } 41 | 42 | void reset(CFT object = NULL) 43 | { 44 | if (object_) 45 | CFRelease(object_); 46 | object_ = object; 47 | } 48 | 49 | bool operator==(CFT that) const 50 | { 51 | return object_ == that; 52 | } 53 | 54 | bool operator!=(CFT that) const 55 | { 56 | return object_ != that; 57 | } 58 | 59 | operator CFT() const 60 | { 61 | return object_; 62 | } 63 | 64 | CFT get() const 65 | { 66 | return object_; 67 | } 68 | 69 | void swap(CFRef& that) 70 | { 71 | CFT temp = that.object_; 72 | that.object_ = object_; 73 | object_ = temp; 74 | } 75 | 76 | // CFRef<>::release() is like scoped_ptr<>::release. It is NOT 77 | // a wrapper for CFRelease(). To force a CFRef<> object to call 78 | // CFRelease(), use CFRef<>::reset(). 79 | CFT release() 80 | { 81 | CFT temp = object_; 82 | object_ = NULL; 83 | return temp; 84 | } 85 | 86 | private: 87 | CFT object_; 88 | }; 89 | 90 | } 91 | #endif 92 | -------------------------------------------------------------------------------- /modules/python/python_module.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #ifndef _PYTHON_MODULE_H 7 | #define _PYTHON_MODULE_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "python_api.h" 16 | #include "python_utils.h" 17 | #include "k_python_object.h" 18 | #include "k_python_method.h" 19 | #include "k_python_list.h" 20 | #include "k_python_tuple.h" 21 | #include "k_python_dict.h" 22 | #include "python_interpreter.h" 23 | 24 | #define THROW_PYTHON_EXCEPTION \ 25 | PyObject *_ptype, *_pvalue, *_trace; \ 26 | PyErr_Fetch(&_ptype, &_pvalue, &_trace); \ 27 | ValueException _ex = ValueException::FromString("Unknown"); \ 28 | if (_pvalue != NULL) \ 29 | { \ 30 | KValueRef _ex_val = PythonUtils::ToKrollValue(_pvalue); \ 31 | _ex = ValueException(_ex_val); \ 32 | } \ 33 | Py_XDECREF(_ptype); \ 34 | Py_XDECREF(_pvalue); \ 35 | Py_XDECREF(_trace); \ 36 | throw _ex; 37 | 38 | namespace kroll 39 | { 40 | class KROLL_PYTHON_API PythonModule : public Module, public ModuleProvider 41 | { 42 | public: 43 | PythonModule(Host* host, const char* path) : 44 | Module(host, path, STRING(MODULE_NAME), STRING(MODULE_VERSION)) 45 | { 46 | } 47 | 48 | ~PythonModule() 49 | { 50 | } 51 | 52 | void Initialize(); 53 | void Stop(); 54 | 55 | virtual bool IsModule(std::string& path); 56 | virtual Module* CreateModule(std::string& path); 57 | 58 | Host* GetHost() 59 | { 60 | return host; 61 | } 62 | 63 | static PythonModule* Instance() 64 | { 65 | return instance_; 66 | } 67 | 68 | private: 69 | PythonInterpreter interpreter; 70 | static PythonModule *instance_; 71 | DISALLOW_EVIL_CONSTRUCTORS(PythonModule); 72 | }; 73 | 74 | struct PyLockGIL 75 | { 76 | PyLockGIL() : gstate(PyGILState_Ensure()) 77 | { } 78 | 79 | ~PyLockGIL() 80 | { 81 | PyGILState_Release(gstate); 82 | } 83 | 84 | PyGILState_STATE gstate; 85 | }; 86 | 87 | struct PyAllowThreads 88 | { 89 | PyAllowThreads() : threadState(PyEval_SaveThread()) 90 | { } 91 | 92 | ~PyAllowThreads() 93 | { 94 | PyEval_RestoreThread(threadState); 95 | } 96 | 97 | PyThreadState* threadState; 98 | }; 99 | } 100 | 101 | #include "python_module_instance.h" 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /libkroll/utils/osx/osx_utils.mm: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "../utils.h" 7 | #include 8 | 9 | namespace UTILS_NS 10 | { 11 | 12 | std::string CFStringToUTF8(CFStringRef cfstring) 13 | { 14 | CFIndex length = CFStringGetLength(cfstring); 15 | if (length == 0) 16 | return std::string(); 17 | 18 | CFRange wholeString = CFRangeMake(0, length); 19 | CFIndex outSize; 20 | CFIndex converted = CFStringGetBytes(cfstring, 21 | wholeString, 22 | kCFStringEncodingUTF8, 23 | 0, // lossByte 24 | false, // isExternalRepresentation 25 | NULL, // buffer 26 | 0, // maxBufLen 27 | &outSize); 28 | 29 | if (converted == 0 || outSize == 0) 30 | return std::string(); 31 | 32 | // outSize is the number of UInt8-sized units needed in the destination. 33 | // A buffer allocated as UInt8 units might not be properly aligned to 34 | // contain elements of std::string::value_type. Use a container for the 35 | // proper value_type, and convert outSize by figuring the number of 36 | // value_type elements per UInt8. Leave room for a NUL terminator. 37 | std::string::size_type elements = outSize + 1; 38 | 39 | std::vector outBuffer(elements); 40 | converted = CFStringGetBytes(cfstring, 41 | wholeString, 42 | kCFStringEncodingUTF8, 43 | 0, // lossByte 44 | false, // isExternalRepresentation 45 | reinterpret_cast(&outBuffer[0]), 46 | outSize, 47 | NULL); // usedBufLen 48 | 49 | if (converted == 0) 50 | return std::string(); 51 | 52 | outBuffer[elements - 1] = '\0'; 53 | return std::string(&outBuffer[0], elements - 1); 54 | } 55 | 56 | CFStringRef UTF8ToCFString(const std::string& input) 57 | { 58 | std::string::size_type length = input.length(); 59 | if (length == 0) 60 | return CFSTR(""); 61 | 62 | return CFStringCreateWithBytes(kCFAllocatorDefault, 63 | reinterpret_cast(input.data()), 64 | length * sizeof(std::string::value_type), 65 | kCFStringEncodingUTF8, false); 66 | } 67 | 68 | std::string CFErrorToString(CFErrorRef cferror) 69 | { 70 | CFStringRef cferrorString = CFErrorCopyDescription(cferror); 71 | std::string errorString("Could not get error string"); 72 | if (cferrorString) 73 | { 74 | errorString = CFStringToUTF8(cferrorString); 75 | CFRelease(cferrorString); 76 | } 77 | CFRelease(cferror); 78 | 79 | return errorString; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /libkroll/binding/kmethod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #ifndef _K_METHOD_H_ 8 | #define _K_METHOD_H_ 9 | #include 10 | 11 | namespace kroll 12 | { 13 | typedef Callback2::Type MethodCallback; 14 | 15 | /** 16 | * An abstract representation of a method 17 | */ 18 | class KROLL_API KMethod : public KObject 19 | { 20 | 21 | public: 22 | 23 | KMethod(const char *type = "KMethod") : KObject(type) {} 24 | virtual ~KMethod() {} 25 | 26 | /** 27 | * Call this method with the given arguments. 28 | * Errors will result in a thrown ValueException 29 | * @return the return value of this method 30 | */ 31 | virtual KValueRef Call(const ValueList& args) = 0; 32 | 33 | /** 34 | * Call this method with the given 'this' object and arguments. 35 | * Errors will result in a thrown ValueException 36 | * @return the return value of this method 37 | */ 38 | virtual KValueRef Call(KObjectRef thisObject, const ValueList& args); 39 | 40 | /** 41 | * Set a property on this object to the given value 42 | * Errors will result in a thrown ValueException 43 | */ 44 | virtual void Set(const char* name, KValueRef value) = 0; 45 | 46 | /** 47 | * @return the property with the given name or Value::Undefined 48 | * if the property is not found. 49 | * Errors will result in a thrown ValueException 50 | */ 51 | virtual KValueRef Get(const char* name) = 0; 52 | 53 | /** 54 | * @return a list of this object's property names. 55 | */ 56 | virtual SharedStringList GetPropertyNames() = 0; 57 | 58 | /** 59 | * @return a string representation of this object 60 | */ 61 | SharedString DisplayString(int levels); 62 | 63 | /** 64 | * Return the unwrapped version of this object 65 | */ 66 | static KMethodRef Unwrap(KMethodRef); 67 | 68 | /* Convenience methods below */ 69 | KValueRef Call(KValueRef one); 70 | KValueRef Call(KValueRef one, KValueRef two); 71 | KValueRef Call(KValueRef one, KValueRef two, KValueRef three); 72 | KValueRef Call(); 73 | KValueRef Call(const char* one); 74 | KValueRef Call(const char* one, KValueRef two); 75 | KValueRef Call(const char* one, KValueRef two, KValueRef three); 76 | KValueRef Call(const char* one, KValueRef two, KValueRef three, 77 | KValueRef four); 78 | 79 | private: 80 | DISALLOW_EVIL_CONSTRUCTORS(KMethod); 81 | }; 82 | } 83 | 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /libkroll/utils/poco/KDigestEngine.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | // 7 | // DigestEngine.cpp 8 | // 9 | // $Id: //poco/1.3/Foundation/src/DigestEngine.cpp#1 $ 10 | // 11 | // Library: Foundation 12 | // Package: Crypt 13 | // Module: DigestEngine 14 | // 15 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 16 | // and Contributors. 17 | // 18 | // Permission is hereby granted, free of charge, to any person or organization 19 | // obtaining a copy of the software and accompanying documentation covered by 20 | // this license (the "Software") to use, reproduce, display, distribute, 21 | // execute, and transmit the Software, and to prepare derivative works of the 22 | // Software, and to permit third-parties to whom the Software is furnished to 23 | // do so, all subject to the following: 24 | // 25 | // The copyright notices in the Software and this entire statement, including 26 | // the above license grant, this restriction and the following disclaimer, 27 | // must be included in all copies of the Software, in whole or in part, and 28 | // all derivative works of the Software, unless such copies or derivative 29 | // works are solely in the form of machine-executable object code generated by 30 | // a source language processor. 31 | // 32 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 35 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 36 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 37 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 38 | // DEALINGS IN THE SOFTWARE. 39 | // 40 | 41 | 42 | #include "KDigestEngine.h" 43 | 44 | 45 | namespace KPoco { 46 | 47 | 48 | DigestEngine::DigestEngine() 49 | { 50 | } 51 | 52 | 53 | DigestEngine::~DigestEngine() 54 | { 55 | } 56 | 57 | 58 | std::string DigestEngine::digestToHex(const Digest& bytes) 59 | { 60 | static const char digits[] = "0123456789abcdef"; 61 | std::string result; 62 | result.reserve(bytes.size()*2); 63 | for (Digest::const_iterator it = bytes.begin(); it != bytes.end(); ++it) 64 | { 65 | unsigned char c = *it; 66 | result += digits[(c >> 4) & 0xF]; 67 | result += digits[c & 0xF]; 68 | } 69 | return result; 70 | } 71 | 72 | 73 | } // namespace KPoco 74 | -------------------------------------------------------------------------------- /SConscript.thirdparty: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import effess 3 | import os 4 | import sys 5 | import inspect 6 | import urllib 7 | import tarfile 8 | import os.path as path 9 | import distutils.dir_util as dirutil 10 | from progressbar import ProgressBar 11 | Import('build') 12 | 13 | revisions = { 14 | "linux-i386": 41, 15 | "linux-x86_64": 31, 16 | "osx-i386": 7, 17 | "win32-i386": 43 18 | } 19 | 20 | thirdparty_name = 'thirdparty-%s-%s-r%s' % (build.os, build.arch, revisions[build.os+'-'+build.arch]) 21 | url = 'http://kroll.appcelerator.com.s3.amazonaws.com/kroll-%s.tgz' % (thirdparty_name) 22 | 23 | build.third_party = path.join(build.cwd(), thirdparty_name) 24 | rtdir = build.runtime_build_dir 25 | 26 | def exists(): 27 | return path.isdir(build.third_party) 28 | 29 | def fetch(): 30 | print "You don't seem to have the appropriate thirdparty files. I'll fetch them." 31 | print "Downloading %s" % url 32 | 33 | pbar = ProgressBar().start() 34 | try: 35 | def progress_callback(count, block_size, total_size): 36 | if (total_size < 0): 37 | raise Exception("Could not fetch archive! Does it exist on the server?") 38 | percent = int(count * block_size * 100/total_size) 39 | pbar.update(percent) 40 | 41 | fname, msg = urllib.urlretrieve(url, reporthook=progress_callback) 42 | 43 | print "Fetched it (%s). I'm going to unpack it now..." % (fname) 44 | os.makedirs(build.third_party) 45 | tfile = tarfile.open(fname, mode="r:gz") 46 | tfile.extractall(path=build.third_party) 47 | finally: 48 | urllib.urlcleanup() 49 | pbar.finish() 50 | 51 | if not exists(): fetch() 52 | 53 | if build.is_linux(): 54 | effess.copy_tree(path.join(build.third_party, 'webkit', 'lib'), rtdir) 55 | effess.copy_tree(path.join(build.third_party, 'poco', 'lib'), rtdir) 56 | 57 | elif build.is_win32(): 58 | effess.copy_tree(path.join(build.third_party, 'poco', 'bin'), rtdir) 59 | effess.copy_tree(path.join(build.third_party, 'webkit', 'bin'), rtdir) 60 | effess.copy_tree(path.join(build.third_party, 'sdk'), path.join(build.dir, 'sdk')) 61 | 62 | elif build.is_osx(): 63 | excludes = ['.h', '.defs', 'JavaScriptGlue.framework'] 64 | targets = [] 65 | for framework in Glob(path.join(build.third_party, '*/*.framework')): 66 | t = build.utils.CopyToDir(framework, rtdir, exclude=excludes) 67 | targets.append(t) 68 | 69 | # PHP dependencies don't aren't distributed with the runtime, only Poco's. 70 | # for libdir in Glob(path.join(build.third_party, '*/lib')): 71 | libdir = path.join(build.third_party, "poco", "lib"); 72 | targets.append(build.utils.CopyTree(libdir, rtdir, exclude=excludes)) 73 | build.mark_build_target(targets) 74 | 75 | -------------------------------------------------------------------------------- /libkroll/binding/kmethod.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | #include 9 | #include 10 | 11 | namespace kroll 12 | { 13 | 14 | SharedString KMethod::DisplayString(int levels) 15 | { 16 | std::ostringstream oss; 17 | oss << "<" << this->GetType() << " at " << this << ">"; 18 | return new std::string(oss.str()); 19 | } 20 | 21 | KValueRef KMethod::Call(KObjectRef thisObject, const ValueList& args) 22 | { 23 | return this->Call(args); 24 | } 25 | 26 | KValueRef KMethod::Call() 27 | { 28 | return this->Call(ValueList()); 29 | } 30 | 31 | KValueRef KMethod::Call(const char* one, KValueRef two, KValueRef three, 32 | KValueRef four) 33 | { 34 | ValueList args; 35 | args.push_back(Value::NewString(one)); 36 | args.push_back(two); 37 | args.push_back(three); 38 | args.push_back(four); 39 | return this->Call(args); 40 | } 41 | 42 | KValueRef KMethod::Call(KValueRef one) 43 | { 44 | ValueList args; 45 | args.push_back(one); 46 | return this->Call(args); 47 | } 48 | 49 | KValueRef KMethod::Call(KValueRef one, KValueRef two) 50 | { 51 | ValueList args; 52 | args.push_back(one); 53 | args.push_back(two); 54 | return this->Call(args); 55 | } 56 | 57 | KValueRef KMethod::Call(KValueRef one, KValueRef two, KValueRef three) 58 | { 59 | ValueList args; 60 | args.push_back(one); 61 | args.push_back(two); 62 | args.push_back(three); 63 | return this->Call(args); 64 | } 65 | 66 | KValueRef KMethod::Call(const char* one) 67 | { 68 | ValueList args; 69 | args.push_back(Value::NewString(one)); 70 | return this->Call(args); 71 | } 72 | 73 | KValueRef KMethod::Call(const char* one, KValueRef two) 74 | { 75 | ValueList args; 76 | args.push_back(Value::NewString(one)); 77 | args.push_back(two); 78 | return this->Call(args); 79 | } 80 | 81 | KValueRef KMethod::Call(const char* one, KValueRef two, KValueRef three) 82 | { 83 | ValueList args; 84 | args.push_back(Value::NewString(one)); 85 | args.push_back(two); 86 | args.push_back(three); 87 | return this->Call(args); 88 | } 89 | 90 | KMethodRef KMethod::Unwrap(KMethodRef o) 91 | { 92 | AutoPtr pmeth = o.cast(); 93 | if (pmeth.isNull()) 94 | { 95 | return o; 96 | } 97 | else 98 | { 99 | return pmeth->GetDelegate(); 100 | } 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /libkroll/binding/scope_method_delegate.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "../kroll.h" 8 | 9 | using namespace kroll; 10 | 11 | ScopeMethodDelegate::ScopeMethodDelegate(MethodDelegateType type, 12 | KObjectRef global, 13 | KObjectRef scope, 14 | KMethodRef delegate) : 15 | type(type), global(global), scope(scope), delegate(delegate) 16 | { 17 | } 18 | 19 | ScopeMethodDelegate::~ScopeMethodDelegate() 20 | { 21 | } 22 | 23 | 24 | void ScopeMethodDelegate::Set(const char *name, KValueRef value) 25 | { 26 | delegate->Set(name,value); 27 | } 28 | 29 | KValueRef ScopeMethodDelegate::Get(const char *name) 30 | { 31 | return delegate->Get(name); 32 | } 33 | 34 | SharedStringList ScopeMethodDelegate::GetPropertyNames() 35 | { 36 | return delegate->GetPropertyNames(); 37 | } 38 | 39 | bool ScopeMethodDelegate::IsGlobalKey(std::string& key) 40 | { 41 | std::string::size_type pos = key.find_first_of("."); 42 | return (pos!=std::string::npos); 43 | } 44 | 45 | KValueRef ScopeMethodDelegate::Call(const ValueList& args) 46 | { 47 | std::string key = args.at(0)->ToString(); 48 | KObjectRef obj = IsGlobalKey(key) ? global : scope; 49 | if (type == GET) 50 | { 51 | // not found, look inside scope 52 | return obj->Get(key.c_str()); 53 | } 54 | else 55 | { 56 | KValueRef result = args.at(1); 57 | obj->SetNS(key.c_str(),result); 58 | return Value::Undefined; 59 | } 60 | } 61 | 62 | AutoPtr ScopeMethodDelegate::CreateDelegate(KObjectRef global, KObjectRef bo) 63 | { 64 | AutoPtr scope = new StaticBoundObject(); 65 | SharedStringList keys = bo->GetPropertyNames(); 66 | StringList::iterator iter = keys->begin(); 67 | 68 | while(iter!=keys->end()) 69 | { 70 | SharedString key_ptr = (*iter++); 71 | std::string key = *key_ptr; 72 | KValueRef value = bo->Get(key.c_str()); 73 | 74 | if (key == "set") 75 | { 76 | KMethodRef d = new ScopeMethodDelegate(SET, global, scope, value->ToMethod()); 77 | KValueRef v = Value::NewMethod(d); 78 | scope->Set(key.c_str(), v); 79 | } 80 | else if (key == "get") 81 | { 82 | KMethodRef d = new ScopeMethodDelegate(GET, global, scope, value->ToMethod()); 83 | KValueRef v = Value::NewMethod(d); 84 | scope->Set(key.c_str(), v); 85 | } 86 | else 87 | { 88 | scope->Set(key.c_str(), value); 89 | } 90 | 91 | } 92 | return scope; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /libkroll/utils/linux/boot_utils_linux.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | #include "../utils.h" 7 | 8 | namespace UTILS_NS 9 | { 10 | namespace BootUtils 11 | { 12 | vector& GetComponentSearchPaths() 13 | { 14 | static std::vector componentSearchPaths; 15 | if (componentSearchPaths.empty()) 16 | { 17 | // Allow the user to force an override to the runtime home by setting the 18 | // appropriate environment variable -- this will be the first path searched 19 | if (EnvironmentUtils::Has("KR_SEARCH_PATH")) 20 | componentSearchPaths.push_back(EnvironmentUtils::Get("KR_SEARCH_PATH")); 21 | 22 | // Kroll runtime and modules will located by searching the following paths in order: 23 | // 1. ~/.PRODUCT_NAME (eg. ~/.titanium) 24 | // 2. /opt/PRODUCT_NAME (default runtime base path for system-wide installation) 25 | // 3. /usr/local/lib/PRODUCT_NAME 26 | // 4. /usr/lib/PRODUCT_NAME 27 | string pname = PRODUCT_NAME; 28 | std::transform(pname.begin(), pname.end(), pname.begin(), tolower); 29 | componentSearchPaths.push_back(FileUtils::GetUserRuntimeHomeDirectory()); 30 | componentSearchPaths.push_back(string("/opt/") + pname); 31 | componentSearchPaths.push_back(string("/usr/local/lib/") + pname); 32 | componentSearchPaths.push_back(string("/usr/lib/") + pname); 33 | } 34 | return componentSearchPaths; 35 | } 36 | 37 | bool RunInstaller( 38 | vector missing, 39 | SharedApplication application, 40 | std::string updateFile, 41 | std::string installerPath, 42 | bool quiet, 43 | bool forceInstall) 44 | { 45 | if (installerPath.empty()) 46 | { 47 | installerPath = application->path; 48 | } 49 | 50 | string exec = FileUtils::Join( 51 | installerPath.c_str(), "installer", "installer", NULL); 52 | 53 | if (!FileUtils::IsFile(exec)) 54 | { 55 | return false; 56 | } 57 | 58 | vector args; 59 | args.push_back("--apppath"); 60 | args.push_back(application->path); 61 | 62 | if (!updateFile.empty()) 63 | { 64 | args.push_back("--updatefile"); 65 | args.push_back(updateFile); 66 | } 67 | // The Linux installer has no quiet mode 68 | 69 | std::vector::iterator di = missing.begin(); 70 | while (di != missing.end()) 71 | { 72 | SharedDependency d = *di++; 73 | string url = application->GetURLForDependency(d); 74 | args.push_back(url); 75 | } 76 | 77 | FileUtils::RunAndWait(exec, args); 78 | return true; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /modules/php/php_interpreter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2009 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | 7 | #include "php_module.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | namespace kroll { 16 | 17 | PHPInterpreter::PHPInterpreter() 18 | { 19 | } 20 | 21 | static string GetContextId(KObjectRef global) 22 | { 23 | string contextId(global->GetString("__php_module_id__")); 24 | if (contextId.empty()) 25 | { 26 | static int nextId = 0; 27 | contextId.append("__kroll__namespace__"); 28 | contextId.append(KList::IntToChars(++nextId)); 29 | global->SetString("__php_module_id__", contextId); 30 | } 31 | 32 | return contextId; 33 | } 34 | 35 | KValueRef PHPInterpreter::EvaluateFile(const char* filepath, KObjectRef context) 36 | { 37 | static Poco::Mutex evaluatorMutex; 38 | Poco::Mutex::ScopedLock evaluatorLock(evaluatorMutex); 39 | 40 | TSRMLS_FETCH(); 41 | 42 | // Read in source code 43 | std::string code(FileUtils::ReadFile(filepath)); 44 | 45 | // Contexts must be the same for runs with the same global object. 46 | string contextId(GetContextId(context)); 47 | PHPUtils::GenerateCaseMap(code TSRMLS_CC); 48 | 49 | std::ostringstream codeString; 50 | codeString << "namespace " << contextId << " {\n"; 51 | codeString << code << "\n"; 52 | codeString << " $__fns = get_defined_functions();\n"; 53 | codeString << " if (array_key_exists(\"user\", $__fns)) {\n"; 54 | codeString << " foreach($__fns[\"user\"] as $fname) {\n"; 55 | codeString << " if (!$window->$fname) {"; 56 | codeString << " krollAddFunction($window, $fname);\n"; 57 | codeString << " }\n"; 58 | codeString << " }\n"; 59 | codeString << " }\n"; 60 | codeString << "}\n"; 61 | printf("%s\n", codeString.str().c_str()); 62 | 63 | // This seems to be needed to make PHP actually give us errors 64 | // at parse/compile time -- see: main/main.c line 969 65 | PG(during_request_startup) = 0; 66 | 67 | KObjectRef previousGlobal(PHPUtils::GetCurrentGlobalObject()); 68 | PHPUtils::SwapGlobalObject(context, &EG(symbol_table) TSRMLS_CC); 69 | 70 | zend_first_try 71 | { 72 | zend_eval_string((char *) codeString.str().c_str(), NULL, 73 | (char *) filepath TSRMLS_CC); 74 | } 75 | zend_catch 76 | { 77 | Logger::Get("PHP")->Error("Evaluation of script failed"); 78 | } 79 | zend_end_try(); 80 | 81 | PHPUtils::SwapGlobalObject(previousGlobal, &EG(symbol_table) TSRMLS_CC); 82 | 83 | return Value::Null; 84 | } 85 | 86 | } // namespace kroll 87 | -------------------------------------------------------------------------------- /libkroll/kroll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Appcelerator Kroll - licensed under the Apache Public License 2 3 | * see LICENSE in the root folder for details on the license. 4 | * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved. 5 | */ 6 | /** 7 | * This file is the easiest way to gain access to the full Kroll API 8 | * To use it, just do the following: 9 | * \code 10 | * #include 11 | * \endcode 12 | */ 13 | 14 | #ifndef _KROLL_H_ 15 | #define _KROLL_H_ 16 | 17 | #include "base.h" 18 | #include 19 | #include 20 | #include 21 | 22 | using Poco::SharedPtr; 23 | using Poco::AutoPtr; 24 | 25 | #ifndef OS_WIN32 26 | // this is important which essentially marks all of 27 | // these classes below and the typedef/templates to be 28 | // visible outside of the library. if you don't do this 29 | // you won't be able to catch exceptions of KValueRef for 30 | // example 31 | #pragma GCC visibility push(default) 32 | #endif 33 | 34 | namespace kroll 35 | { 36 | class Value; 37 | class KObject; 38 | class KMethod; 39 | class KList; 40 | 41 | class StaticBoundObject; 42 | class StaticBoundMethod; 43 | class StaticBoundList; 44 | 45 | class GlobalObject; 46 | class ScopeMethodDelegate; 47 | class Bytes; 48 | class VoidPtr; 49 | class ValueReleasePolicy; 50 | class Logger; 51 | class ArgList; 52 | 53 | typedef AutoPtr KValueRef; 54 | typedef AutoPtr KObjectRef; 55 | typedef AutoPtr KMethodRef; 56 | typedef AutoPtr KListRef; 57 | typedef AutoPtr BytesRef; 58 | 59 | typedef SharedPtr SharedString; 60 | typedef std::vector StringList; 61 | typedef SharedPtr SharedStringList; 62 | 63 | typedef ArgList ValueList; 64 | 65 | class Module; 66 | class Application; 67 | class KComponent; 68 | class Dependency; 69 | 70 | typedef SharedPtr SharedComponent; 71 | typedef SharedPtr SharedApplication; 72 | typedef SharedPtr SharedDependency; 73 | } 74 | 75 | #ifndef OS_WIN32 76 | #pragma GCC visibility pop 77 | #endif 78 | 79 | #include "utils/utils.h" 80 | #include "net/net.h" 81 | #include "reference_counted.h" 82 | #include "logger.h" 83 | 84 | #include "binding/binding.h" 85 | #include "module_provider.h" 86 | #include "module.h" 87 | #include "async_job.h" 88 | #include "main_thread_job.h" 89 | #include "ScriptController.h" 90 | 91 | #ifdef OS_OSX 92 | #include "osx/osx.h" 93 | #elif defined(OS_WIN32) 94 | #include "win32/win32.h" 95 | #endif 96 | 97 | #include "host.h" 98 | 99 | #endif 100 | --------------------------------------------------------------------------------