初始化
@@ -0,0 +1,76 @@
|
||||
# Ignore thumbnails created by windows
|
||||
Thumbs.db
|
||||
|
||||
# Ignore files build by Visual Studio
|
||||
*.obj
|
||||
*.exe
|
||||
*.pdb
|
||||
*.aps
|
||||
*.vcproj.*.user
|
||||
*.vcxproj.user
|
||||
*.vspscc
|
||||
*_i.c
|
||||
*.i
|
||||
*.icf
|
||||
*_p.c
|
||||
*.ncb
|
||||
*.suo
|
||||
*.tlb
|
||||
*.tlh
|
||||
*.bak
|
||||
*.cache
|
||||
*.ilk
|
||||
*.log
|
||||
[Bb]in
|
||||
[Dd]ebug/
|
||||
[Dd]ebug.win32/
|
||||
*.sbr
|
||||
*.sdf
|
||||
obj/
|
||||
[Rr]elease/
|
||||
[Rr]elease.win32/
|
||||
_ReSharper*/
|
||||
[Tt]est[Rr]esult*
|
||||
ipch/
|
||||
*.opensdf
|
||||
Generated Files
|
||||
AppPackages
|
||||
|
||||
# Ignore files build by ndk and eclipse
|
||||
libs/
|
||||
bin/
|
||||
obj/
|
||||
gen/
|
||||
assets/
|
||||
local.properties
|
||||
|
||||
# Ignore files build by airplay and marmalade
|
||||
build_*_xcode/
|
||||
build_*_vc10/
|
||||
|
||||
# Ignore files build by Xcode
|
||||
*.mode*v*
|
||||
*.pbxuser
|
||||
*.xcbkptlist
|
||||
*.xcworkspacedata
|
||||
*.xcuserstate
|
||||
*.xccheckout
|
||||
xcschememanagement.plist
|
||||
.DS_Store
|
||||
._.*
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
proj.ios_mac/build/
|
||||
|
||||
# Ignore vim swaps
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Cmake files
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
CMakeLists.txt.user
|
||||
|
||||
*.jsc
|
||||
@@ -0,0 +1,343 @@
|
||||
/**
|
||||
* @module audioengine
|
||||
*/
|
||||
var jsb = jsb || {};
|
||||
|
||||
/**
|
||||
* @class AudioProfile
|
||||
*/
|
||||
jsb.AudioProfile = {
|
||||
|
||||
/**
|
||||
* @method AudioProfile
|
||||
* @constructor
|
||||
*/
|
||||
AudioProfile : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class AudioEngine
|
||||
*/
|
||||
jsb.AudioEngine = {
|
||||
|
||||
/**
|
||||
* @method lazyInit
|
||||
* @return {bool}
|
||||
*/
|
||||
lazyInit : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setCurrentTime
|
||||
* @param {int} arg0
|
||||
* @param {float} arg1
|
||||
* @return {bool}
|
||||
*/
|
||||
setCurrentTime : function (
|
||||
int,
|
||||
float
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getVolume
|
||||
* @param {int} arg0
|
||||
* @return {float}
|
||||
*/
|
||||
getVolume : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method uncache
|
||||
* @param {String} arg0
|
||||
*/
|
||||
uncache : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method resumeAll
|
||||
*/
|
||||
resumeAll : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method stopAll
|
||||
*/
|
||||
stopAll : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method pause
|
||||
* @param {int} arg0
|
||||
*/
|
||||
pause : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method end
|
||||
*/
|
||||
end : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getMaxAudioInstance
|
||||
* @return {int}
|
||||
*/
|
||||
getMaxAudioInstance : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isEnabled
|
||||
* @return {bool}
|
||||
*/
|
||||
isEnabled : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDurationFromFile
|
||||
* @param {String} arg0
|
||||
* @return {float}
|
||||
*/
|
||||
getDurationFromFile : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getCurrentTime
|
||||
* @param {int} arg0
|
||||
* @return {float}
|
||||
*/
|
||||
getCurrentTime : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setMaxAudioInstance
|
||||
* @param {int} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
setMaxAudioInstance : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isLoop
|
||||
* @param {int} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
isLoop : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method pauseAll
|
||||
*/
|
||||
pauseAll : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method uncacheAll
|
||||
*/
|
||||
uncacheAll : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setVolume
|
||||
* @param {int} arg0
|
||||
* @param {float} arg1
|
||||
*/
|
||||
setVolume : function (
|
||||
int,
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method preload
|
||||
* @param {String|String} str
|
||||
* @param {function} func
|
||||
*/
|
||||
preload : function(
|
||||
str,
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setEnabled
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setEnabled : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method play2d
|
||||
* @param {String} arg0
|
||||
* @param {bool} arg1
|
||||
* @param {float} arg2
|
||||
* @param {cc.AudioProfile} arg3
|
||||
* @return {int}
|
||||
*/
|
||||
play2d : function (
|
||||
str,
|
||||
bool,
|
||||
float,
|
||||
audioprofile
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getState
|
||||
* @param {int} arg0
|
||||
* @return {cc.AudioEngine::AudioState}
|
||||
*/
|
||||
getState : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method resume
|
||||
* @param {int} arg0
|
||||
*/
|
||||
resume : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method stop
|
||||
* @param {int} arg0
|
||||
*/
|
||||
stop : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDuration
|
||||
* @param {int} arg0
|
||||
* @return {float}
|
||||
*/
|
||||
getDuration : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setLoop
|
||||
* @param {int} arg0
|
||||
* @param {bool} arg1
|
||||
*/
|
||||
setLoop : function (
|
||||
int,
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDefaultProfile
|
||||
* @return {cc.AudioProfile}
|
||||
*/
|
||||
getDefaultProfile : function (
|
||||
)
|
||||
{
|
||||
return cc.AudioProfile;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setFinishCallback
|
||||
* @param {int} arg0
|
||||
* @param {function} arg1
|
||||
*/
|
||||
setFinishCallback : function (
|
||||
int,
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getProfile
|
||||
* @param {String|int} str
|
||||
* @return {cc.AudioProfile|cc.AudioProfile}
|
||||
*/
|
||||
getProfile : function(
|
||||
int
|
||||
)
|
||||
{
|
||||
return cc.AudioProfile;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getPlayingAudioCount
|
||||
* @return {int}
|
||||
*/
|
||||
getPlayingAudioCount : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* @module cocos2dx_editor_support
|
||||
*/
|
||||
var middleware = middleware || {};
|
||||
|
||||
/**
|
||||
* @class Texture2D
|
||||
*/
|
||||
middleware.Texture2D = {
|
||||
|
||||
/**
|
||||
* @method getRealTextureIndex
|
||||
* @return {int}
|
||||
*/
|
||||
getRealTextureIndex : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setTexParamCallback
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setTexParamCallback : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setPixelsHigh
|
||||
* @param {int} arg0
|
||||
*/
|
||||
setPixelsHigh : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getNativeTexture
|
||||
* @return {cc.renderer::Texture}
|
||||
*/
|
||||
getNativeTexture : function (
|
||||
)
|
||||
{
|
||||
return cc.renderer::Texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setPixelsWide
|
||||
* @param {int} arg0
|
||||
*/
|
||||
setPixelsWide : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getPixelsHigh
|
||||
* @return {int}
|
||||
*/
|
||||
getPixelsHigh : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getPixelsWide
|
||||
* @return {int}
|
||||
*/
|
||||
getPixelsWide : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setRealTextureIndex
|
||||
* @param {int} arg0
|
||||
*/
|
||||
setRealTextureIndex : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setNativeTexture
|
||||
* @param {cc.renderer::Texture} arg0
|
||||
*/
|
||||
setNativeTexture : function (
|
||||
texture
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setTexParameters
|
||||
* @param {cc.middleware::Texture2D::_TexParams} arg0
|
||||
*/
|
||||
setTexParameters : function (
|
||||
_texparams
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Texture2D
|
||||
* @constructor
|
||||
*/
|
||||
Texture2D : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class MiddlewareManager
|
||||
*/
|
||||
middleware.MiddlewareManager = {
|
||||
|
||||
/**
|
||||
* @method render
|
||||
* @param {float} arg0
|
||||
*/
|
||||
render : function (
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method update
|
||||
* @param {float} arg0
|
||||
*/
|
||||
update : function (
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method destroyInstance
|
||||
*/
|
||||
destroyInstance : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method generateModuleID
|
||||
* @return {unsigned char}
|
||||
*/
|
||||
generateModuleID : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getInstance
|
||||
* @return {cc.middleware::MiddlewareManager}
|
||||
*/
|
||||
getInstance : function (
|
||||
)
|
||||
{
|
||||
return cc.middleware::MiddlewareManager;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method MiddlewareManager
|
||||
* @constructor
|
||||
*/
|
||||
MiddlewareManager : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,548 @@
|
||||
/**
|
||||
* @module extension
|
||||
*/
|
||||
var jsb = jsb || {};
|
||||
|
||||
/**
|
||||
* @class EventAssetsManagerEx
|
||||
*/
|
||||
jsb.EventAssetsManager = {
|
||||
|
||||
/**
|
||||
* @method getAssetsManagerEx
|
||||
* @return {cc.AssetsManagerEx}
|
||||
*/
|
||||
getAssetsManagerEx : function (
|
||||
)
|
||||
{
|
||||
return cc.AssetsManagerEx;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDownloadedFiles
|
||||
* @return {int}
|
||||
*/
|
||||
getDownloadedFiles : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getTotalFiles
|
||||
* @return {int}
|
||||
*/
|
||||
getTotalFiles : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getAssetId
|
||||
* @return {String}
|
||||
*/
|
||||
getAssetId : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getTotalBytes
|
||||
* @return {double}
|
||||
*/
|
||||
getTotalBytes : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getCURLECode
|
||||
* @return {int}
|
||||
*/
|
||||
getCURLECode : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getMessage
|
||||
* @return {String}
|
||||
*/
|
||||
getMessage : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getCURLMCode
|
||||
* @return {int}
|
||||
*/
|
||||
getCURLMCode : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDownloadedBytes
|
||||
* @return {double}
|
||||
*/
|
||||
getDownloadedBytes : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getPercentByFile
|
||||
* @return {float}
|
||||
*/
|
||||
getPercentByFile : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getEventCode
|
||||
* @return {cc.EventAssetsManagerEx::EventCode}
|
||||
*/
|
||||
getEventCode : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getPercent
|
||||
* @return {float}
|
||||
*/
|
||||
getPercent : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isResuming
|
||||
* @return {bool}
|
||||
*/
|
||||
isResuming : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method EventAssetsManagerEx
|
||||
* @constructor
|
||||
* @param {String} arg0
|
||||
* @param {cc.AssetsManagerEx} arg1
|
||||
* @param {cc.EventAssetsManagerEx::EventCode} arg2
|
||||
* @param {String} arg3
|
||||
* @param {String} arg4
|
||||
* @param {int} arg5
|
||||
* @param {int} arg6
|
||||
*/
|
||||
EventAssetsManagerEx : function (
|
||||
str,
|
||||
assetsmanagerex,
|
||||
eventcode,
|
||||
str,
|
||||
str,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Manifest
|
||||
*/
|
||||
jsb.Manifest = {
|
||||
|
||||
/**
|
||||
* @method getManifestRoot
|
||||
* @return {String}
|
||||
*/
|
||||
getManifestRoot : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setUpdating
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setUpdating : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getManifestFileUrl
|
||||
* @return {String}
|
||||
*/
|
||||
getManifestFileUrl : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isVersionLoaded
|
||||
* @return {bool}
|
||||
*/
|
||||
isVersionLoaded : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method parseFile
|
||||
* @param {String} arg0
|
||||
*/
|
||||
parseFile : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isLoaded
|
||||
* @return {bool}
|
||||
*/
|
||||
isLoaded : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getPackageUrl
|
||||
* @return {String}
|
||||
*/
|
||||
getPackageUrl : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isUpdating
|
||||
* @return {bool}
|
||||
*/
|
||||
isUpdating : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getVersion
|
||||
* @return {String}
|
||||
*/
|
||||
getVersion : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method parseJSONString
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
*/
|
||||
parseJSONString : function (
|
||||
str,
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getVersionFileUrl
|
||||
* @return {String}
|
||||
*/
|
||||
getVersionFileUrl : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getSearchPaths
|
||||
* @return {Array}
|
||||
*/
|
||||
getSearchPaths : function (
|
||||
)
|
||||
{
|
||||
return new Array();
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Manifest
|
||||
* @constructor
|
||||
* @param {String|String} str
|
||||
* @param {String} str
|
||||
*/
|
||||
Manifest : function(
|
||||
str,
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class AssetsManagerEx
|
||||
*/
|
||||
jsb.AssetsManager = {
|
||||
|
||||
/**
|
||||
* @method getDownloadedFiles
|
||||
* @return {int}
|
||||
*/
|
||||
getDownloadedFiles : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setEventCallback
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setEventCallback : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method downloadFailedAssets
|
||||
*/
|
||||
downloadFailedAssets : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getTotalFiles
|
||||
* @return {int}
|
||||
*/
|
||||
getTotalFiles : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method checkUpdate
|
||||
*/
|
||||
checkUpdate : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadLocalManifest
|
||||
* @param {String|cc.Manifest} str
|
||||
* @param {String} str
|
||||
* @return {bool|bool}
|
||||
*/
|
||||
loadLocalManifest : function(
|
||||
manifest,
|
||||
str
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setMaxConcurrentTask
|
||||
* @param {int} arg0
|
||||
*/
|
||||
setMaxConcurrentTask : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getLocalManifest
|
||||
* @return {cc.Manifest}
|
||||
*/
|
||||
getLocalManifest : function (
|
||||
)
|
||||
{
|
||||
return cc.Manifest;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getRemoteManifest
|
||||
* @return {cc.Manifest}
|
||||
*/
|
||||
getRemoteManifest : function (
|
||||
)
|
||||
{
|
||||
return cc.Manifest;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method cancelUpdate
|
||||
*/
|
||||
cancelUpdate : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isResuming
|
||||
* @return {bool}
|
||||
*/
|
||||
isResuming : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getState
|
||||
* @return {cc.AssetsManagerEx::State}
|
||||
*/
|
||||
getState : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getMaxConcurrentTask
|
||||
* @return {int}
|
||||
*/
|
||||
getMaxConcurrentTask : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setVersionCompareHandle
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setVersionCompareHandle : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getTotalBytes
|
||||
* @return {double}
|
||||
*/
|
||||
getTotalBytes : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setVerifyCallback
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setVerifyCallback : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getStoragePath
|
||||
* @return {String}
|
||||
*/
|
||||
getStoragePath : function (
|
||||
)
|
||||
{
|
||||
return ;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method update
|
||||
*/
|
||||
update : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDownloadedBytes
|
||||
* @return {double}
|
||||
*/
|
||||
getDownloadedBytes : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method prepareUpdate
|
||||
*/
|
||||
prepareUpdate : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadRemoteManifest
|
||||
* @param {cc.Manifest} arg0
|
||||
* @return {bool}
|
||||
*/
|
||||
loadRemoteManifest : function (
|
||||
manifest
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method create
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
* @return {cc.AssetsManagerEx}
|
||||
*/
|
||||
create : function (
|
||||
str,
|
||||
str
|
||||
)
|
||||
{
|
||||
return cc.AssetsManagerEx;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method AssetsManagerEx
|
||||
* @constructor
|
||||
* @param {String|String} str
|
||||
* @param {String|String} str
|
||||
* @param {function} func
|
||||
*/
|
||||
AssetsManagerEx : function(
|
||||
str,
|
||||
str,
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @module network
|
||||
*/
|
||||
var jsb = jsb || {};
|
||||
|
||||
/**
|
||||
* @class Downloader
|
||||
*/
|
||||
jsb.Downloader = {
|
||||
|
||||
/**
|
||||
* @method setOnTaskProgress
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setOnTaskProgress : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Downloader
|
||||
* @constructor
|
||||
* @param {cc.network::DownloaderHints} downloaderhints
|
||||
*/
|
||||
Downloader : function(
|
||||
downloaderhints
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,258 @@
|
||||
/**
|
||||
* @module cocos2dx_particle
|
||||
*/
|
||||
var middleware = middleware || {};
|
||||
|
||||
/**
|
||||
* @class ParticleSimulator
|
||||
*/
|
||||
middleware.ParticleSimulator = {
|
||||
|
||||
/**
|
||||
* @method setGravity
|
||||
* @param {float} arg0
|
||||
* @param {float} arg1
|
||||
* @param {float} arg2
|
||||
*/
|
||||
setGravity : function (
|
||||
float,
|
||||
float,
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method render
|
||||
* @param {float} arg0
|
||||
*/
|
||||
render : function (
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setSourcePos
|
||||
* @param {float} arg0
|
||||
* @param {float} arg1
|
||||
* @param {float} arg2
|
||||
*/
|
||||
setSourcePos : function (
|
||||
float,
|
||||
float,
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method onEnable
|
||||
*/
|
||||
onEnable : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setEffect
|
||||
* @param {cc.renderer::EffectVariant} arg0
|
||||
*/
|
||||
setEffect : function (
|
||||
effectvariant
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setPosVar
|
||||
* @param {float} arg0
|
||||
* @param {float} arg1
|
||||
* @param {float} arg2
|
||||
*/
|
||||
setPosVar : function (
|
||||
float,
|
||||
float,
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setEndColorVar
|
||||
* @param {unsigned char} arg0
|
||||
* @param {unsigned char} arg1
|
||||
* @param {unsigned char} arg2
|
||||
* @param {unsigned char} arg3
|
||||
*/
|
||||
setEndColorVar : function (
|
||||
char,
|
||||
char,
|
||||
char,
|
||||
char
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getParticleCount
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getParticleCount : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStartColorVar
|
||||
* @param {unsigned char} arg0
|
||||
* @param {unsigned char} arg1
|
||||
* @param {unsigned char} arg2
|
||||
* @param {unsigned char} arg3
|
||||
*/
|
||||
setStartColorVar : function (
|
||||
char,
|
||||
char,
|
||||
char,
|
||||
char
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method emitParticle
|
||||
* @param {vec3_object} arg0
|
||||
*/
|
||||
emitParticle : function (
|
||||
vec3
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method stop
|
||||
*/
|
||||
stop : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method update
|
||||
* @param {float} arg0
|
||||
*/
|
||||
update : function (
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method active
|
||||
* @return {bool}
|
||||
*/
|
||||
active : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method updateUVs
|
||||
* @param {Array} arg0
|
||||
*/
|
||||
updateUVs : function (
|
||||
array
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStartColor
|
||||
* @param {unsigned char} arg0
|
||||
* @param {unsigned char} arg1
|
||||
* @param {unsigned char} arg2
|
||||
* @param {unsigned char} arg3
|
||||
*/
|
||||
setStartColor : function (
|
||||
char,
|
||||
char,
|
||||
char,
|
||||
char
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method reset
|
||||
*/
|
||||
reset : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method onDisable
|
||||
*/
|
||||
onDisable : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method bindNodeProxy
|
||||
* @param {cc.renderer::NodeProxy} arg0
|
||||
*/
|
||||
bindNodeProxy : function (
|
||||
nodeproxy
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setEndColor
|
||||
* @param {unsigned char} arg0
|
||||
* @param {unsigned char} arg1
|
||||
* @param {unsigned char} arg2
|
||||
* @param {unsigned char} arg3
|
||||
*/
|
||||
setEndColor : function (
|
||||
char,
|
||||
char,
|
||||
char,
|
||||
char
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setFinishedCallback
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setFinishedCallback : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStopCallback
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setStopCallback : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method ParticleSimulator
|
||||
* @constructor
|
||||
*/
|
||||
ParticleSimulator : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,841 @@
|
||||
/**
|
||||
* @module gfx
|
||||
*/
|
||||
var gfx = gfx || {};
|
||||
|
||||
/**
|
||||
* @class GraphicsHandle
|
||||
*/
|
||||
gfx.GraphicsHandle = {
|
||||
|
||||
/**
|
||||
* @method getHandle
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getHandle : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method GraphicsHandle
|
||||
* @constructor
|
||||
*/
|
||||
GraphicsHandle : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class IndexBuffer
|
||||
*/
|
||||
gfx.IndexBuffer = {
|
||||
|
||||
/**
|
||||
* @method getUsage
|
||||
* @return {cc.renderer::Usage}
|
||||
*/
|
||||
getUsage : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setFormat
|
||||
* @param {cc.renderer::IndexFormat} arg0
|
||||
*/
|
||||
setFormat : function (
|
||||
indexformat
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setCount
|
||||
* @param {unsigned int} arg0
|
||||
*/
|
||||
setCount : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method destroy
|
||||
*/
|
||||
destroy : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setUsage
|
||||
* @param {cc.renderer::Usage} arg0
|
||||
*/
|
||||
setUsage : function (
|
||||
usage
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getCount
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getCount : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBytesPerIndex
|
||||
* @param {unsigned int} arg0
|
||||
*/
|
||||
setBytesPerIndex : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getBytes
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getBytes : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method IndexBuffer
|
||||
* @constructor
|
||||
*/
|
||||
IndexBuffer : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class VertexBuffer
|
||||
*/
|
||||
gfx.VertexBuffer = {
|
||||
|
||||
/**
|
||||
* @method getUsage
|
||||
* @return {cc.renderer::Usage}
|
||||
*/
|
||||
getUsage : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setCount
|
||||
* @param {unsigned int} arg0
|
||||
*/
|
||||
setCount : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method destroy
|
||||
*/
|
||||
destroy : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setUsage
|
||||
* @param {cc.renderer::Usage} arg0
|
||||
*/
|
||||
setUsage : function (
|
||||
usage
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getCount
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getCount : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getBytes
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getBytes : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method VertexBuffer
|
||||
* @constructor
|
||||
*/
|
||||
VertexBuffer : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class DeviceGraphics
|
||||
*/
|
||||
gfx.Device = {
|
||||
|
||||
/**
|
||||
* @method setBlendFuncSeparate
|
||||
* @param {cc.renderer::BlendFactor} arg0
|
||||
* @param {cc.renderer::BlendFactor} arg1
|
||||
* @param {cc.renderer::BlendFactor} arg2
|
||||
* @param {cc.renderer::BlendFactor} arg3
|
||||
*/
|
||||
setBlendFuncSeparate : function (
|
||||
blendfactor,
|
||||
blendfactor,
|
||||
blendfactor,
|
||||
blendfactor
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method enableBlend
|
||||
*/
|
||||
enableBlend : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setPrimitiveType
|
||||
* @param {cc.renderer::PrimitiveType} arg0
|
||||
*/
|
||||
setPrimitiveType : function (
|
||||
primitivetype
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBlendEquationSeparate
|
||||
* @param {cc.renderer::BlendOp} arg0
|
||||
* @param {cc.renderer::BlendOp} arg1
|
||||
*/
|
||||
setBlendEquationSeparate : function (
|
||||
blendop,
|
||||
blendop
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setIndexBuffer
|
||||
* @param {cc.renderer::IndexBuffer} arg0
|
||||
*/
|
||||
setIndexBuffer : function (
|
||||
indexbuffer
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setProgram
|
||||
* @param {cc.renderer::Program} arg0
|
||||
*/
|
||||
setProgram : function (
|
||||
program
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setFrameBuffer
|
||||
* @param {cc.renderer::FrameBuffer} arg0
|
||||
*/
|
||||
setFrameBuffer : function (
|
||||
framebuffer
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStencilFunc
|
||||
* @param {cc.renderer::ComparisonFunc} arg0
|
||||
* @param {int} arg1
|
||||
* @param {unsigned int} arg2
|
||||
*/
|
||||
setStencilFunc : function (
|
||||
comparisonfunc,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBlendColor
|
||||
* @param {unsigned char|unsigned int} char
|
||||
* @param {unsigned char} char
|
||||
* @param {unsigned char} char
|
||||
* @param {unsigned char} char
|
||||
*/
|
||||
setBlendColor : function(
|
||||
char,
|
||||
char,
|
||||
char,
|
||||
char
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setScissor
|
||||
* @param {int} arg0
|
||||
* @param {int} arg1
|
||||
* @param {int} arg2
|
||||
* @param {int} arg3
|
||||
*/
|
||||
setScissor : function (
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setVertexBuffer
|
||||
* @param {int} arg0
|
||||
* @param {cc.renderer::VertexBuffer} arg1
|
||||
* @param {int} arg2
|
||||
*/
|
||||
setVertexBuffer : function (
|
||||
int,
|
||||
vertexbuffer,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method enableDepthWrite
|
||||
*/
|
||||
enableDepthWrite : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getCapacity
|
||||
* @return {cc.renderer::DeviceGraphics::Capacity}
|
||||
*/
|
||||
getCapacity : function (
|
||||
)
|
||||
{
|
||||
return cc.renderer::DeviceGraphics::Capacity;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStencilOpBack
|
||||
* @param {cc.renderer::StencilOp} arg0
|
||||
* @param {cc.renderer::StencilOp} arg1
|
||||
* @param {cc.renderer::StencilOp} arg2
|
||||
* @param {unsigned int} arg3
|
||||
*/
|
||||
setStencilOpBack : function (
|
||||
stencilop,
|
||||
stencilop,
|
||||
stencilop,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setViewport
|
||||
* @param {int} arg0
|
||||
* @param {int} arg1
|
||||
* @param {int} arg2
|
||||
* @param {int} arg3
|
||||
*/
|
||||
setViewport : function (
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method draw
|
||||
* @param {unsigned int} arg0
|
||||
* @param {int} arg1
|
||||
*/
|
||||
draw : function (
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setDepthFunc
|
||||
* @param {cc.renderer::ComparisonFunc} arg0
|
||||
*/
|
||||
setDepthFunc : function (
|
||||
comparisonfunc
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method enableDepthTest
|
||||
*/
|
||||
enableDepthTest : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method resetDrawCalls
|
||||
*/
|
||||
resetDrawCalls : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getDrawCalls
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getDrawCalls : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBlendEquation
|
||||
* @param {cc.renderer::BlendOp} arg0
|
||||
*/
|
||||
setBlendEquation : function (
|
||||
blendop
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStencilFuncFront
|
||||
* @param {cc.renderer::ComparisonFunc} arg0
|
||||
* @param {int} arg1
|
||||
* @param {unsigned int} arg2
|
||||
*/
|
||||
setStencilFuncFront : function (
|
||||
comparisonfunc,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStencilOpFront
|
||||
* @param {cc.renderer::StencilOp} arg0
|
||||
* @param {cc.renderer::StencilOp} arg1
|
||||
* @param {cc.renderer::StencilOp} arg2
|
||||
* @param {unsigned int} arg3
|
||||
*/
|
||||
setStencilOpFront : function (
|
||||
stencilop,
|
||||
stencilop,
|
||||
stencilop,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStencilFuncBack
|
||||
* @param {cc.renderer::ComparisonFunc} arg0
|
||||
* @param {int} arg1
|
||||
* @param {unsigned int} arg2
|
||||
*/
|
||||
setStencilFuncBack : function (
|
||||
comparisonfunc,
|
||||
int,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBlendFunc
|
||||
* @param {cc.renderer::BlendFactor} arg0
|
||||
* @param {cc.renderer::BlendFactor} arg1
|
||||
*/
|
||||
setBlendFunc : function (
|
||||
blendfactor,
|
||||
blendfactor
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setCullMode
|
||||
* @param {cc.renderer::CullMode} arg0
|
||||
*/
|
||||
setCullMode : function (
|
||||
cullmode
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setStencilOp
|
||||
* @param {cc.renderer::StencilOp} arg0
|
||||
* @param {cc.renderer::StencilOp} arg1
|
||||
* @param {cc.renderer::StencilOp} arg2
|
||||
* @param {unsigned int} arg3
|
||||
*/
|
||||
setStencilOp : function (
|
||||
stencilop,
|
||||
stencilop,
|
||||
stencilop,
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method enableStencilTest
|
||||
*/
|
||||
enableStencilTest : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method destroy
|
||||
*/
|
||||
destroy : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getInstance
|
||||
* @return {cc.renderer::DeviceGraphics}
|
||||
*/
|
||||
getInstance : function (
|
||||
)
|
||||
{
|
||||
return cc.renderer::DeviceGraphics;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class FrameBuffer
|
||||
*/
|
||||
gfx.FrameBuffer = {
|
||||
|
||||
/**
|
||||
* @method getHeight
|
||||
* @return {int}
|
||||
*/
|
||||
getHeight : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getWidth
|
||||
* @return {int}
|
||||
*/
|
||||
getWidth : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method destroy
|
||||
*/
|
||||
destroy : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method FrameBuffer
|
||||
* @constructor
|
||||
*/
|
||||
FrameBuffer : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class RenderTarget
|
||||
*/
|
||||
gfx.RenderTarget = {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class RenderBuffer
|
||||
*/
|
||||
gfx.RenderBuffer = {
|
||||
|
||||
/**
|
||||
* @method init
|
||||
* @param {cc.renderer::DeviceGraphics} arg0
|
||||
* @param {cc.renderer::RenderBuffer::Format} arg1
|
||||
* @param {unsigned short} arg2
|
||||
* @param {unsigned short} arg3
|
||||
* @return {bool}
|
||||
*/
|
||||
init : function (
|
||||
devicegraphics,
|
||||
format,
|
||||
short,
|
||||
short
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method update
|
||||
* @param {unsigned short} arg0
|
||||
* @param {unsigned short} arg1
|
||||
* @return {bool}
|
||||
*/
|
||||
update : function (
|
||||
short,
|
||||
short
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method create
|
||||
* @param {cc.renderer::DeviceGraphics} arg0
|
||||
* @param {cc.renderer::RenderBuffer::Format} arg1
|
||||
* @param {unsigned short} arg2
|
||||
* @param {unsigned short} arg3
|
||||
* @return {cc.renderer::RenderBuffer}
|
||||
*/
|
||||
create : function (
|
||||
devicegraphics,
|
||||
format,
|
||||
short,
|
||||
short
|
||||
)
|
||||
{
|
||||
return cc.renderer::RenderBuffer;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method RenderBuffer
|
||||
* @constructor
|
||||
*/
|
||||
RenderBuffer : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Texture
|
||||
*/
|
||||
gfx.Texture = {
|
||||
|
||||
/**
|
||||
* @method getWidth
|
||||
* @return {unsigned short}
|
||||
*/
|
||||
getWidth : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setAlphaAtlas
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setAlphaAtlas : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getHeight
|
||||
* @return {unsigned short}
|
||||
*/
|
||||
getHeight : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isAlphaAtlas
|
||||
* @return {bool}
|
||||
*/
|
||||
isAlphaAtlas : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getTarget
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getTarget : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Texture2D
|
||||
*/
|
||||
gfx.Texture2D = {
|
||||
|
||||
/**
|
||||
* @method updateImage
|
||||
* @param {cc.renderer::Texture::ImageOption} arg0
|
||||
*/
|
||||
updateImage : function (
|
||||
imageoption
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method init
|
||||
* @param {cc.renderer::DeviceGraphics} arg0
|
||||
* @param {cc.renderer::Texture::Options} arg1
|
||||
* @return {bool}
|
||||
*/
|
||||
init : function (
|
||||
devicegraphics,
|
||||
options
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method updateSubImage
|
||||
* @param {cc.renderer::Texture::SubImageOption} arg0
|
||||
*/
|
||||
updateSubImage : function (
|
||||
subimageoption
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method update
|
||||
* @param {cc.renderer::Texture::Options} arg0
|
||||
*/
|
||||
update : function (
|
||||
options
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Texture2D
|
||||
* @constructor
|
||||
*/
|
||||
Texture2D : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Program
|
||||
*/
|
||||
gfx.Program = {
|
||||
|
||||
/**
|
||||
* @method getID
|
||||
* @return {unsigned int}
|
||||
*/
|
||||
getID : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method init
|
||||
* @param {cc.renderer::DeviceGraphics} arg0
|
||||
* @param {char} arg1
|
||||
* @param {char} arg2
|
||||
* @return {bool}
|
||||
*/
|
||||
init : function (
|
||||
devicegraphics,
|
||||
char,
|
||||
char
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method link
|
||||
*/
|
||||
link : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Program
|
||||
* @constructor
|
||||
*/
|
||||
Program : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* @module video
|
||||
*/
|
||||
var jsb = jsb || {};
|
||||
|
||||
/**
|
||||
* @class VideoPlayer
|
||||
*/
|
||||
jsb.VideoPlayer = {
|
||||
|
||||
/**
|
||||
* @method setFullScreenEnabled
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setFullScreenEnabled : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getFrameWidth
|
||||
* @return {int}
|
||||
*/
|
||||
getFrameWidth : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method duration
|
||||
* @return {float}
|
||||
*/
|
||||
duration : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method pause
|
||||
*/
|
||||
pause : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getFrame
|
||||
*/
|
||||
getFrame : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setShowRawFrame
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setShowRawFrame : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method onPlayEvent
|
||||
* @param {int} arg0
|
||||
*/
|
||||
onPlayEvent : function (
|
||||
int
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method addEventListener
|
||||
* @param {String} arg0
|
||||
* @param {function} arg1
|
||||
*/
|
||||
addEventListener : function (
|
||||
str,
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method seekTo
|
||||
* @param {float} arg0
|
||||
*/
|
||||
seekTo : function (
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method play
|
||||
*/
|
||||
play : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getFrameHeight
|
||||
* @return {int}
|
||||
*/
|
||||
getFrameHeight : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method stop
|
||||
*/
|
||||
stop : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setURL
|
||||
* @param {String} arg0
|
||||
*/
|
||||
setURL : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method update
|
||||
*/
|
||||
update : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method pushFrameDataToTexture2D
|
||||
* @param {cc.renderer::Texture} arg0
|
||||
*/
|
||||
pushFrameDataToTexture2D : function (
|
||||
texture
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method isKeepAspectRatioEnabled
|
||||
* @return {bool}
|
||||
*/
|
||||
isKeepAspectRatioEnabled : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getFrameChannel
|
||||
* @return {int}
|
||||
*/
|
||||
getFrameChannel : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getVideoTexDataSize
|
||||
* @return {int}
|
||||
*/
|
||||
getVideoTexDataSize : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setKeepAspectRatioEnabled
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setKeepAspectRatioEnabled : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method currentTime
|
||||
* @return {float}
|
||||
*/
|
||||
currentTime : function (
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setFrame
|
||||
* @param {float} arg0
|
||||
* @param {float} arg1
|
||||
* @param {float} arg2
|
||||
* @param {float} arg3
|
||||
*/
|
||||
setFrame : function (
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setVisible
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setVisible : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method VideoPlayer
|
||||
* @constructor
|
||||
*/
|
||||
VideoPlayer : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* @module webview
|
||||
*/
|
||||
var jsb = jsb || {};
|
||||
|
||||
/**
|
||||
* @class WebView
|
||||
*/
|
||||
jsb.WebView = {
|
||||
|
||||
/**
|
||||
* @method setOnShouldStartLoading
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setOnShouldStartLoading : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setOnDidFailLoading
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setOnDidFailLoading : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method canGoBack
|
||||
* @return {bool}
|
||||
*/
|
||||
canGoBack : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadHTMLString
|
||||
* @param {String} arg0
|
||||
* @param {String} arg1
|
||||
*/
|
||||
loadHTMLString : function (
|
||||
str,
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method goForward
|
||||
*/
|
||||
goForward : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method goBack
|
||||
*/
|
||||
goBack : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setScalesPageToFit
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setScalesPageToFit : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getOnDidFailLoading
|
||||
* @return {function}
|
||||
*/
|
||||
getOnDidFailLoading : function (
|
||||
)
|
||||
{
|
||||
return std::function<void (cocos2d::WebView , std::string&)>;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadFile
|
||||
* @param {String} arg0
|
||||
*/
|
||||
loadFile : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadURL
|
||||
* @param {String} arg0
|
||||
*/
|
||||
loadURL : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBounces
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setBounces : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method evaluateJS
|
||||
* @param {String} arg0
|
||||
*/
|
||||
evaluateJS : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setOnJSCallback
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setOnJSCallback : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setBackgroundTransparent
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setBackgroundTransparent : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getOnJSCallback
|
||||
* @return {function}
|
||||
*/
|
||||
getOnJSCallback : function (
|
||||
)
|
||||
{
|
||||
return std::function<void (cocos2d::WebView , std::string&)>;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method canGoForward
|
||||
* @return {bool}
|
||||
*/
|
||||
canGoForward : function (
|
||||
)
|
||||
{
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getOnShouldStartLoading
|
||||
* @return {function}
|
||||
*/
|
||||
getOnShouldStartLoading : function (
|
||||
)
|
||||
{
|
||||
return std::function<bool (cocos2d::WebView , std::string&)>;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method stopLoading
|
||||
*/
|
||||
stopLoading : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setFrame
|
||||
* @param {float} arg0
|
||||
* @param {float} arg1
|
||||
* @param {float} arg2
|
||||
* @param {float} arg3
|
||||
*/
|
||||
setFrame : function (
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
float
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setVisible
|
||||
* @param {bool} arg0
|
||||
*/
|
||||
setVisible : function (
|
||||
bool
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method reload
|
||||
*/
|
||||
reload : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method loadData
|
||||
* @param {cc.Data} arg0
|
||||
* @param {String} arg1
|
||||
* @param {String} arg2
|
||||
* @param {String} arg3
|
||||
*/
|
||||
loadData : function (
|
||||
data,
|
||||
str,
|
||||
str,
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setJavascriptInterfaceScheme
|
||||
* @param {String} arg0
|
||||
*/
|
||||
setJavascriptInterfaceScheme : function (
|
||||
str
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method setOnDidFinishLoading
|
||||
* @param {function} arg0
|
||||
*/
|
||||
setOnDidFinishLoading : function (
|
||||
func
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
/**
|
||||
* @method getOnDidFinishLoading
|
||||
* @return {function}
|
||||
*/
|
||||
getOnDidFinishLoading : function (
|
||||
)
|
||||
{
|
||||
return std::function<void (cocos2d::WebView , std::string&)>;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method create
|
||||
* @return {cc.WebView}
|
||||
*/
|
||||
create : function (
|
||||
)
|
||||
{
|
||||
return cc.WebView;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method WebView
|
||||
* @constructor
|
||||
*/
|
||||
WebView : function (
|
||||
)
|
||||
{
|
||||
},
|
||||
|
||||
};
|
||||
@@ -0,0 +1,827 @@
|
||||
#include "scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.hpp"
|
||||
#if (USE_AUDIO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
|
||||
#include "scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "audio/include/AudioEngine.h"
|
||||
|
||||
se::Object* __jsb_cocos2d_AudioProfile_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_AudioProfile_class = nullptr;
|
||||
|
||||
static bool js_audioengine_AudioProfile_get_name(se::State& s)
|
||||
{
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_audioengine_AudioProfile_get_name : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::Value jsret;
|
||||
ok &= std_string_to_seval(cobj->name, &jsret);
|
||||
s.rval() = jsret;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_audioengine_AudioProfile_get_name)
|
||||
|
||||
static bool js_audioengine_AudioProfile_set_name(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_audioengine_AudioProfile_set_name : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioProfile_set_name : Error processing new value");
|
||||
cobj->name = arg0;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_audioengine_AudioProfile_set_name)
|
||||
|
||||
static bool js_audioengine_AudioProfile_get_maxInstances(se::State& s)
|
||||
{
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_audioengine_AudioProfile_get_maxInstances : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::Value jsret;
|
||||
ok &= uint32_to_seval(cobj->maxInstances, &jsret);
|
||||
s.rval() = jsret;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_audioengine_AudioProfile_get_maxInstances)
|
||||
|
||||
static bool js_audioengine_AudioProfile_set_maxInstances(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_audioengine_AudioProfile_set_maxInstances : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
unsigned int arg0 = 0;
|
||||
ok &= seval_to_uint32(args[0], (uint32_t*)&arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioProfile_set_maxInstances : Error processing new value");
|
||||
cobj->maxInstances = arg0;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_audioengine_AudioProfile_set_maxInstances)
|
||||
|
||||
static bool js_audioengine_AudioProfile_get_minDelay(se::State& s)
|
||||
{
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_audioengine_AudioProfile_get_minDelay : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::Value jsret;
|
||||
ok &= double_to_seval(cobj->minDelay, &jsret);
|
||||
s.rval() = jsret;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_audioengine_AudioProfile_get_minDelay)
|
||||
|
||||
static bool js_audioengine_AudioProfile_set_minDelay(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_audioengine_AudioProfile_set_minDelay : Invalid Native Object");
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
double arg0 = 0;
|
||||
ok &= seval_to_double(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioProfile_set_minDelay : Error processing new value");
|
||||
cobj->minDelay = arg0;
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_audioengine_AudioProfile_set_minDelay)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cocos2d_AudioProfile_finalize)
|
||||
|
||||
static bool js_audioengine_AudioProfile_constructor(se::State& s)
|
||||
{
|
||||
cocos2d::AudioProfile* cobj = new (std::nothrow) cocos2d::AudioProfile();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_audioengine_AudioProfile_constructor, __jsb_cocos2d_AudioProfile_class, js_cocos2d_AudioProfile_finalize)
|
||||
|
||||
|
||||
|
||||
|
||||
static bool js_cocos2d_AudioProfile_finalize(se::State& s)
|
||||
{
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::AudioProfile)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
cocos2d::AudioProfile* cobj = (cocos2d::AudioProfile*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_cocos2d_AudioProfile_finalize)
|
||||
|
||||
bool js_register_audioengine_AudioProfile(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("AudioProfile", obj, nullptr, _SE(js_audioengine_AudioProfile_constructor));
|
||||
|
||||
cls->defineProperty("name", _SE(js_audioengine_AudioProfile_get_name), _SE(js_audioengine_AudioProfile_set_name));
|
||||
cls->defineProperty("maxInstances", _SE(js_audioengine_AudioProfile_get_maxInstances), _SE(js_audioengine_AudioProfile_set_maxInstances));
|
||||
cls->defineProperty("minDelay", _SE(js_audioengine_AudioProfile_get_minDelay), _SE(js_audioengine_AudioProfile_set_minDelay));
|
||||
cls->defineFinalizeFunction(_SE(js_cocos2d_AudioProfile_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::AudioProfile>(cls);
|
||||
|
||||
__jsb_cocos2d_AudioProfile_proto = cls->getProto();
|
||||
__jsb_cocos2d_AudioProfile_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
se::Object* __jsb_cocos2d_AudioEngine_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_AudioEngine_class = nullptr;
|
||||
|
||||
static bool js_audioengine_AudioEngine_lazyInit(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
bool result = cocos2d::AudioEngine::lazyInit();
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_lazyInit : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_lazyInit)
|
||||
|
||||
static bool js_audioengine_AudioEngine_setCurrentTime(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
int arg0 = 0;
|
||||
float arg1 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
ok &= seval_to_float(args[1], &arg1);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setCurrentTime : Error processing arguments");
|
||||
bool result = cocos2d::AudioEngine::setCurrentTime(arg0, arg1);
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setCurrentTime : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_setCurrentTime)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getVolume(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getVolume : Error processing arguments");
|
||||
float result = cocos2d::AudioEngine::getVolume(arg0);
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getVolume : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getVolume)
|
||||
|
||||
static bool js_audioengine_AudioEngine_uncache(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_uncache : Error processing arguments");
|
||||
cocos2d::AudioEngine::uncache(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_uncache)
|
||||
|
||||
static bool js_audioengine_AudioEngine_resumeAll(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cocos2d::AudioEngine::resumeAll();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_resumeAll)
|
||||
|
||||
static bool js_audioengine_AudioEngine_stopAll(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cocos2d::AudioEngine::stopAll();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_stopAll)
|
||||
|
||||
static bool js_audioengine_AudioEngine_pause(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_pause : Error processing arguments");
|
||||
cocos2d::AudioEngine::pause(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_pause)
|
||||
|
||||
static bool js_audioengine_AudioEngine_end(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cocos2d::AudioEngine::end();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_end)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getMaxAudioInstance(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cocos2d::AudioEngine::getMaxAudioInstance();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getMaxAudioInstance : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getMaxAudioInstance)
|
||||
|
||||
static bool js_audioengine_AudioEngine_isEnabled(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
bool result = cocos2d::AudioEngine::isEnabled();
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_isEnabled : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_isEnabled)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getDurationFromFile(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getDurationFromFile : Error processing arguments");
|
||||
float result = cocos2d::AudioEngine::getDurationFromFile(arg0);
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getDurationFromFile : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getDurationFromFile)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getCurrentTime(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getCurrentTime : Error processing arguments");
|
||||
float result = cocos2d::AudioEngine::getCurrentTime(arg0);
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getCurrentTime : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getCurrentTime)
|
||||
|
||||
static bool js_audioengine_AudioEngine_setMaxAudioInstance(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setMaxAudioInstance : Error processing arguments");
|
||||
bool result = cocos2d::AudioEngine::setMaxAudioInstance(arg0);
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setMaxAudioInstance : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_setMaxAudioInstance)
|
||||
|
||||
static bool js_audioengine_AudioEngine_isLoop(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_isLoop : Error processing arguments");
|
||||
bool result = cocos2d::AudioEngine::isLoop(arg0);
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_isLoop : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_isLoop)
|
||||
|
||||
static bool js_audioengine_AudioEngine_pauseAll(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cocos2d::AudioEngine::pauseAll();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_pauseAll)
|
||||
|
||||
static bool js_audioengine_AudioEngine_uncacheAll(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cocos2d::AudioEngine::uncacheAll();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_uncacheAll)
|
||||
|
||||
static bool js_audioengine_AudioEngine_setVolume(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
int arg0 = 0;
|
||||
float arg1 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
ok &= seval_to_float(args[1], &arg1);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setVolume : Error processing arguments");
|
||||
cocos2d::AudioEngine::setVolume(arg0, arg1);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_setVolume)
|
||||
|
||||
static bool js_audioengine_AudioEngine_preload(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
do {
|
||||
if (argc == 2) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
if (!ok) { ok = true; break; }
|
||||
std::function<void (bool)> arg1;
|
||||
do {
|
||||
if (args[1].isObject() && args[1].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[1]);
|
||||
jsFunc.toObject()->root();
|
||||
auto lambda = [=](bool larg0) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(1);
|
||||
ok &= boolean_to_seval(larg0, &args[0]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg1 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg1 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
if (!ok) { ok = true; break; }
|
||||
cocos2d::AudioEngine::preload(arg0, arg1);
|
||||
return true;
|
||||
}
|
||||
} while (false);
|
||||
do {
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
if (!ok) { ok = true; break; }
|
||||
cocos2d::AudioEngine::preload(arg0);
|
||||
return true;
|
||||
}
|
||||
} while (false);
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_preload)
|
||||
|
||||
static bool js_audioengine_AudioEngine_setEnabled(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setEnabled : Error processing arguments");
|
||||
cocos2d::AudioEngine::setEnabled(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_setEnabled)
|
||||
|
||||
static bool js_audioengine_AudioEngine_play2d(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
int result = cocos2d::AudioEngine::play2d(arg0);
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
if (argc == 2) {
|
||||
std::string arg0;
|
||||
bool arg1;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
ok &= seval_to_boolean(args[1], &arg1);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
int result = cocos2d::AudioEngine::play2d(arg0, arg1);
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
if (argc == 3) {
|
||||
std::string arg0;
|
||||
bool arg1;
|
||||
float arg2 = 0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
ok &= seval_to_boolean(args[1], &arg1);
|
||||
ok &= seval_to_float(args[2], &arg2);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
int result = cocos2d::AudioEngine::play2d(arg0, arg1, arg2);
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
if (argc == 4) {
|
||||
std::string arg0;
|
||||
bool arg1;
|
||||
float arg2 = 0;
|
||||
const cocos2d::AudioProfile* arg3 = nullptr;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
ok &= seval_to_boolean(args[1], &arg1);
|
||||
ok &= seval_to_float(args[2], &arg2);
|
||||
ok &= seval_to_native_ptr(args[3], &arg3);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
int result = cocos2d::AudioEngine::play2d(arg0, arg1, arg2, arg3);
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_play2d : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_play2d)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getState(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getState : Error processing arguments");
|
||||
int result = (int)cocos2d::AudioEngine::getState(arg0);
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getState : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getState)
|
||||
|
||||
static bool js_audioengine_AudioEngine_resume(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_resume : Error processing arguments");
|
||||
cocos2d::AudioEngine::resume(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_resume)
|
||||
|
||||
static bool js_audioengine_AudioEngine_stop(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_stop : Error processing arguments");
|
||||
cocos2d::AudioEngine::stop(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_stop)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getDuration(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getDuration : Error processing arguments");
|
||||
float result = cocos2d::AudioEngine::getDuration(arg0);
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getDuration : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getDuration)
|
||||
|
||||
static bool js_audioengine_AudioEngine_setLoop(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
int arg0 = 0;
|
||||
bool arg1;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
ok &= seval_to_boolean(args[1], &arg1);
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setLoop : Error processing arguments");
|
||||
cocos2d::AudioEngine::setLoop(arg0, arg1);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_setLoop)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getDefaultProfile(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
cocos2d::AudioProfile* result = cocos2d::AudioEngine::getDefaultProfile();
|
||||
ok &= native_ptr_to_seval<cocos2d::AudioProfile>((cocos2d::AudioProfile*)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getDefaultProfile : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getDefaultProfile)
|
||||
|
||||
static bool js_audioengine_AudioEngine_setFinishCallback(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
int arg0 = 0;
|
||||
std::function<void (int, const std::string&)> arg1;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
do {
|
||||
if (args[1].isObject() && args[1].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[1]);
|
||||
jsFunc.toObject()->root();
|
||||
auto lambda = [=](int larg0, const std::string& larg1) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(2);
|
||||
ok &= int32_to_seval(larg0, &args[0]);
|
||||
ok &= std_string_to_seval(larg1, &args[1]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg1 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg1 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_setFinishCallback : Error processing arguments");
|
||||
cocos2d::AudioEngine::setFinishCallback(arg0, arg1);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_setFinishCallback)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getProfile(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
do {
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
if (!ok) { ok = true; break; }
|
||||
cocos2d::AudioProfile* result = cocos2d::AudioEngine::getProfile(arg0);
|
||||
ok &= native_ptr_to_seval<cocos2d::AudioProfile>((cocos2d::AudioProfile*)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getProfile : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
} while (false);
|
||||
do {
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
if (!ok) { ok = true; break; }
|
||||
cocos2d::AudioProfile* result = cocos2d::AudioEngine::getProfile(arg0);
|
||||
ok &= native_ptr_to_seval<cocos2d::AudioProfile>((cocos2d::AudioProfile*)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getProfile : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
} while (false);
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getProfile)
|
||||
|
||||
static bool js_audioengine_AudioEngine_getPlayingAudioCount(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cocos2d::AudioEngine::getPlayingAudioCount();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_audioengine_AudioEngine_getPlayingAudioCount : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_audioengine_AudioEngine_getPlayingAudioCount)
|
||||
|
||||
|
||||
|
||||
|
||||
bool js_register_audioengine_AudioEngine(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("AudioEngine", obj, nullptr, nullptr);
|
||||
|
||||
cls->defineStaticFunction("lazyInit", _SE(js_audioengine_AudioEngine_lazyInit));
|
||||
cls->defineStaticFunction("setCurrentTime", _SE(js_audioengine_AudioEngine_setCurrentTime));
|
||||
cls->defineStaticFunction("getVolume", _SE(js_audioengine_AudioEngine_getVolume));
|
||||
cls->defineStaticFunction("uncache", _SE(js_audioengine_AudioEngine_uncache));
|
||||
cls->defineStaticFunction("resumeAll", _SE(js_audioengine_AudioEngine_resumeAll));
|
||||
cls->defineStaticFunction("stopAll", _SE(js_audioengine_AudioEngine_stopAll));
|
||||
cls->defineStaticFunction("pause", _SE(js_audioengine_AudioEngine_pause));
|
||||
cls->defineStaticFunction("end", _SE(js_audioengine_AudioEngine_end));
|
||||
cls->defineStaticFunction("getMaxAudioInstance", _SE(js_audioengine_AudioEngine_getMaxAudioInstance));
|
||||
cls->defineStaticFunction("isEnabled", _SE(js_audioengine_AudioEngine_isEnabled));
|
||||
cls->defineStaticFunction("getDurationFromFile", _SE(js_audioengine_AudioEngine_getDurationFromFile));
|
||||
cls->defineStaticFunction("getCurrentTime", _SE(js_audioengine_AudioEngine_getCurrentTime));
|
||||
cls->defineStaticFunction("setMaxAudioInstance", _SE(js_audioengine_AudioEngine_setMaxAudioInstance));
|
||||
cls->defineStaticFunction("isLoop", _SE(js_audioengine_AudioEngine_isLoop));
|
||||
cls->defineStaticFunction("pauseAll", _SE(js_audioengine_AudioEngine_pauseAll));
|
||||
cls->defineStaticFunction("uncacheAll", _SE(js_audioengine_AudioEngine_uncacheAll));
|
||||
cls->defineStaticFunction("setVolume", _SE(js_audioengine_AudioEngine_setVolume));
|
||||
cls->defineStaticFunction("preload", _SE(js_audioengine_AudioEngine_preload));
|
||||
cls->defineStaticFunction("setEnabled", _SE(js_audioengine_AudioEngine_setEnabled));
|
||||
cls->defineStaticFunction("play2d", _SE(js_audioengine_AudioEngine_play2d));
|
||||
cls->defineStaticFunction("getState", _SE(js_audioengine_AudioEngine_getState));
|
||||
cls->defineStaticFunction("resume", _SE(js_audioengine_AudioEngine_resume));
|
||||
cls->defineStaticFunction("stop", _SE(js_audioengine_AudioEngine_stop));
|
||||
cls->defineStaticFunction("getDuration", _SE(js_audioengine_AudioEngine_getDuration));
|
||||
cls->defineStaticFunction("setLoop", _SE(js_audioengine_AudioEngine_setLoop));
|
||||
cls->defineStaticFunction("getDefaultProfile", _SE(js_audioengine_AudioEngine_getDefaultProfile));
|
||||
cls->defineStaticFunction("setFinishCallback", _SE(js_audioengine_AudioEngine_setFinishCallback));
|
||||
cls->defineStaticFunction("getProfile", _SE(js_audioengine_AudioEngine_getProfile));
|
||||
cls->defineStaticFunction("getPlayingAudioCount", _SE(js_audioengine_AudioEngine_getPlayingAudioCount));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::AudioEngine>(cls);
|
||||
|
||||
__jsb_cocos2d_AudioEngine_proto = cls->getProto();
|
||||
__jsb_cocos2d_AudioEngine_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool register_all_audioengine(se::Object* obj)
|
||||
{
|
||||
// Get the ns
|
||||
se::Value nsVal;
|
||||
if (!obj->getProperty("jsb", &nsVal))
|
||||
{
|
||||
se::HandleObject jsobj(se::Object::createPlainObject());
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("jsb", nsVal);
|
||||
}
|
||||
se::Object* ns = nsVal.toObject();
|
||||
|
||||
js_register_audioengine_AudioProfile(ns);
|
||||
js_register_audioengine_AudioEngine(ns);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //#if (USE_AUDIO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if (USE_AUDIO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_AudioProfile_proto;
|
||||
extern se::Class* __jsb_cocos2d_AudioProfile_class;
|
||||
|
||||
bool js_register_cocos2d_AudioProfile(se::Object* obj);
|
||||
bool register_all_audioengine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioProfile_AudioProfile);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_AudioEngine_proto;
|
||||
extern se::Class* __jsb_cocos2d_AudioEngine_class;
|
||||
|
||||
bool js_register_cocos2d_AudioEngine(se::Object* obj);
|
||||
bool register_all_audioengine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_lazyInit);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_setCurrentTime);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getVolume);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_uncache);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_resumeAll);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_stopAll);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_pause);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_end);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getMaxAudioInstance);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_isEnabled);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getDurationFromFile);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getCurrentTime);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_setMaxAudioInstance);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_isLoop);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_pauseAll);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_uncacheAll);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_setVolume);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_preload);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_setEnabled);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_play2d);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getState);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_resume);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_stop);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getDuration);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_setLoop);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getDefaultProfile);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_setFinishCallback);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getProfile);
|
||||
SE_DECLARE_FUNC(js_audioengine_AudioEngine_getPlayingAudioCount);
|
||||
|
||||
#endif //#if (USE_AUDIO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
@@ -0,0 +1,126 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_FileUtils_proto;
|
||||
extern se::Class* __jsb_cocos2d_FileUtils_class;
|
||||
|
||||
bool js_register_cocos2d_FileUtils(se::Object* obj);
|
||||
bool register_all_engine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_writeDataToFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_fullPathForFilename);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getStringFromFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_removeFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getDataFromFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_isAbsolutePath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_renameFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_normalizePath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getDefaultResourceRootPath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_loadFilenameLookupDictionaryFromFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_isPopupNotify);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getValueVectorFromFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getSearchPaths);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getFileDir);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_writeToFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getOriginalSearchPaths);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_listFiles);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getValueMapFromFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getFileSize);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getValueMapFromData);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_removeDirectory);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_setSearchPaths);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_writeStringToFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_setSearchResolutionsOrder);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_addSearchResolutionsOrder);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_addSearchPath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_writeValueVectorToFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_isFileExist);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_purgeCachedEntries);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_fullPathFromRelativeFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getSuitableFOpen);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_writeValueMapToFile);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getFileExtension);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_setWritablePath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_setPopupNotify);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_isDirectoryExist);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_setDefaultResourceRootPath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getSearchResolutionsOrder);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_createDirectory);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getWritablePath);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_setDelegate);
|
||||
SE_DECLARE_FUNC(js_engine_FileUtils_getInstance);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_Device_proto;
|
||||
extern se::Class* __jsb_cocos2d_Device_class;
|
||||
|
||||
bool js_register_cocos2d_Device(se::Object* obj);
|
||||
bool register_all_engine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getDevicePixelRatio);
|
||||
SE_DECLARE_FUNC(js_engine_Device_setAccelerometerEnabled);
|
||||
SE_DECLARE_FUNC(js_engine_Device_setAccelerometerInterval);
|
||||
SE_DECLARE_FUNC(js_engine_Device_vibrate);
|
||||
SE_DECLARE_FUNC(js_engine_Device_setKeepScreenOn);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getNetworkType);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getBatteryLevel);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getDeviceRotation);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getDPI);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getSafeAreaEdge);
|
||||
SE_DECLARE_FUNC(js_engine_Device_getDeviceModel);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_SAXParser_proto;
|
||||
extern se::Class* __jsb_cocos2d_SAXParser_class;
|
||||
|
||||
bool js_register_cocos2d_SAXParser(se::Object* obj);
|
||||
bool register_all_engine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_engine_SAXParser_init);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_CanvasGradient_proto;
|
||||
extern se::Class* __jsb_cocos2d_CanvasGradient_class;
|
||||
|
||||
bool js_register_cocos2d_CanvasGradient(se::Object* obj);
|
||||
bool register_all_engine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasGradient_addColorStop);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasGradient_CanvasGradient);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_CanvasRenderingContext2D_proto;
|
||||
extern se::Class* __jsb_cocos2d_CanvasRenderingContext2D_class;
|
||||
|
||||
bool js_register_cocos2d_CanvasRenderingContext2D(se::Object* obj);
|
||||
bool register_all_engine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_restore);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_moveTo);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_lineTo);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_setPremultiply);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_setTransform);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_stroke);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_measureText);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_fill);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D__fillImageData);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_scale);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_clearRect);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_transform);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_fillText);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_strokeText);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_save);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_fillRect);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_rotate);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_beginPath);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_rect);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_translate);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_createLinearGradient);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_closePath);
|
||||
SE_DECLARE_FUNC(js_engine_CanvasRenderingContext2D_CanvasRenderingContext2D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_LabelRenderer_proto;
|
||||
extern se::Class* __jsb_cocos2d_LabelRenderer_class;
|
||||
|
||||
bool js_register_cocos2d_LabelRenderer(se::Object* obj);
|
||||
bool register_all_engine(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_engine_LabelRenderer_setEffect);
|
||||
SE_DECLARE_FUNC(js_engine_LabelRenderer_bindNodeProxy);
|
||||
SE_DECLARE_FUNC(js_engine_LabelRenderer_render);
|
||||
SE_DECLARE_FUNC(js_engine_LabelRenderer_setJsComponent);
|
||||
SE_DECLARE_FUNC(js_engine_LabelRenderer_getJsComponent);
|
||||
SE_DECLARE_FUNC(js_engine_LabelRenderer_LabelRenderer);
|
||||
|
||||
@@ -0,0 +1,516 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if USE_DRAGONBONES > 0
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_dragonBones_BaseObject_proto;
|
||||
extern se::Class* __jsb_dragonBones_BaseObject_class;
|
||||
|
||||
bool js_register_dragonBones_BaseObject(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseObject_returnToPool);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseObject_clearPool);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseObject_setMaxCount);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_Matrix_proto;
|
||||
extern se::Class* __jsb_dragonBones_Matrix_class;
|
||||
|
||||
bool js_register_dragonBones_Matrix(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_Transform_proto;
|
||||
extern se::Class* __jsb_dragonBones_Transform_class;
|
||||
|
||||
bool js_register_dragonBones_Transform(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Transform_normalizeRadian);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_TextureAtlasData_proto;
|
||||
extern se::Class* __jsb_dragonBones_TextureAtlasData_class;
|
||||
|
||||
bool js_register_dragonBones_TextureAtlasData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureAtlasData_createTexture);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureAtlasData_getTexture);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureAtlasData_addTexture);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_TextureData_proto;
|
||||
extern se::Class* __jsb_dragonBones_TextureData_class;
|
||||
|
||||
bool js_register_dragonBones_TextureData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureData_getParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureData_setFrame);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureData_getRegion);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureData_getFrame);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureData_setParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TextureData_createRectangle);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_UserData_proto;
|
||||
extern se::Class* __jsb_dragonBones_UserData_class;
|
||||
|
||||
bool js_register_dragonBones_UserData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_getFloat);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_getFloats);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_getString);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_getInts);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_getInt);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_addInt);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_getStrings);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_addFloat);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_UserData_addString);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_ArmatureData_proto;
|
||||
extern se::Class* __jsb_dragonBones_ArmatureData_class;
|
||||
|
||||
bool js_register_dragonBones_ArmatureData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getBone);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_addAction);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_setUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getSlot);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getSkin);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_setDefaultAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_setType);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_setParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getDefaultSkin);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getMesh);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_setDefaultSkin);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getAnimationNames);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getType);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_addConstraint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getAABB);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getDefaultAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_getConstraint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureData_sortBones);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_BoneData_proto;
|
||||
extern se::Class* __jsb_dragonBones_BoneData_class;
|
||||
|
||||
bool js_register_dragonBones_BoneData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoneData_setParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoneData_getTransfrom);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoneData_setUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoneData_getUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoneData_getParent);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_SlotData_proto;
|
||||
extern se::Class* __jsb_dragonBones_SlotData_class;
|
||||
|
||||
bool js_register_dragonBones_SlotData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_setUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_setColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_getUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_getColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_setBlendMode);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_getBlendMode);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_setParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_getParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_createColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SlotData_getDefaultColor);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_DragonBonesData_proto;
|
||||
extern se::Class* __jsb_dragonBones_DragonBonesData_class;
|
||||
|
||||
bool js_register_dragonBones_DragonBonesData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_DragonBonesData_setUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_DragonBonesData_getUserData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_DragonBonesData_getFrameIndices);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_DragonBonesData_getArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_DragonBonesData_getArmatureNames);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_DragonBonesData_addArmature);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_SkinData_proto;
|
||||
extern se::Class* __jsb_dragonBones_SkinData_class;
|
||||
|
||||
bool js_register_dragonBones_SkinData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SkinData_addDisplay);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_SkinData_getDisplay);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_BoundingBoxData_proto;
|
||||
extern se::Class* __jsb_dragonBones_BoundingBoxData_class;
|
||||
|
||||
bool js_register_dragonBones_BoundingBoxData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoundingBoxData_intersectsSegment);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoundingBoxData_containsPoint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoundingBoxData_getType);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BoundingBoxData_setType);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_RectangleBoundingBoxData_proto;
|
||||
extern se::Class* __jsb_dragonBones_RectangleBoundingBoxData_class;
|
||||
|
||||
bool js_register_dragonBones_RectangleBoundingBoxData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_RectangleBoundingBoxData_rectangleIntersectsSegment);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_RectangleBoundingBoxData_getTypeIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_RectangleBoundingBoxData_RectangleBoundingBoxData);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_EllipseBoundingBoxData_proto;
|
||||
extern se::Class* __jsb_dragonBones_EllipseBoundingBoxData_class;
|
||||
|
||||
bool js_register_dragonBones_EllipseBoundingBoxData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EllipseBoundingBoxData_getTypeIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EllipseBoundingBoxData_ellipseIntersectsSegment);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EllipseBoundingBoxData_EllipseBoundingBoxData);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_PolygonBoundingBoxData_proto;
|
||||
extern se::Class* __jsb_dragonBones_PolygonBoundingBoxData_class;
|
||||
|
||||
bool js_register_dragonBones_PolygonBoundingBoxData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_PolygonBoundingBoxData_getVertices);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_PolygonBoundingBoxData_getTypeIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_PolygonBoundingBoxData_polygonIntersectsSegment);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_PolygonBoundingBoxData_PolygonBoundingBoxData);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_AnimationData_proto;
|
||||
extern se::Class* __jsb_dragonBones_AnimationData_class;
|
||||
|
||||
bool js_register_dragonBones_AnimationData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_getActionTimeline);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_setParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_setActionTimeline);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_getSlotCachedFrameIndices);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_addConstraintTimeline);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_getBoneCachedFrameIndices);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_getZOrderTimeline);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_setZOrderTimeline);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationData_getParent);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_Armature_proto;
|
||||
extern se::Class* __jsb_dragonBones_Armature_class;
|
||||
|
||||
bool js_register_dragonBones_Armature(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getBone);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getClock);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_render);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getSlot);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_setClock);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature__bufferAction);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature__addBone);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getAnimatable);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getName);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_dispose);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_invalidUpdate);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getCacheFrameRate);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getFlipY);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getFlipX);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_intersectsSegment);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_setCacheFrameRate);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature__addConstraint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_setFlipY);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_setFlipX);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature__addSlot);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_advanceTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getArmatureData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getEventDispatcher);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_containsPoint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Armature_getProxy);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_TransformObject_proto;
|
||||
extern se::Class* __jsb_dragonBones_TransformObject_class;
|
||||
|
||||
bool js_register_dragonBones_TransformObject(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TransformObject_getOffset);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TransformObject_getGlobal);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TransformObject_getOrigin);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TransformObject_getGlobalTransformMatrix);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TransformObject_getArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_TransformObject_updateGlobalTransform);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_AnimationState_proto;
|
||||
extern se::Class* __jsb_dragonBones_AnimationState_class;
|
||||
|
||||
bool js_register_dragonBones_AnimationState(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_isCompleted);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_play);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_fadeOut);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_getName);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_stop);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_setCurrentTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_getCurrentTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_getTotalTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_init);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_isFadeIn);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_addBoneMask);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_containsBoneMask);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_removeAllBoneMask);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_getAnimationData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_isFadeComplete);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_advanceTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_isPlaying);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_removeBoneMask);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_getCurrentPlayTimes);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AnimationState_isFadeOut);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_Bone_proto;
|
||||
extern se::Class* __jsb_dragonBones_Bone_class;
|
||||
|
||||
bool js_register_dragonBones_Bone(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_getOffsetMode);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_getParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_getName);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_contains);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_update);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_updateByConstraint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_getVisible);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_init);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_invalidUpdate);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_setOffsetMode);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_setVisible);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Bone_getBoneData);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_Slot_proto;
|
||||
extern se::Class* __jsb_dragonBones_Slot_class;
|
||||
|
||||
bool js_register_dragonBones_Slot(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot__updateColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_setRawDisplayDatas);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_getVisible);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_getSlotData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_getName);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot__setZorder);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_invalidUpdate);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_getChildArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_intersectsSegment);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_update);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_updateTransformAndMatrix);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_getParent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_getBoundingBoxData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_setChildArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_replaceDisplayData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_containsPoint);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Slot_setVisible);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_WorldClock_proto;
|
||||
extern se::Class* __jsb_dragonBones_WorldClock_class;
|
||||
|
||||
bool js_register_dragonBones_WorldClock(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_render);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_clear);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_contains);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_getClock);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_advanceTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_setClock);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_WorldClock_getStaticClock);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_Animation_proto;
|
||||
extern se::Class* __jsb_dragonBones_Animation_class;
|
||||
|
||||
bool js_register_dragonBones_Animation(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_init);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_gotoAndPlayByTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_fadeIn);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_playConfig);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_isCompleted);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_play);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_getState);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_stop);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_getLastAnimationName);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_getLastAnimationState);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_getAnimationNames);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_advanceTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_isPlaying);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_gotoAndPlayByProgress);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_getAnimationConfig);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_reset);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_hasAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_gotoAndStopByTime);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_gotoAndStopByProgress);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_gotoAndPlayByFrame);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_Animation_gotoAndStopByFrame);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_EventObject_proto;
|
||||
extern se::Class* __jsb_dragonBones_EventObject_class;
|
||||
|
||||
bool js_register_dragonBones_EventObject(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EventObject_getBone);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EventObject_getData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EventObject_getAnimationState);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EventObject_getArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EventObject_getSlot);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_EventObject_actionDataToInstance);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_BaseFactory_proto;
|
||||
extern se::Class* __jsb_dragonBones_BaseFactory_class;
|
||||
|
||||
bool js_register_dragonBones_BaseFactory(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_replaceSkin);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_replaceAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_getClock);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_removeDragonBonesData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_removeTextureAtlasData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_parseDragonBonesData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_clear);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_addDragonBonesData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_buildArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_addTextureAtlasData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_getArmatureData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_replaceSlotDisplay);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_changeSkin);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_replaceDisplay);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_BaseFactory_getDragonBonesData);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CCTextureAtlasData_proto;
|
||||
extern se::Class* __jsb_dragonBones_CCTextureAtlasData_class;
|
||||
|
||||
bool js_register_dragonBones_CCTextureAtlasData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCTextureAtlasData_setRenderTexture);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCTextureAtlasData_getRenderTexture);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CCTextureData_proto;
|
||||
extern se::Class* __jsb_dragonBones_CCTextureData_class;
|
||||
|
||||
bool js_register_dragonBones_CCTextureData(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CCSlot_proto;
|
||||
extern se::Class* __jsb_dragonBones_CCSlot_class;
|
||||
|
||||
bool js_register_dragonBones_CCSlot(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCSlot_getTexture);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCSlot_updateWorldMatrix);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CCArmatureDisplay_proto;
|
||||
extern se::Class* __jsb_dragonBones_CCArmatureDisplay_class;
|
||||
|
||||
bool js_register_dragonBones_CCArmatureDisplay(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_dbInit);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_addDBEventListener);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_getRootDisplay);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setAttachUtil);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_removeDBEventListener);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setEffect);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_dispose);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setOpacityModifyRGB);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_dbClear);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_dispatchDBEvent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_getDebugData);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_hasDBEventListener);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_dbUpdate);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setDBEventCallback);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setDebugBonesEnabled);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_getAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_bindNodeProxy);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_setBatchEnabled);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_dbRender);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_getArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_convertToRootSpace);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_create);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureDisplay_CCArmatureDisplay);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CCFactory_proto;
|
||||
extern se::Class* __jsb_dragonBones_CCFactory_class;
|
||||
|
||||
bool js_register_dragonBones_CCFactory(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_setTimeScale);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_getSoundEventManager);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_render);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_removeDragonBonesDataByUUID);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_update);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_remove);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_getTextureAtlasDataByIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_getDragonBones);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_parseDragonBonesDataByPath);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_add);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_buildArmatureDisplay);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_stopSchedule);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_removeTextureAtlasDataByIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_getTimeScale);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_isInit);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_destroyFactory);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_getClock);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_getFactory);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCFactory_CCFactory);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_ArmatureCacheMgr_proto;
|
||||
extern se::Class* __jsb_dragonBones_ArmatureCacheMgr_class;
|
||||
|
||||
bool js_register_dragonBones_ArmatureCacheMgr(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureCacheMgr_removeArmatureCache);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureCacheMgr_buildArmatureCache);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureCacheMgr_destroyInstance);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_ArmatureCacheMgr_getInstance);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CCArmatureCacheDisplay_proto;
|
||||
extern se::Class* __jsb_dragonBones_CCArmatureCacheDisplay_class;
|
||||
|
||||
bool js_register_dragonBones_CCArmatureCacheDisplay(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setTimeScale);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_render);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_addDBEventListener);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setAttachUtil);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_removeDBEventListener);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_onEnable);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setEffect);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_dispose);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setOpacityModifyRGB);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_dispatchDBEvent);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_beginSchedule);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_updateAllAnimationCache);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_update);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_playAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setDBEventCallback);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_updateAnimationCache);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_getTimeScale);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_getAnimation);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_onDisable);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_bindNodeProxy);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_setBatchEnabled);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_getArmature);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_stopSchedule);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CCArmatureCacheDisplay_CCArmatureCacheDisplay);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_AttachUtilBase_proto;
|
||||
extern se::Class* __jsb_dragonBones_AttachUtilBase_class;
|
||||
|
||||
bool js_register_dragonBones_AttachUtilBase(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_AttachUtilBase_associateAttachedNode);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_RealTimeAttachUtil_proto;
|
||||
extern se::Class* __jsb_dragonBones_RealTimeAttachUtil_class;
|
||||
|
||||
bool js_register_dragonBones_RealTimeAttachUtil(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_RealTimeAttachUtil_RealTimeAttachUtil);
|
||||
|
||||
extern se::Object* __jsb_dragonBones_CacheModeAttachUtil_proto;
|
||||
extern se::Class* __jsb_dragonBones_CacheModeAttachUtil_class;
|
||||
|
||||
bool js_register_dragonBones_CacheModeAttachUtil(se::Object* obj);
|
||||
bool register_all_cocos2dx_dragonbones(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_dragonbones_CacheModeAttachUtil_CacheModeAttachUtil);
|
||||
|
||||
#endif //#if USE_DRAGONBONES > 0
|
||||
@@ -0,0 +1,429 @@
|
||||
#include "scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.hpp"
|
||||
#if USE_MIDDLEWARE > 0
|
||||
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
|
||||
#include "scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "editor-support/middleware-adapter.h"
|
||||
#include "editor-support/MiddlewareManager.h"
|
||||
|
||||
se::Object* __jsb_cocos2d_middleware_Texture2D_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_middleware_Texture2D_class = nullptr;
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_getRealTextureIndex(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_getRealTextureIndex : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getRealTextureIndex();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_getRealTextureIndex : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_getRealTextureIndex)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_setTexParamCallback(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_setTexParamCallback : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<void (int, unsigned int, unsigned int, unsigned int, unsigned int)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](int larg0, unsigned int larg1, unsigned int larg2, unsigned int larg3, unsigned int larg4) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(5);
|
||||
ok &= int32_to_seval(larg0, &args[0]);
|
||||
ok &= uint32_to_seval(larg1, &args[1]);
|
||||
ok &= uint32_to_seval(larg2, &args[2]);
|
||||
ok &= uint32_to_seval(larg3, &args[3]);
|
||||
ok &= uint32_to_seval(larg4, &args[4]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_setTexParamCallback : Error processing arguments");
|
||||
cobj->setTexParamCallback(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_setTexParamCallback)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_setPixelsHigh(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_setPixelsHigh : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_setPixelsHigh : Error processing arguments");
|
||||
cobj->setPixelsHigh(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_setPixelsHigh)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_getNativeTexture(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_getNativeTexture : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
cocos2d::renderer::Texture* result = cobj->getNativeTexture();
|
||||
ok &= native_ptr_to_seval<cocos2d::renderer::Texture>((cocos2d::renderer::Texture*)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_getNativeTexture : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_getNativeTexture)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_setPixelsWide(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_setPixelsWide : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_setPixelsWide : Error processing arguments");
|
||||
cobj->setPixelsWide(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_setPixelsWide)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_getPixelsHigh(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_getPixelsHigh : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getPixelsHigh();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_getPixelsHigh : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_getPixelsHigh)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_getPixelsWide(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_getPixelsWide : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getPixelsWide();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_getPixelsWide : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_getPixelsWide)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_setRealTextureIndex(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_setRealTextureIndex : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_setRealTextureIndex : Error processing arguments");
|
||||
cobj->setRealTextureIndex(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_setRealTextureIndex)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_setNativeTexture(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_setNativeTexture : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
cocos2d::renderer::Texture* arg0 = nullptr;
|
||||
ok &= seval_to_native_ptr(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_setNativeTexture : Error processing arguments");
|
||||
cobj->setNativeTexture(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_setNativeTexture)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_setTexParameters(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_Texture2D_setTexParameters : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
cocos2d::middleware::Texture2D::_TexParams arg0;
|
||||
#pragma warning NO CONVERSION TO NATIVE FOR _TexParams
|
||||
ok = false;
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_Texture2D_setTexParameters : Error processing arguments");
|
||||
cobj->setTexParameters(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_Texture2D_setTexParameters)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cocos2d_middleware_Texture2D_finalize)
|
||||
|
||||
static bool js_cocos2dx_editor_support_Texture2D_constructor(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::Texture2D* cobj = new (std::nothrow) cocos2d::middleware::Texture2D();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_cocos2dx_editor_support_Texture2D_constructor, __jsb_cocos2d_middleware_Texture2D_class, js_cocos2d_middleware_Texture2D_finalize)
|
||||
|
||||
|
||||
|
||||
|
||||
static bool js_cocos2d_middleware_Texture2D_finalize(se::State& s)
|
||||
{
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::middleware::Texture2D)", s.nativeThisObject());
|
||||
cocos2d::middleware::Texture2D* cobj = (cocos2d::middleware::Texture2D*)s.nativeThisObject();
|
||||
cobj->release();
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_cocos2d_middleware_Texture2D_finalize)
|
||||
|
||||
bool js_register_cocos2dx_editor_support_Texture2D(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("Texture2D", obj, nullptr, _SE(js_cocos2dx_editor_support_Texture2D_constructor));
|
||||
|
||||
cls->defineFunction("getRealTextureIndex", _SE(js_cocos2dx_editor_support_Texture2D_getRealTextureIndex));
|
||||
cls->defineFunction("setTexParamCallback", _SE(js_cocos2dx_editor_support_Texture2D_setTexParamCallback));
|
||||
cls->defineFunction("setPixelsHigh", _SE(js_cocos2dx_editor_support_Texture2D_setPixelsHigh));
|
||||
cls->defineFunction("getNativeTexture", _SE(js_cocos2dx_editor_support_Texture2D_getNativeTexture));
|
||||
cls->defineFunction("setPixelsWide", _SE(js_cocos2dx_editor_support_Texture2D_setPixelsWide));
|
||||
cls->defineFunction("getPixelsHigh", _SE(js_cocos2dx_editor_support_Texture2D_getPixelsHigh));
|
||||
cls->defineFunction("getPixelsWide", _SE(js_cocos2dx_editor_support_Texture2D_getPixelsWide));
|
||||
cls->defineFunction("setRealTextureIndex", _SE(js_cocos2dx_editor_support_Texture2D_setRealTextureIndex));
|
||||
cls->defineFunction("setNativeTexture", _SE(js_cocos2dx_editor_support_Texture2D_setNativeTexture));
|
||||
cls->defineFunction("setTexParameters", _SE(js_cocos2dx_editor_support_Texture2D_setTexParameters));
|
||||
cls->defineFinalizeFunction(_SE(js_cocos2d_middleware_Texture2D_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::middleware::Texture2D>(cls);
|
||||
|
||||
__jsb_cocos2d_middleware_Texture2D_proto = cls->getProto();
|
||||
__jsb_cocos2d_middleware_Texture2D_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
se::Object* __jsb_cocos2d_middleware_MiddlewareManager_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_middleware_MiddlewareManager_class = nullptr;
|
||||
|
||||
static bool js_cocos2dx_editor_support_MiddlewareManager_render(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::MiddlewareManager* cobj = (cocos2d::middleware::MiddlewareManager*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_MiddlewareManager_render : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
float arg0 = 0;
|
||||
ok &= seval_to_float(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_render : Error processing arguments");
|
||||
cobj->render(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_render)
|
||||
|
||||
static bool js_cocos2dx_editor_support_MiddlewareManager_update(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::MiddlewareManager* cobj = (cocos2d::middleware::MiddlewareManager*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_MiddlewareManager_update : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
float arg0 = 0;
|
||||
ok &= seval_to_float(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_update : Error processing arguments");
|
||||
cobj->update(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_update)
|
||||
|
||||
static bool js_cocos2dx_editor_support_MiddlewareManager_destroyInstance(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cocos2d::middleware::MiddlewareManager::destroyInstance();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_destroyInstance)
|
||||
|
||||
static bool js_cocos2dx_editor_support_MiddlewareManager_generateModuleID(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
uint8_t result = cocos2d::middleware::MiddlewareManager::generateModuleID();
|
||||
ok &= uint8_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_generateModuleID : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_generateModuleID)
|
||||
|
||||
static bool js_cocos2dx_editor_support_MiddlewareManager_getInstance(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
cocos2d::middleware::MiddlewareManager* result = cocos2d::middleware::MiddlewareManager::getInstance();
|
||||
ok &= native_ptr_to_seval<cocos2d::middleware::MiddlewareManager>((cocos2d::middleware::MiddlewareManager*)result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_getInstance : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getInstance)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cocos2d_middleware_MiddlewareManager_finalize)
|
||||
|
||||
static bool js_cocos2dx_editor_support_MiddlewareManager_constructor(se::State& s)
|
||||
{
|
||||
cocos2d::middleware::MiddlewareManager* cobj = new (std::nothrow) cocos2d::middleware::MiddlewareManager();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_cocos2dx_editor_support_MiddlewareManager_constructor, __jsb_cocos2d_middleware_MiddlewareManager_class, js_cocos2d_middleware_MiddlewareManager_finalize)
|
||||
|
||||
|
||||
|
||||
|
||||
static bool js_cocos2d_middleware_MiddlewareManager_finalize(se::State& s)
|
||||
{
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::middleware::MiddlewareManager)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
cocos2d::middleware::MiddlewareManager* cobj = (cocos2d::middleware::MiddlewareManager*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_cocos2d_middleware_MiddlewareManager_finalize)
|
||||
|
||||
bool js_register_cocos2dx_editor_support_MiddlewareManager(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("MiddlewareManager", obj, nullptr, _SE(js_cocos2dx_editor_support_MiddlewareManager_constructor));
|
||||
|
||||
cls->defineFunction("render", _SE(js_cocos2dx_editor_support_MiddlewareManager_render));
|
||||
cls->defineFunction("update", _SE(js_cocos2dx_editor_support_MiddlewareManager_update));
|
||||
cls->defineStaticFunction("destroyInstance", _SE(js_cocos2dx_editor_support_MiddlewareManager_destroyInstance));
|
||||
cls->defineStaticFunction("generateModuleID", _SE(js_cocos2dx_editor_support_MiddlewareManager_generateModuleID));
|
||||
cls->defineStaticFunction("getInstance", _SE(js_cocos2dx_editor_support_MiddlewareManager_getInstance));
|
||||
cls->defineFinalizeFunction(_SE(js_cocos2d_middleware_MiddlewareManager_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::middleware::MiddlewareManager>(cls);
|
||||
|
||||
__jsb_cocos2d_middleware_MiddlewareManager_proto = cls->getProto();
|
||||
__jsb_cocos2d_middleware_MiddlewareManager_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool register_all_cocos2dx_editor_support(se::Object* obj)
|
||||
{
|
||||
// Get the ns
|
||||
se::Value nsVal;
|
||||
if (!obj->getProperty("middleware", &nsVal))
|
||||
{
|
||||
se::HandleObject jsobj(se::Object::createPlainObject());
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("middleware", nsVal);
|
||||
}
|
||||
se::Object* ns = nsVal.toObject();
|
||||
|
||||
js_register_cocos2dx_editor_support_MiddlewareManager(ns);
|
||||
js_register_cocos2dx_editor_support_Texture2D(ns);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //#if USE_MIDDLEWARE > 0
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if USE_MIDDLEWARE > 0
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_middleware_Texture2D_proto;
|
||||
extern se::Class* __jsb_cocos2d_middleware_Texture2D_class;
|
||||
|
||||
bool js_register_cocos2d_middleware_Texture2D(se::Object* obj);
|
||||
bool register_all_cocos2dx_editor_support(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_getRealTextureIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_setTexParamCallback);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_setPixelsHigh);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_getNativeTexture);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_setPixelsWide);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_getPixelsHigh);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_getPixelsWide);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_setRealTextureIndex);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_setNativeTexture);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_setTexParameters);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_Texture2D_Texture2D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_middleware_MiddlewareManager_proto;
|
||||
extern se::Class* __jsb_cocos2d_middleware_MiddlewareManager_class;
|
||||
|
||||
bool js_register_cocos2d_middleware_MiddlewareManager(se::Object* obj);
|
||||
bool register_all_cocos2dx_editor_support(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_render);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_update);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_destroyInstance);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_generateModuleID);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getInstance);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_MiddlewareManager);
|
||||
|
||||
#endif //#if USE_MIDDLEWARE > 0
|
||||
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_extension_EventAssetsManagerEx_proto;
|
||||
extern se::Class* __jsb_cocos2d_extension_EventAssetsManagerEx_class;
|
||||
|
||||
bool js_register_cocos2d_extension_EventAssetsManagerEx(se::Object* obj);
|
||||
bool register_all_extension(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getAssetsManagerEx);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getDownloadedFiles);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getTotalFiles);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getAssetId);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getTotalBytes);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getCURLECode);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getMessage);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getCURLMCode);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getDownloadedBytes);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getPercentByFile);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getEventCode);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_getPercent);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_isResuming);
|
||||
SE_DECLARE_FUNC(js_extension_EventAssetsManagerEx_EventAssetsManagerEx);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_extension_Manifest_proto;
|
||||
extern se::Class* __jsb_cocos2d_extension_Manifest_class;
|
||||
|
||||
bool js_register_cocos2d_extension_Manifest(se::Object* obj);
|
||||
bool register_all_extension(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_getManifestRoot);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_setUpdating);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_getManifestFileUrl);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_isVersionLoaded);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_parseFile);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_isLoaded);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_getPackageUrl);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_isUpdating);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_getVersion);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_parseJSONString);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_getVersionFileUrl);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_getSearchPaths);
|
||||
SE_DECLARE_FUNC(js_extension_Manifest_Manifest);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_extension_AssetsManagerEx_proto;
|
||||
extern se::Class* __jsb_cocos2d_extension_AssetsManagerEx_class;
|
||||
|
||||
bool js_register_cocos2d_extension_AssetsManagerEx(se::Object* obj);
|
||||
bool register_all_extension(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getDownloadedFiles);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_setEventCallback);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_downloadFailedAssets);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getTotalFiles);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_checkUpdate);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_loadLocalManifest);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_setMaxConcurrentTask);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getLocalManifest);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getRemoteManifest);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_cancelUpdate);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_isResuming);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getState);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getMaxConcurrentTask);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_setVersionCompareHandle);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getTotalBytes);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_setVerifyCallback);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getStoragePath);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_update);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_getDownloadedBytes);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_prepareUpdate);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_loadRemoteManifest);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_create);
|
||||
SE_DECLARE_FUNC(js_extension_AssetsManagerEx_AssetsManagerEx);
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
#include "scripting/js-bindings/auto/jsb_cocos2dx_network_auto.hpp"
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
|
||||
#include "scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "network/CCDownloader.h"
|
||||
|
||||
se::Object* __jsb_cocos2d_network_Downloader_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_network_Downloader_class = nullptr;
|
||||
|
||||
static bool js_network_Downloader_setOnTaskProgress(se::State& s)
|
||||
{
|
||||
cocos2d::network::Downloader* cobj = (cocos2d::network::Downloader*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_network_Downloader_setOnTaskProgress : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<void (const cocos2d::network::DownloadTask &, long long, long long, long long)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](const cocos2d::network::DownloadTask & larg0, long long larg1, long long larg2, long long larg3) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(4);
|
||||
ok &= DownloadTask_to_seval(larg0, &args[0]);
|
||||
ok &= longlong_to_seval(larg1, &args[1]);
|
||||
ok &= longlong_to_seval(larg2, &args[2]);
|
||||
ok &= longlong_to_seval(larg3, &args[3]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_network_Downloader_setOnTaskProgress : Error processing arguments");
|
||||
cobj->setOnTaskProgress(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_network_Downloader_setOnTaskProgress)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cocos2d_network_Downloader_finalize)
|
||||
|
||||
static bool js_network_Downloader_constructor(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
do {
|
||||
if (argc == 1) {
|
||||
cocos2d::network::DownloaderHints arg0;
|
||||
ok &= seval_to_DownloaderHints(args[0], &arg0);
|
||||
if (!ok) { ok = true; break; }
|
||||
cocos2d::network::Downloader* cobj = new (std::nothrow) cocos2d::network::Downloader(arg0);
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
} while(false);
|
||||
do {
|
||||
if (argc == 0) {
|
||||
cocos2d::network::Downloader* cobj = new (std::nothrow) cocos2d::network::Downloader();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
|
||||
return true;
|
||||
}
|
||||
} while(false);
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_CTOR(js_network_Downloader_constructor, __jsb_cocos2d_network_Downloader_class, js_cocos2d_network_Downloader_finalize)
|
||||
|
||||
|
||||
|
||||
|
||||
static bool js_cocos2d_network_Downloader_finalize(se::State& s)
|
||||
{
|
||||
CCLOGINFO("jsbindings: finalizing JS object %p (cocos2d::network::Downloader)", s.nativeThisObject());
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
|
||||
{
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
cocos2d::network::Downloader* cobj = (cocos2d::network::Downloader*)s.nativeThisObject();
|
||||
delete cobj;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_cocos2d_network_Downloader_finalize)
|
||||
|
||||
bool js_register_network_Downloader(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("Downloader", obj, nullptr, _SE(js_network_Downloader_constructor));
|
||||
|
||||
cls->defineFunction("setOnTaskProgress", _SE(js_network_Downloader_setOnTaskProgress));
|
||||
cls->defineFinalizeFunction(_SE(js_cocos2d_network_Downloader_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::network::Downloader>(cls);
|
||||
|
||||
__jsb_cocos2d_network_Downloader_proto = cls->getProto();
|
||||
__jsb_cocos2d_network_Downloader_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool register_all_network(se::Object* obj)
|
||||
{
|
||||
// Get the ns
|
||||
se::Value nsVal;
|
||||
if (!obj->getProperty("jsb", &nsVal))
|
||||
{
|
||||
se::HandleObject jsobj(se::Object::createPlainObject());
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("jsb", nsVal);
|
||||
}
|
||||
se::Object* ns = nsVal.toObject();
|
||||
|
||||
js_register_network_Downloader(ns);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_network_Downloader_proto;
|
||||
extern se::Class* __jsb_cocos2d_network_Downloader_class;
|
||||
|
||||
bool js_register_cocos2d_network_Downloader(se::Object* obj);
|
||||
bool register_all_network(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_network_Downloader_setOnTaskProgress);
|
||||
SE_DECLARE_FUNC(js_network_Downloader_Downloader);
|
||||
|
||||
#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if USE_PARTICLE > 0
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_ParticleSimulator_proto;
|
||||
extern se::Class* __jsb_cocos2d_ParticleSimulator_class;
|
||||
|
||||
bool js_register_cocos2d_ParticleSimulator(se::Object* obj);
|
||||
bool register_all_cocos2dx_particle(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setGravity);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_render);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setSourcePos);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_onEnable);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setEffect);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setPosVar);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setEndColorVar);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_getParticleCount);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setStartColorVar);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_emitParticle);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_stop);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_update);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_active);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_updateUVs);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setStartColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_reset);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_onDisable);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_bindNodeProxy);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setEndColor);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setFinishedCallback);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_setStopCallback);
|
||||
SE_DECLARE_FUNC(js_cocos2dx_particle_ParticleSimulator_ParticleSimulator);
|
||||
|
||||
#endif //#if USE_PARTICLE > 0
|
||||
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_GraphicsHandle_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_GraphicsHandle_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_GraphicsHandle(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_GraphicsHandle_getHandle);
|
||||
SE_DECLARE_FUNC(js_gfx_GraphicsHandle_GraphicsHandle);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_IndexBuffer_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_IndexBuffer_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_IndexBuffer(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_getUsage);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_setFormat);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_setCount);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_setUsage);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_getCount);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_setBytesPerIndex);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_getBytes);
|
||||
SE_DECLARE_FUNC(js_gfx_IndexBuffer_IndexBuffer);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_VertexBuffer_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_VertexBuffer_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_VertexBuffer(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_getUsage);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_setCount);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_setUsage);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_getCount);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_getBytes);
|
||||
SE_DECLARE_FUNC(js_gfx_VertexBuffer_VertexBuffer);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_DeviceGraphics_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_DeviceGraphics_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_DeviceGraphics(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setBlendFuncSeparate);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_enableBlend);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setPrimitiveType);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setBlendEquationSeparate);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setIndexBuffer);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setProgram);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setFrameBuffer);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setStencilFunc);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setBlendColor);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setScissor);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setVertexBuffer);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_enableDepthWrite);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_getCapacity);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setStencilOpBack);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setViewport);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_draw);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setDepthFunc);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_enableDepthTest);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_resetDrawCalls);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_getDrawCalls);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setBlendEquation);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setStencilFuncFront);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setStencilOpFront);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setStencilFuncBack);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setBlendFunc);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setCullMode);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_setStencilOp);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_enableStencilTest);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_DeviceGraphics_getInstance);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_FrameBuffer_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_FrameBuffer_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_FrameBuffer(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_FrameBuffer_getHeight);
|
||||
SE_DECLARE_FUNC(js_gfx_FrameBuffer_getWidth);
|
||||
SE_DECLARE_FUNC(js_gfx_FrameBuffer_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_FrameBuffer_FrameBuffer);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_RenderTarget_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_RenderTarget_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_RenderTarget(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_RenderBuffer_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_RenderBuffer_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_RenderBuffer(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderBuffer_init);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderBuffer_update);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderBuffer_create);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderBuffer_RenderBuffer);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Texture_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Texture_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Texture(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture_getWidth);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture_setAlphaAtlas);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture_getHeight);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture_isAlphaAtlas);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture_getTarget);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Texture2D_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Texture2D_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Texture2D(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture2D_updateImage);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture2D_init);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture2D_updateSubImage);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture2D_update);
|
||||
SE_DECLARE_FUNC(js_gfx_Texture2D_Texture2D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Program_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Program_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Program(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Program_getID);
|
||||
SE_DECLARE_FUNC(js_gfx_Program_init);
|
||||
SE_DECLARE_FUNC(js_gfx_Program_link);
|
||||
SE_DECLARE_FUNC(js_gfx_Program_Program);
|
||||
|
||||
#endif //#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
@@ -0,0 +1,347 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_ProgramLib_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_ProgramLib_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_ProgramLib(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_ProgramLib_define);
|
||||
SE_DECLARE_FUNC(js_renderer_ProgramLib_ProgramLib);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_EffectBase_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_EffectBase_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_EffectBase(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_getProperty);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_setStencilTest);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_getDefine);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_setCullMode);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_setBlend);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_setStencil);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_getPasses);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_setDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectBase_define);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Effect_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Effect_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Effect(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_Effect_clear);
|
||||
SE_DECLARE_FUNC(js_renderer_Effect_switchTechnique);
|
||||
SE_DECLARE_FUNC(js_renderer_Effect_copy);
|
||||
SE_DECLARE_FUNC(js_renderer_Effect_Effect);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_EffectVariant_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_EffectVariant_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_EffectVariant(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectVariant_setEffect);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectVariant_updateHash);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectVariant_copy);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectVariant_getEffect);
|
||||
SE_DECLARE_FUNC(js_renderer_EffectVariant_EffectVariant);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_AssemblerBase_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_AssemblerBase_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_AssemblerBase(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerBase_disableDirty);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerBase_reset);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerBase_setUseModel);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerBase_isDirty);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerBase_setDirty);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerBase_AssemblerBase);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_MemPool_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_MemPool_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_MemPool(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_MemPool_removeCommonData);
|
||||
SE_DECLARE_FUNC(js_renderer_MemPool_updateCommonData);
|
||||
SE_DECLARE_FUNC(js_renderer_MemPool_MemPool);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_NodeProxy_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_NodeProxy_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_NodeProxy(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_disableVisit);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_switchTraverseToRender);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_notifyUpdateParent);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_destroyImmediately);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_isValid);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_enableVisit);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_getLocalMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_setName);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_clearAssembler);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_switchTraverseToVisit);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_setAssembler);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeProxy_NodeProxy);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_BaseRenderer_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_BaseRenderer_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_BaseRenderer(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_BaseRenderer_getProgramLib);
|
||||
SE_DECLARE_FUNC(js_renderer_BaseRenderer_init);
|
||||
SE_DECLARE_FUNC(js_renderer_BaseRenderer_BaseRenderer);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_View_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_View_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_View(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_View_View);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Camera_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Camera_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Camera(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setFov);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getFrameBuffer);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setStencil);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setPriority);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getOrthoHeight);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setCullingMask);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getStencil);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setType);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getPriority);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setFar);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setFrameBuffer);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setRect);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setClearFlags);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getFar);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getType);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getCullingMask);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setNear);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setStages);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setOrthoHeight);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getStages);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getFov);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setColor);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_setWorldMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getNear);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_getClearFlags);
|
||||
SE_DECLARE_FUNC(js_renderer_Camera_Camera);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_ForwardRenderer_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_ForwardRenderer_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_ForwardRenderer(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_ForwardRenderer_renderCamera);
|
||||
SE_DECLARE_FUNC(js_renderer_ForwardRenderer_init);
|
||||
SE_DECLARE_FUNC(js_renderer_ForwardRenderer_render);
|
||||
SE_DECLARE_FUNC(js_renderer_ForwardRenderer_ForwardRenderer);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Light_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Light_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Light(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getRange);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowFrustumSize);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowResolution);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getFrustumEdgeFalloff);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setSpotExp);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowType);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setType);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getViewProjMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getPositionUniform);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowBias);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowDarkness);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getSpotAngle);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getDirectionUniform);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getSpotExp);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowDepthScale);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getViewPorjMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getSpotAngleUniform);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getType);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getColorUniform);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getIntensity);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowMaxDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getWorldMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowMap);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getColor);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setIntensity);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowMinDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowMinDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_update);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowDarkness);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setWorldMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setSpotAngle);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setRange);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setColor);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowMaxDepth);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setFrustumEdgeFalloff);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowResolution);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowDepthScale);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_getShadowType);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_setShadowBias);
|
||||
SE_DECLARE_FUNC(js_renderer_Light_Light);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Scene_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Scene_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Scene(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_getCameraCount);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_removeCamera);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_getLightCount);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_removeView);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_getLights);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_removeLight);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_addCamera);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_getLight);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_addLight);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_getCameras);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_sortCameras);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_setDebugCamera);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_reset);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_getCamera);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_addView);
|
||||
SE_DECLARE_FUNC(js_renderer_Scene_Scene);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_NodeMemPool_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_NodeMemPool_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_NodeMemPool(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeMemPool_removeNodeData);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeMemPool_updateNodeData);
|
||||
SE_DECLARE_FUNC(js_renderer_NodeMemPool_NodeMemPool);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_RenderDataList_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_RenderDataList_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_RenderDataList(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_RenderDataList_updateMesh);
|
||||
SE_DECLARE_FUNC(js_renderer_RenderDataList_clear);
|
||||
SE_DECLARE_FUNC(js_renderer_RenderDataList_RenderDataList);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Assembler_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Assembler_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Assembler(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_setVertexFormat);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_isIgnoreOpacityFlag);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_ignoreWorldMatrix);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_updateVerticesRange);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_setRenderDataList);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_updateMeshIndex);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_updateEffect);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_updateIndicesRange);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_ignoreOpacityFlag);
|
||||
SE_DECLARE_FUNC(js_renderer_Assembler_Assembler);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_CustomAssembler_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_CustomAssembler_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_CustomAssembler(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_CustomAssembler_clearEffect);
|
||||
SE_DECLARE_FUNC(js_renderer_CustomAssembler_updateEffect);
|
||||
SE_DECLARE_FUNC(js_renderer_CustomAssembler_updateIABuffer);
|
||||
SE_DECLARE_FUNC(js_renderer_CustomAssembler_CustomAssembler);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_RenderFlow_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_RenderFlow_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_RenderFlow(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_RenderFlow_render);
|
||||
SE_DECLARE_FUNC(js_renderer_RenderFlow_RenderFlow);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_AssemblerSprite_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_AssemblerSprite_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_AssemblerSprite(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerSprite_setLocalData);
|
||||
SE_DECLARE_FUNC(js_renderer_AssemblerSprite_AssemblerSprite);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_SimpleSprite2D_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_SimpleSprite2D_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_SimpleSprite2D(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_SimpleSprite2D_SimpleSprite2D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_MaskAssembler_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_MaskAssembler_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_MaskAssembler(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_MaskAssembler_setMaskInverted);
|
||||
SE_DECLARE_FUNC(js_renderer_MaskAssembler_setImageStencil);
|
||||
SE_DECLARE_FUNC(js_renderer_MaskAssembler_setClearSubHandle);
|
||||
SE_DECLARE_FUNC(js_renderer_MaskAssembler_getMaskInverted);
|
||||
SE_DECLARE_FUNC(js_renderer_MaskAssembler_setRenderSubHandle);
|
||||
SE_DECLARE_FUNC(js_renderer_MaskAssembler_MaskAssembler);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_TiledMapAssembler_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_TiledMapAssembler_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_TiledMapAssembler(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_TiledMapAssembler_updateNodes);
|
||||
SE_DECLARE_FUNC(js_renderer_TiledMapAssembler_clearNodes);
|
||||
SE_DECLARE_FUNC(js_renderer_TiledMapAssembler_TiledMapAssembler);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_SlicedSprite2D_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_SlicedSprite2D_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_SlicedSprite2D(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_SlicedSprite2D_SlicedSprite2D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_MeshAssembler_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_MeshAssembler_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_MeshAssembler(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_MeshAssembler_setNode);
|
||||
SE_DECLARE_FUNC(js_renderer_MeshAssembler_updateIAData);
|
||||
SE_DECLARE_FUNC(js_renderer_MeshAssembler_MeshAssembler);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_SimpleSprite3D_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_SimpleSprite3D_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_SimpleSprite3D(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_SimpleSprite3D_SimpleSprite3D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_SlicedSprite3D_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_SlicedSprite3D_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_SlicedSprite3D(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_SlicedSprite3D_SlicedSprite3D);
|
||||
|
||||
extern se::Object* __jsb_cocos2d_renderer_Particle3DAssembler_proto;
|
||||
extern se::Class* __jsb_cocos2d_renderer_Particle3DAssembler_class;
|
||||
|
||||
bool js_register_cocos2d_renderer_Particle3DAssembler(se::Object* obj);
|
||||
bool register_all_renderer(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_renderer_Particle3DAssembler_setTrailSpace);
|
||||
SE_DECLARE_FUNC(js_renderer_Particle3DAssembler_setTrailVertexFormat);
|
||||
SE_DECLARE_FUNC(js_renderer_Particle3DAssembler_setParticleSpace);
|
||||
SE_DECLARE_FUNC(js_renderer_Particle3DAssembler_setTrailModuleEnable);
|
||||
SE_DECLARE_FUNC(js_renderer_Particle3DAssembler_Particle3DAssembler);
|
||||
|
||||
#endif //#if (USE_GFX_RENDERER > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
@@ -0,0 +1,522 @@
|
||||
#include "scripting/js-bindings/auto/jsb_video_auto.hpp"
|
||||
#if (USE_VIDEO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
|
||||
#include "scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "ui/videoplayer/VideoPlayer.h"
|
||||
|
||||
se::Object* __jsb_cocos2d_VideoPlayer_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_VideoPlayer_class = nullptr;
|
||||
|
||||
static bool js_video_VideoPlayer_setFullScreenEnabled(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_setFullScreenEnabled : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_setFullScreenEnabled : Error processing arguments");
|
||||
cobj->setFullScreenEnabled(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_setFullScreenEnabled)
|
||||
|
||||
static bool js_video_VideoPlayer_getFrameWidth(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_getFrameWidth : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getFrameWidth();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_getFrameWidth : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_getFrameWidth)
|
||||
|
||||
static bool js_video_VideoPlayer_duration(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_duration : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
float result = cobj->duration();
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_duration : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_duration)
|
||||
|
||||
static bool js_video_VideoPlayer_pause(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_pause : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->pause();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_pause)
|
||||
|
||||
static bool js_video_VideoPlayer_getFrame(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_getFrame : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->getFrame();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_getFrame)
|
||||
|
||||
static bool js_video_VideoPlayer_setShowRawFrame(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_setShowRawFrame : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_setShowRawFrame : Error processing arguments");
|
||||
cobj->setShowRawFrame(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_setShowRawFrame)
|
||||
|
||||
static bool js_video_VideoPlayer_onPlayEvent(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_onPlayEvent : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
int arg0 = 0;
|
||||
do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_onPlayEvent : Error processing arguments");
|
||||
cobj->onPlayEvent(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_onPlayEvent)
|
||||
|
||||
static bool js_video_VideoPlayer_addEventListener(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_addEventListener : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
std::string arg0;
|
||||
std::function<void ()> arg1;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
do {
|
||||
if (args[1].isObject() && args[1].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[1]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=]() -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(se::EmptyValueArray, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg1 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg1 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_addEventListener : Error processing arguments");
|
||||
cobj->addEventListener(arg0, arg1);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_addEventListener)
|
||||
|
||||
static bool js_video_VideoPlayer_seekTo(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_seekTo : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
float arg0 = 0;
|
||||
ok &= seval_to_float(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_seekTo : Error processing arguments");
|
||||
cobj->seekTo(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_seekTo)
|
||||
|
||||
static bool js_video_VideoPlayer_play(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_play : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->play();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_play)
|
||||
|
||||
static bool js_video_VideoPlayer_getFrameHeight(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_getFrameHeight : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getFrameHeight();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_getFrameHeight : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_getFrameHeight)
|
||||
|
||||
static bool js_video_VideoPlayer_stop(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_stop : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->stop();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_stop)
|
||||
|
||||
static bool js_video_VideoPlayer_setURL(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_setURL : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_setURL : Error processing arguments");
|
||||
cobj->setURL(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_setURL)
|
||||
|
||||
static bool js_video_VideoPlayer_update(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_update : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->update();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_update)
|
||||
|
||||
static bool js_video_VideoPlayer_pushFrameDataToTexture2D(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_pushFrameDataToTexture2D : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
cocos2d::renderer::Texture* arg0 = nullptr;
|
||||
ok &= seval_to_native_ptr(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_pushFrameDataToTexture2D : Error processing arguments");
|
||||
cobj->pushFrameDataToTexture2D(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_pushFrameDataToTexture2D)
|
||||
|
||||
static bool js_video_VideoPlayer_isKeepAspectRatioEnabled(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_isKeepAspectRatioEnabled : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
bool result = cobj->isKeepAspectRatioEnabled();
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_isKeepAspectRatioEnabled : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_isKeepAspectRatioEnabled)
|
||||
|
||||
static bool js_video_VideoPlayer_getFrameChannel(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_getFrameChannel : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getFrameChannel();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_getFrameChannel : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_getFrameChannel)
|
||||
|
||||
static bool js_video_VideoPlayer_getVideoTexDataSize(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_getVideoTexDataSize : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
int result = cobj->getVideoTexDataSize();
|
||||
ok &= int32_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_getVideoTexDataSize : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_getVideoTexDataSize)
|
||||
|
||||
static bool js_video_VideoPlayer_setKeepAspectRatioEnabled(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_setKeepAspectRatioEnabled : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_setKeepAspectRatioEnabled : Error processing arguments");
|
||||
cobj->setKeepAspectRatioEnabled(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_setKeepAspectRatioEnabled)
|
||||
|
||||
static bool js_video_VideoPlayer_currentTime(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_currentTime : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
float result = cobj->currentTime();
|
||||
ok &= float_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_currentTime : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_currentTime)
|
||||
|
||||
static bool js_video_VideoPlayer_setFrame(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_setFrame : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 4) {
|
||||
float arg0 = 0;
|
||||
float arg1 = 0;
|
||||
float arg2 = 0;
|
||||
float arg3 = 0;
|
||||
ok &= seval_to_float(args[0], &arg0);
|
||||
ok &= seval_to_float(args[1], &arg1);
|
||||
ok &= seval_to_float(args[2], &arg2);
|
||||
ok &= seval_to_float(args[3], &arg3);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_setFrame : Error processing arguments");
|
||||
cobj->setFrame(arg0, arg1, arg2, arg3);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_setFrame)
|
||||
|
||||
static bool js_video_VideoPlayer_setVisible(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_video_VideoPlayer_setVisible : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_video_VideoPlayer_setVisible : Error processing arguments");
|
||||
cobj->setVisible(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_video_VideoPlayer_setVisible)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cocos2d_VideoPlayer_finalize)
|
||||
|
||||
static bool js_video_VideoPlayer_constructor(se::State& s)
|
||||
{
|
||||
cocos2d::VideoPlayer* cobj = new (std::nothrow) cocos2d::VideoPlayer();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_video_VideoPlayer_constructor, __jsb_cocos2d_VideoPlayer_class, js_cocos2d_VideoPlayer_finalize)
|
||||
|
||||
|
||||
|
||||
|
||||
static bool js_cocos2d_VideoPlayer_finalize(se::State& s)
|
||||
{
|
||||
// destructor is skipped
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_cocos2d_VideoPlayer_finalize)
|
||||
|
||||
static bool js_cocos2d_VideoPlayer_destroy(se::State& s)
|
||||
{
|
||||
CCLOGINFO("jsbindings: destory JS object %p (cocos2d::VideoPlayer)", s.nativeThisObject());
|
||||
cocos2d::VideoPlayer* cobj = (cocos2d::VideoPlayer*)s.nativeThisObject();
|
||||
cobj->release();
|
||||
auto objIter = se::NativePtrToObjectMap::find(s.nativeThisObject());
|
||||
if(objIter != se::NativePtrToObjectMap::end())
|
||||
{
|
||||
objIter->second->clearPrivateData(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2d_VideoPlayer_destroy)
|
||||
|
||||
bool js_register_video_VideoPlayer(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("VideoPlayer", obj, nullptr, _SE(js_video_VideoPlayer_constructor));
|
||||
|
||||
cls->defineFunction("setFullScreenEnabled", _SE(js_video_VideoPlayer_setFullScreenEnabled));
|
||||
cls->defineFunction("getFrameWidth", _SE(js_video_VideoPlayer_getFrameWidth));
|
||||
cls->defineFunction("duration", _SE(js_video_VideoPlayer_duration));
|
||||
cls->defineFunction("pause", _SE(js_video_VideoPlayer_pause));
|
||||
cls->defineFunction("getFrame", _SE(js_video_VideoPlayer_getFrame));
|
||||
cls->defineFunction("setShowRawFrame", _SE(js_video_VideoPlayer_setShowRawFrame));
|
||||
cls->defineFunction("onPlayEvent", _SE(js_video_VideoPlayer_onPlayEvent));
|
||||
cls->defineFunction("addEventListener", _SE(js_video_VideoPlayer_addEventListener));
|
||||
cls->defineFunction("seekTo", _SE(js_video_VideoPlayer_seekTo));
|
||||
cls->defineFunction("play", _SE(js_video_VideoPlayer_play));
|
||||
cls->defineFunction("getFrameHeight", _SE(js_video_VideoPlayer_getFrameHeight));
|
||||
cls->defineFunction("stop", _SE(js_video_VideoPlayer_stop));
|
||||
cls->defineFunction("setURL", _SE(js_video_VideoPlayer_setURL));
|
||||
cls->defineFunction("update", _SE(js_video_VideoPlayer_update));
|
||||
cls->defineFunction("pushFrameDataToTexture2D", _SE(js_video_VideoPlayer_pushFrameDataToTexture2D));
|
||||
cls->defineFunction("isKeepAspectRatioEnabled", _SE(js_video_VideoPlayer_isKeepAspectRatioEnabled));
|
||||
cls->defineFunction("getFrameChannel", _SE(js_video_VideoPlayer_getFrameChannel));
|
||||
cls->defineFunction("getVideoTexDataSize", _SE(js_video_VideoPlayer_getVideoTexDataSize));
|
||||
cls->defineFunction("setKeepAspectRatioEnabled", _SE(js_video_VideoPlayer_setKeepAspectRatioEnabled));
|
||||
cls->defineFunction("currentTime", _SE(js_video_VideoPlayer_currentTime));
|
||||
cls->defineFunction("setFrame", _SE(js_video_VideoPlayer_setFrame));
|
||||
cls->defineFunction("setVisible", _SE(js_video_VideoPlayer_setVisible));
|
||||
cls->defineFunction("destroy", _SE(js_cocos2d_VideoPlayer_destroy));
|
||||
cls->defineFinalizeFunction(_SE(js_cocos2d_VideoPlayer_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::VideoPlayer>(cls);
|
||||
|
||||
__jsb_cocos2d_VideoPlayer_proto = cls->getProto();
|
||||
__jsb_cocos2d_VideoPlayer_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool register_all_video(se::Object* obj)
|
||||
{
|
||||
// Get the ns
|
||||
se::Value nsVal;
|
||||
if (!obj->getProperty("jsb", &nsVal))
|
||||
{
|
||||
se::HandleObject jsobj(se::Object::createPlainObject());
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("jsb", nsVal);
|
||||
}
|
||||
se::Object* ns = nsVal.toObject();
|
||||
|
||||
js_register_video_VideoPlayer(ns);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //#if (USE_VIDEO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if (USE_VIDEO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_VideoPlayer_proto;
|
||||
extern se::Class* __jsb_cocos2d_VideoPlayer_class;
|
||||
|
||||
bool js_register_cocos2d_VideoPlayer(se::Object* obj);
|
||||
bool register_all_video(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_setFullScreenEnabled);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_getFrameWidth);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_duration);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_pause);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_getFrame);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_setShowRawFrame);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_onPlayEvent);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_addEventListener);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_seekTo);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_play);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_getFrameHeight);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_stop);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_setURL);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_update);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_pushFrameDataToTexture2D);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_isKeepAspectRatioEnabled);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_getFrameChannel);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_getVideoTexDataSize);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_setKeepAspectRatioEnabled);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_currentTime);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_setFrame);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_setVisible);
|
||||
SE_DECLARE_FUNC(js_video_VideoPlayer_VideoPlayer);
|
||||
|
||||
#endif //#if (USE_VIDEO > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
@@ -0,0 +1,718 @@
|
||||
#include "scripting/js-bindings/auto/jsb_webview_auto.hpp"
|
||||
#if (USE_WEB_VIEW > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
|
||||
#include "scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "ui/webview/WebView.h"
|
||||
|
||||
se::Object* __jsb_cocos2d_WebView_proto = nullptr;
|
||||
se::Class* __jsb_cocos2d_WebView_class = nullptr;
|
||||
|
||||
static bool js_webview_WebView_setOnShouldStartLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setOnShouldStartLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<bool (cocos2d::WebView *, const std::string&)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](cocos2d::WebView* larg0, const std::string& larg1) -> bool {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(2);
|
||||
ok &= native_ptr_to_seval<cocos2d::WebView>((cocos2d::WebView*)larg0, &args[0]);
|
||||
ok &= std_string_to_seval(larg1, &args[1]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
bool result;
|
||||
ok &= seval_to_boolean(rval, &result);
|
||||
SE_PRECONDITION2(ok, result, "lambda function : Error processing return value with type bool");
|
||||
return result;
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setOnShouldStartLoading : Error processing arguments");
|
||||
cobj->setOnShouldStartLoading(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setOnShouldStartLoading)
|
||||
|
||||
static bool js_webview_WebView_setOnDidFailLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setOnDidFailLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<void (cocos2d::WebView *, const std::string&)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](cocos2d::WebView* larg0, const std::string& larg1) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(2);
|
||||
ok &= native_ptr_to_seval<cocos2d::WebView>((cocos2d::WebView*)larg0, &args[0]);
|
||||
ok &= std_string_to_seval(larg1, &args[1]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setOnDidFailLoading : Error processing arguments");
|
||||
cobj->setOnDidFailLoading(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setOnDidFailLoading)
|
||||
|
||||
static bool js_webview_WebView_canGoBack(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_canGoBack : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
bool result = cobj->canGoBack();
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_canGoBack : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_canGoBack)
|
||||
|
||||
static bool js_webview_WebView_loadHTMLString(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_loadHTMLString : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_loadHTMLString : Error processing arguments");
|
||||
cobj->loadHTMLString(arg0);
|
||||
return true;
|
||||
}
|
||||
if (argc == 2) {
|
||||
std::string arg0;
|
||||
std::string arg1;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
ok &= seval_to_std_string(args[1], &arg1);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_loadHTMLString : Error processing arguments");
|
||||
cobj->loadHTMLString(arg0, arg1);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_loadHTMLString)
|
||||
|
||||
static bool js_webview_WebView_goForward(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_goForward : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->goForward();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_goForward)
|
||||
|
||||
static bool js_webview_WebView_goBack(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_goBack : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->goBack();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_goBack)
|
||||
|
||||
static bool js_webview_WebView_setScalesPageToFit(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setScalesPageToFit : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setScalesPageToFit : Error processing arguments");
|
||||
cobj->setScalesPageToFit(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setScalesPageToFit)
|
||||
|
||||
static bool js_webview_WebView_getOnDidFailLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_getOnDidFailLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
cocos2d::WebView::ccWebViewCallback result = cobj->getOnDidFailLoading();
|
||||
#pragma warning NO CONVERSION FROM NATIVE FOR std::function;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_getOnDidFailLoading : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_getOnDidFailLoading)
|
||||
|
||||
static bool js_webview_WebView_loadFile(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_loadFile : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_loadFile : Error processing arguments");
|
||||
cobj->loadFile(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_loadFile)
|
||||
|
||||
static bool js_webview_WebView_loadURL(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_loadURL : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_loadURL : Error processing arguments");
|
||||
cobj->loadURL(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_loadURL)
|
||||
|
||||
static bool js_webview_WebView_setBounces(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setBounces : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setBounces : Error processing arguments");
|
||||
cobj->setBounces(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setBounces)
|
||||
|
||||
static bool js_webview_WebView_evaluateJS(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_evaluateJS : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_evaluateJS : Error processing arguments");
|
||||
cobj->evaluateJS(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_evaluateJS)
|
||||
|
||||
static bool js_webview_WebView_setOnJSCallback(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setOnJSCallback : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<void (cocos2d::WebView *, const std::string&)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](cocos2d::WebView* larg0, const std::string& larg1) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(2);
|
||||
ok &= native_ptr_to_seval<cocos2d::WebView>((cocos2d::WebView*)larg0, &args[0]);
|
||||
ok &= std_string_to_seval(larg1, &args[1]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setOnJSCallback : Error processing arguments");
|
||||
cobj->setOnJSCallback(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setOnJSCallback)
|
||||
|
||||
static bool js_webview_WebView_setBackgroundTransparent(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setBackgroundTransparent : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setBackgroundTransparent : Error processing arguments");
|
||||
cobj->setBackgroundTransparent(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setBackgroundTransparent)
|
||||
|
||||
static bool js_webview_WebView_getOnJSCallback(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_getOnJSCallback : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
cocos2d::WebView::ccWebViewCallback result = cobj->getOnJSCallback();
|
||||
#pragma warning NO CONVERSION FROM NATIVE FOR std::function;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_getOnJSCallback : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_getOnJSCallback)
|
||||
|
||||
static bool js_webview_WebView_canGoForward(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_canGoForward : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
bool result = cobj->canGoForward();
|
||||
ok &= boolean_to_seval(result, &s.rval());
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_canGoForward : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_canGoForward)
|
||||
|
||||
static bool js_webview_WebView_getOnShouldStartLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_getOnShouldStartLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
std::function<bool (cocos2d::WebView *, const std::string&)> result = cobj->getOnShouldStartLoading();
|
||||
#pragma warning NO CONVERSION FROM NATIVE FOR std::function;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_getOnShouldStartLoading : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_getOnShouldStartLoading)
|
||||
|
||||
static bool js_webview_WebView_stopLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_stopLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->stopLoading();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_stopLoading)
|
||||
|
||||
static bool js_webview_WebView_setFrame(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setFrame : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 4) {
|
||||
float arg0 = 0;
|
||||
float arg1 = 0;
|
||||
float arg2 = 0;
|
||||
float arg3 = 0;
|
||||
ok &= seval_to_float(args[0], &arg0);
|
||||
ok &= seval_to_float(args[1], &arg1);
|
||||
ok &= seval_to_float(args[2], &arg2);
|
||||
ok &= seval_to_float(args[3], &arg3);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setFrame : Error processing arguments");
|
||||
cobj->setFrame(arg0, arg1, arg2, arg3);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setFrame)
|
||||
|
||||
static bool js_webview_WebView_setVisible(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setVisible : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setVisible : Error processing arguments");
|
||||
cobj->setVisible(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setVisible)
|
||||
|
||||
static bool js_webview_WebView_reload(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_reload : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 0) {
|
||||
cobj->reload();
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_reload)
|
||||
|
||||
static bool js_webview_WebView_loadData(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_loadData : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 4) {
|
||||
cocos2d::Data arg0;
|
||||
std::string arg1;
|
||||
std::string arg2;
|
||||
std::string arg3;
|
||||
ok &= seval_to_Data(args[0], &arg0);
|
||||
ok &= seval_to_std_string(args[1], &arg1);
|
||||
ok &= seval_to_std_string(args[2], &arg2);
|
||||
ok &= seval_to_std_string(args[3], &arg3);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_loadData : Error processing arguments");
|
||||
cobj->loadData(arg0, arg1, arg2, arg3);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_loadData)
|
||||
|
||||
static bool js_webview_WebView_setJavascriptInterfaceScheme(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setJavascriptInterfaceScheme : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::string arg0;
|
||||
ok &= seval_to_std_string(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setJavascriptInterfaceScheme : Error processing arguments");
|
||||
cobj->setJavascriptInterfaceScheme(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setJavascriptInterfaceScheme)
|
||||
|
||||
static bool js_webview_WebView_setOnDidFinishLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_setOnDidFinishLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<void (cocos2d::WebView *, const std::string&)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](cocos2d::WebView* larg0, const std::string& larg1) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(2);
|
||||
ok &= native_ptr_to_seval<cocos2d::WebView>((cocos2d::WebView*)larg0, &args[0]);
|
||||
ok &= std_string_to_seval(larg1, &args[1]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_setOnDidFinishLoading : Error processing arguments");
|
||||
cobj->setOnDidFinishLoading(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_setOnDidFinishLoading)
|
||||
|
||||
static bool js_webview_WebView_getOnDidFinishLoading(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_webview_WebView_getOnDidFinishLoading : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
cocos2d::WebView::ccWebViewCallback result = cobj->getOnDidFinishLoading();
|
||||
#pragma warning NO CONVERSION FROM NATIVE FOR std::function;
|
||||
SE_PRECONDITION2(ok, false, "js_webview_WebView_getOnDidFinishLoading : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_getOnDidFinishLoading)
|
||||
|
||||
static bool js_webview_WebView_create(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
auto result = cocos2d::WebView::create();
|
||||
result->retain();
|
||||
auto obj = se::Object::createObjectWithClass(__jsb_cocos2d_WebView_class);
|
||||
obj->setPrivateData(result);
|
||||
s.rval().setObject(obj);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_webview_WebView_create)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cocos2d_WebView_finalize)
|
||||
|
||||
static bool js_webview_WebView_constructor(se::State& s)
|
||||
{
|
||||
cocos2d::WebView* cobj = new (std::nothrow) cocos2d::WebView();
|
||||
s.thisObject()->setPrivateData(cobj);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_CTOR(js_webview_WebView_constructor, __jsb_cocos2d_WebView_class, js_cocos2d_WebView_finalize)
|
||||
|
||||
|
||||
|
||||
|
||||
static bool js_cocos2d_WebView_finalize(se::State& s)
|
||||
{
|
||||
// destructor is skipped
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(js_cocos2d_WebView_finalize)
|
||||
|
||||
static bool js_cocos2d_WebView_destroy(se::State& s)
|
||||
{
|
||||
CCLOGINFO("jsbindings: destory JS object %p (cocos2d::WebView)", s.nativeThisObject());
|
||||
cocos2d::WebView* cobj = (cocos2d::WebView*)s.nativeThisObject();
|
||||
cobj->release();
|
||||
auto objIter = se::NativePtrToObjectMap::find(s.nativeThisObject());
|
||||
if(objIter != se::NativePtrToObjectMap::end())
|
||||
{
|
||||
objIter->second->clearPrivateData(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_cocos2d_WebView_destroy)
|
||||
|
||||
bool js_register_webview_WebView(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("WebView", obj, nullptr, _SE(js_webview_WebView_constructor));
|
||||
|
||||
cls->defineFunction("setOnShouldStartLoading", _SE(js_webview_WebView_setOnShouldStartLoading));
|
||||
cls->defineFunction("setOnDidFailLoading", _SE(js_webview_WebView_setOnDidFailLoading));
|
||||
cls->defineFunction("canGoBack", _SE(js_webview_WebView_canGoBack));
|
||||
cls->defineFunction("loadHTMLString", _SE(js_webview_WebView_loadHTMLString));
|
||||
cls->defineFunction("goForward", _SE(js_webview_WebView_goForward));
|
||||
cls->defineFunction("goBack", _SE(js_webview_WebView_goBack));
|
||||
cls->defineFunction("setScalesPageToFit", _SE(js_webview_WebView_setScalesPageToFit));
|
||||
cls->defineFunction("getOnDidFailLoading", _SE(js_webview_WebView_getOnDidFailLoading));
|
||||
cls->defineFunction("loadFile", _SE(js_webview_WebView_loadFile));
|
||||
cls->defineFunction("loadURL", _SE(js_webview_WebView_loadURL));
|
||||
cls->defineFunction("setBounces", _SE(js_webview_WebView_setBounces));
|
||||
cls->defineFunction("evaluateJS", _SE(js_webview_WebView_evaluateJS));
|
||||
cls->defineFunction("setOnJSCallback", _SE(js_webview_WebView_setOnJSCallback));
|
||||
cls->defineFunction("setBackgroundTransparent", _SE(js_webview_WebView_setBackgroundTransparent));
|
||||
cls->defineFunction("getOnJSCallback", _SE(js_webview_WebView_getOnJSCallback));
|
||||
cls->defineFunction("canGoForward", _SE(js_webview_WebView_canGoForward));
|
||||
cls->defineFunction("getOnShouldStartLoading", _SE(js_webview_WebView_getOnShouldStartLoading));
|
||||
cls->defineFunction("stopLoading", _SE(js_webview_WebView_stopLoading));
|
||||
cls->defineFunction("setFrame", _SE(js_webview_WebView_setFrame));
|
||||
cls->defineFunction("setVisible", _SE(js_webview_WebView_setVisible));
|
||||
cls->defineFunction("reload", _SE(js_webview_WebView_reload));
|
||||
cls->defineFunction("loadData", _SE(js_webview_WebView_loadData));
|
||||
cls->defineFunction("setJavascriptInterfaceScheme", _SE(js_webview_WebView_setJavascriptInterfaceScheme));
|
||||
cls->defineFunction("setOnDidFinishLoading", _SE(js_webview_WebView_setOnDidFinishLoading));
|
||||
cls->defineFunction("getOnDidFinishLoading", _SE(js_webview_WebView_getOnDidFinishLoading));
|
||||
cls->defineFunction("destroy", _SE(js_cocos2d_WebView_destroy));
|
||||
cls->defineStaticFunction("create", _SE(js_webview_WebView_create));
|
||||
cls->defineFinalizeFunction(_SE(js_cocos2d_WebView_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cocos2d::WebView>(cls);
|
||||
|
||||
__jsb_cocos2d_WebView_proto = cls->getProto();
|
||||
__jsb_cocos2d_WebView_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool register_all_webview(se::Object* obj)
|
||||
{
|
||||
// Get the ns
|
||||
se::Value nsVal;
|
||||
if (!obj->getProperty("jsb", &nsVal))
|
||||
{
|
||||
se::HandleObject jsobj(se::Object::createPlainObject());
|
||||
nsVal.setObject(jsobj);
|
||||
obj->setProperty("jsb", nsVal);
|
||||
}
|
||||
se::Object* ns = nsVal.toObject();
|
||||
|
||||
js_register_webview_WebView(ns);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //#if (USE_WEB_VIEW > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include "base/ccConfig.h"
|
||||
#if (USE_WEB_VIEW > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
|
||||
extern se::Object* __jsb_cocos2d_WebView_proto;
|
||||
extern se::Class* __jsb_cocos2d_WebView_class;
|
||||
|
||||
bool js_register_cocos2d_WebView(se::Object* obj);
|
||||
bool register_all_webview(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setOnShouldStartLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setOnDidFailLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_canGoBack);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_loadHTMLString);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_goForward);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_goBack);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setScalesPageToFit);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_getOnDidFailLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_loadFile);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_loadURL);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setBounces);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_evaluateJS);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setOnJSCallback);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setBackgroundTransparent);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_getOnJSCallback);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_canGoForward);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_getOnShouldStartLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_stopLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setFrame);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setVisible);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_reload);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_loadData);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setJavascriptInterfaceScheme);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_setOnDidFinishLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_getOnDidFinishLoading);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_create);
|
||||
SE_DECLARE_FUNC(js_webview_WebView_WebView);
|
||||
|
||||
#endif //#if (USE_WEB_VIEW > 0) && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && !defined(CC_TARGET_OS_TVOS)
|
||||
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 482 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 233 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 464 KiB |
|
After Width: | Height: | Size: 193 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 130 KiB |
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define EVENT_COME_TO_FOREGROUND "event_come_to_foreground"
|
||||
#define EVENT_COME_TO_BACKGROUND "event_come_to_background"
|
||||
|
||||
#define EVENT_ON_PAUSE "event_on_pause"
|
||||
#define EVENT_ON_RESUME "event_on_resume"
|
||||
@@ -0,0 +1,488 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "EventDispatcher.h"
|
||||
|
||||
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/scripting/js-bindings/manual/jsb_global.h"
|
||||
#include "cocos/scripting/js-bindings/event/CustomEventTypes.h"
|
||||
|
||||
namespace {
|
||||
se::Value _tickVal;
|
||||
std::vector<se::Object*> _jsTouchObjPool;
|
||||
se::Object* _jsTouchObjArray = nullptr;
|
||||
se::Object* _jsMouseEventObj = nullptr;
|
||||
se::Object* _jsKeyboardEventObj = nullptr;
|
||||
se::Object* _jsResizeEventObj = nullptr;
|
||||
se::Object* _jsOrientationEventObj = nullptr;
|
||||
bool _inited = false;
|
||||
}
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
std::unordered_map<std::string, EventDispatcher::Node*> EventDispatcher::_listeners;
|
||||
|
||||
void EventDispatcher::init()
|
||||
{
|
||||
_inited = true;
|
||||
se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){
|
||||
EventDispatcher::destroy();
|
||||
});
|
||||
}
|
||||
|
||||
void EventDispatcher::destroy()
|
||||
{
|
||||
for (auto touchObj : _jsTouchObjPool)
|
||||
{
|
||||
touchObj->unroot();
|
||||
touchObj->decRef();
|
||||
}
|
||||
_jsTouchObjPool.clear();
|
||||
|
||||
if (_jsTouchObjArray != nullptr)
|
||||
{
|
||||
_jsTouchObjArray->unroot();
|
||||
_jsTouchObjArray->decRef();
|
||||
_jsTouchObjArray = nullptr;
|
||||
}
|
||||
|
||||
if (_jsMouseEventObj != nullptr)
|
||||
{
|
||||
_jsMouseEventObj->unroot();
|
||||
_jsMouseEventObj->decRef();
|
||||
_jsMouseEventObj = nullptr;
|
||||
}
|
||||
|
||||
if (_jsKeyboardEventObj != nullptr)
|
||||
{
|
||||
_jsKeyboardEventObj->unroot();
|
||||
_jsKeyboardEventObj->decRef();
|
||||
_jsKeyboardEventObj = nullptr;
|
||||
}
|
||||
|
||||
if (_jsResizeEventObj != nullptr)
|
||||
{
|
||||
_jsResizeEventObj->unroot();
|
||||
_jsResizeEventObj->decRef();
|
||||
_jsResizeEventObj = nullptr;
|
||||
}
|
||||
|
||||
if (_jsOrientationEventObj != nullptr)
|
||||
{
|
||||
_jsOrientationEventObj->unroot();
|
||||
_jsOrientationEventObj->decRef();
|
||||
_jsOrientationEventObj = nullptr;
|
||||
}
|
||||
|
||||
_inited = false;
|
||||
_tickVal.setUndefined();
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchTouchEvent(const struct TouchEvent& touchEvent)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
assert(_inited);
|
||||
|
||||
if (_jsTouchObjArray == nullptr)
|
||||
{
|
||||
_jsTouchObjArray = se::Object::createArrayObject(0);
|
||||
_jsTouchObjArray->root();
|
||||
}
|
||||
|
||||
_jsTouchObjArray->setProperty("length", se::Value(touchEvent.touches.size()));
|
||||
|
||||
while (_jsTouchObjPool.size() < touchEvent.touches.size())
|
||||
{
|
||||
se::Object* touchObj = se::Object::createPlainObject();
|
||||
touchObj->root();
|
||||
_jsTouchObjPool.push_back(touchObj);
|
||||
}
|
||||
|
||||
uint32_t touchIndex = 0;
|
||||
int poolIndex = 0;
|
||||
for (const auto& touch : touchEvent.touches)
|
||||
{
|
||||
se::Object* jsTouch = _jsTouchObjPool.at(poolIndex++);
|
||||
jsTouch->setProperty("identifier", se::Value(touch.index));
|
||||
jsTouch->setProperty("clientX", se::Value(touch.x));
|
||||
jsTouch->setProperty("clientY", se::Value(touch.y));
|
||||
jsTouch->setProperty("pageX", se::Value(touch.x));
|
||||
jsTouch->setProperty("pageY", se::Value(touch.y));
|
||||
|
||||
_jsTouchObjArray->setArrayElement(touchIndex, se::Value(jsTouch));
|
||||
++touchIndex;
|
||||
}
|
||||
|
||||
const char* eventName = nullptr;
|
||||
switch (touchEvent.type) {
|
||||
case TouchEvent::Type::BEGAN:
|
||||
eventName = "onTouchStart";
|
||||
break;
|
||||
case TouchEvent::Type::MOVED:
|
||||
eventName = "onTouchMove";
|
||||
break;
|
||||
case TouchEvent::Type::ENDED:
|
||||
eventName = "onTouchEnd";
|
||||
break;
|
||||
case TouchEvent::Type::CANCELLED:
|
||||
eventName = "onTouchCancel";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
se::Value callbackVal;
|
||||
if (__jsbObj->getProperty(eventName, &callbackVal) && !callbackVal.isNullOrUndefined())
|
||||
{
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(_jsTouchObjArray));
|
||||
callbackVal.toObject()->call(args, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchMouseEvent(const struct MouseEvent& mouseEvent)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
assert(_inited);
|
||||
|
||||
if (_jsMouseEventObj == nullptr)
|
||||
{
|
||||
_jsMouseEventObj = se::Object::createPlainObject();
|
||||
_jsMouseEventObj->root();
|
||||
}
|
||||
|
||||
const auto& xVal = se::Value(mouseEvent.x);
|
||||
const auto& yVal = se::Value(mouseEvent.y);
|
||||
const MouseEvent::Type type = mouseEvent.type;
|
||||
|
||||
if (type == MouseEvent::Type::WHEEL)
|
||||
{
|
||||
_jsMouseEventObj->setProperty("wheelDeltaX", xVal);
|
||||
_jsMouseEventObj->setProperty("wheelDeltaY", yVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type == MouseEvent::Type::DOWN || type == MouseEvent::Type::UP)
|
||||
{
|
||||
_jsMouseEventObj->setProperty("button", se::Value(mouseEvent.button));
|
||||
}
|
||||
_jsMouseEventObj->setProperty("x", xVal);
|
||||
_jsMouseEventObj->setProperty("y", yVal);
|
||||
}
|
||||
|
||||
const char* eventName = nullptr;
|
||||
switch (type) {
|
||||
case MouseEvent::Type::DOWN:
|
||||
eventName = "onMouseDown";
|
||||
break;
|
||||
case MouseEvent::Type::MOVE:
|
||||
eventName = "onMouseMove";
|
||||
break;
|
||||
case MouseEvent::Type::UP:
|
||||
eventName = "onMouseUp";
|
||||
break;
|
||||
case MouseEvent::Type::WHEEL:
|
||||
eventName = "onMouseWheel";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
se::Value callbackVal;
|
||||
if (__jsbObj->getProperty(eventName, &callbackVal) && !callbackVal.isNullOrUndefined())
|
||||
{
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(_jsMouseEventObj));
|
||||
callbackVal.toObject()->call(args, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchKeyboardEvent(const struct KeyboardEvent& keyboardEvent)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
assert(_inited);
|
||||
|
||||
if (_jsKeyboardEventObj == nullptr)
|
||||
{
|
||||
_jsKeyboardEventObj = se::Object::createPlainObject();
|
||||
_jsKeyboardEventObj->root();
|
||||
}
|
||||
|
||||
const char* eventName = nullptr;
|
||||
switch (keyboardEvent.action) {
|
||||
case KeyboardEvent::Action::PRESS:
|
||||
case KeyboardEvent::Action::REPEAT:
|
||||
eventName = "onKeyDown";
|
||||
break;
|
||||
case KeyboardEvent::Action::RELEASE:
|
||||
eventName = "onKeyUp";
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
se::Value callbackVal;
|
||||
if (__jsbObj->getProperty(eventName, &callbackVal) && !callbackVal.isNullOrUndefined())
|
||||
{
|
||||
_jsKeyboardEventObj->setProperty("altKey", se::Value(keyboardEvent.altKeyActive));
|
||||
_jsKeyboardEventObj->setProperty("ctrlKey", se::Value(keyboardEvent.ctrlKeyActive));
|
||||
_jsKeyboardEventObj->setProperty("metaKey", se::Value(keyboardEvent.metaKeyActive));
|
||||
_jsKeyboardEventObj->setProperty("shiftKey", se::Value(keyboardEvent.shiftKeyActive));
|
||||
_jsKeyboardEventObj->setProperty("repeat", se::Value(keyboardEvent.action == KeyboardEvent::Action::REPEAT));
|
||||
_jsKeyboardEventObj->setProperty("keyCode", se::Value(keyboardEvent.key));
|
||||
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(_jsKeyboardEventObj));
|
||||
callbackVal.toObject()->call(args, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchTickEvent(float dt)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
if (_tickVal.isUndefined())
|
||||
{
|
||||
se::ScriptEngine::getInstance()->getGlobalObject()->getProperty("gameTick", &_tickVal);
|
||||
}
|
||||
|
||||
static std::chrono::steady_clock::time_point prevTime;
|
||||
prevTime = std::chrono::steady_clock::now();
|
||||
|
||||
se::ValueArray args;
|
||||
long long microSeconds = std::chrono::duration_cast<std::chrono::microseconds>(prevTime - se::ScriptEngine::getInstance()->getStartTime()).count();
|
||||
args.push_back(se::Value((double)(microSeconds * 0.001)));
|
||||
_tickVal.toObject()->call(args, nullptr);
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchResizeEvent(int width, int height)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
assert(_inited);
|
||||
|
||||
if (_jsResizeEventObj == nullptr)
|
||||
{
|
||||
_jsResizeEventObj = se::Object::createPlainObject();
|
||||
_jsResizeEventObj->root();
|
||||
}
|
||||
|
||||
se::Value func;
|
||||
__jsbObj->getProperty("onResize", &func);
|
||||
if (func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
_jsResizeEventObj->setProperty("width", se::Value(width));
|
||||
_jsResizeEventObj->setProperty("height", se::Value(height));
|
||||
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(_jsResizeEventObj));
|
||||
func.toObject()->call(args, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchOrientationChangeEvent(int rotation)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
assert(_inited);
|
||||
|
||||
if (_jsOrientationEventObj == nullptr)
|
||||
{
|
||||
_jsOrientationEventObj = se::Object::createPlainObject();
|
||||
_jsOrientationEventObj->root();
|
||||
}
|
||||
|
||||
se::Value func;
|
||||
__jsbObj->getProperty("onOrientationChanged", &func);
|
||||
if (func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
_jsOrientationEventObj->setProperty("rotation", se::Value(rotation));
|
||||
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(_jsOrientationEventObj));
|
||||
func.toObject()->call(args, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void dispatchEnterBackgroundOrForegroundEvent(const char* funcName)
|
||||
{
|
||||
if (!se::ScriptEngine::getInstance()->isValid())
|
||||
return;
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
assert(_inited);
|
||||
|
||||
se::Value func;
|
||||
__jsbObj->getProperty(funcName, &func);
|
||||
if (func.isObject() && func.toObject()->isFunction())
|
||||
{
|
||||
func.toObject()->call(se::EmptyValueArray, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchOnPauseEvent()
|
||||
{
|
||||
// dispatch to Native
|
||||
CustomEvent event;
|
||||
event.name = EVENT_ON_PAUSE;
|
||||
EventDispatcher::dispatchCustomEvent(event);
|
||||
|
||||
// dispatch to JavaScript
|
||||
dispatchEnterBackgroundOrForegroundEvent("onPause");
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchOnResumeEvent()
|
||||
{
|
||||
// dispatch to Native
|
||||
CustomEvent event;
|
||||
event.name = EVENT_ON_RESUME;
|
||||
EventDispatcher::dispatchCustomEvent(event);
|
||||
|
||||
// dispatch to JavaScript
|
||||
dispatchEnterBackgroundOrForegroundEvent("onResume");
|
||||
}
|
||||
|
||||
uint32_t EventDispatcher::addCustomEventListener(const std::string& eventName, const CustomEventListener& listener)
|
||||
{
|
||||
static uint32_t __listenerIDCounter = 0;
|
||||
uint32_t listenerID = ++__listenerIDCounter;
|
||||
listenerID = listenerID == 0 ? 1 : listenerID;
|
||||
|
||||
Node* newNode = new Node();
|
||||
newNode->listener = listener;
|
||||
newNode->listenerID = listenerID;
|
||||
newNode->next = nullptr;
|
||||
|
||||
auto iter = _listeners.find(eventName);
|
||||
if (iter == _listeners.end())
|
||||
{
|
||||
_listeners.emplace(eventName, newNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
Node* node = iter->second;
|
||||
assert(node != nullptr);
|
||||
Node* prev = nullptr;
|
||||
while (node != nullptr)
|
||||
{
|
||||
prev = node;
|
||||
node = node->next;
|
||||
}
|
||||
prev->next = newNode;
|
||||
}
|
||||
return listenerID;
|
||||
}
|
||||
|
||||
void EventDispatcher::removeCustomEventListener(const std::string& eventName, uint32_t listenerID)
|
||||
{
|
||||
if (eventName.empty())
|
||||
return;
|
||||
|
||||
if (listenerID == 0)
|
||||
return;
|
||||
|
||||
auto iter = _listeners.find(eventName);
|
||||
if (iter != _listeners.end())
|
||||
{
|
||||
Node* prev = nullptr;
|
||||
Node* node = iter->second;
|
||||
while (node != nullptr)
|
||||
{
|
||||
if (node->listenerID == listenerID)
|
||||
{
|
||||
if (prev != nullptr)
|
||||
{
|
||||
prev->next = node->next;
|
||||
}
|
||||
else if (node->next)
|
||||
{
|
||||
_listeners[eventName] = node->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
_listeners.erase(iter);
|
||||
}
|
||||
|
||||
delete node;
|
||||
return;
|
||||
}
|
||||
|
||||
prev = node;
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::removeAllCustomEventListeners(const std::string& eventName)
|
||||
{
|
||||
auto iter = _listeners.find(eventName);
|
||||
if (iter != _listeners.end())
|
||||
{
|
||||
Node* node = iter->second;
|
||||
while (node != nullptr)
|
||||
{
|
||||
Node* next = node->next;
|
||||
delete node;
|
||||
node = next;
|
||||
}
|
||||
_listeners.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::dispatchCustomEvent(const CustomEvent& event)
|
||||
{
|
||||
auto iter = _listeners.find(event.name);
|
||||
if (iter != _listeners.end())
|
||||
{
|
||||
Node* next = nullptr;
|
||||
Node* node = iter->second;
|
||||
while (node != nullptr)
|
||||
{
|
||||
next = node->next;
|
||||
node->listener(event);
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace cocos2d
|
||||
@@ -0,0 +1,143 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace cocos2d
|
||||
{
|
||||
|
||||
// Touch event related
|
||||
|
||||
struct TouchInfo
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
int index = 0;
|
||||
};
|
||||
|
||||
struct TouchEvent
|
||||
{
|
||||
enum class Type : uint8_t
|
||||
{
|
||||
BEGAN,
|
||||
MOVED,
|
||||
ENDED,
|
||||
CANCELLED,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
std::vector<TouchInfo> touches;
|
||||
Type type = Type::UNKNOWN;
|
||||
};
|
||||
|
||||
struct MouseEvent
|
||||
{
|
||||
enum class Type : uint8_t
|
||||
{
|
||||
DOWN,
|
||||
UP,
|
||||
MOVE,
|
||||
WHEEL,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
// The button number that was pressed when the mouse event was fired: Left button=0, middle button=1 (if present), right button=2.
|
||||
// For mice configured for left handed use in which the button actions are reversed the values are instead read from right to left.
|
||||
unsigned short button = 0;
|
||||
Type type = Type::UNKNOWN;
|
||||
};
|
||||
|
||||
struct KeyboardEvent
|
||||
{
|
||||
enum class Action : uint8_t {
|
||||
PRESS,
|
||||
RELEASE,
|
||||
REPEAT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
int key = -1;
|
||||
Action action = Action::UNKNOWN;
|
||||
bool altKeyActive = false;
|
||||
bool ctrlKeyActive = false;
|
||||
bool metaKeyActive = false;
|
||||
bool shiftKeyActive = false;
|
||||
};
|
||||
|
||||
class CustomEvent
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
union {
|
||||
void* ptrVal;
|
||||
long longVal;
|
||||
int intVal;
|
||||
short shortVal;
|
||||
char charVal;
|
||||
bool boolVal;
|
||||
} args[10];
|
||||
|
||||
CustomEvent(){};
|
||||
virtual ~CustomEvent(){};
|
||||
};
|
||||
|
||||
class EventDispatcher
|
||||
{
|
||||
public:
|
||||
static void init();
|
||||
static void destroy();
|
||||
|
||||
static void dispatchTouchEvent(const struct TouchEvent& touchEvent);
|
||||
static void dispatchMouseEvent(const struct MouseEvent& mouseEvent);
|
||||
static void dispatchKeyboardEvent(const struct KeyboardEvent& keyboardEvent);
|
||||
static void dispatchTickEvent(float dt);
|
||||
static void dispatchResizeEvent(int width, int height);
|
||||
static void dispatchOrientationChangeEvent(int rotation);
|
||||
static void dispatchOnPauseEvent();
|
||||
static void dispatchOnResumeEvent();
|
||||
|
||||
using CustomEventListener = std::function<void(const CustomEvent&)>;
|
||||
static uint32_t addCustomEventListener(const std::string& eventName, const CustomEventListener& listener);
|
||||
static void removeCustomEventListener(const std::string& eventName, uint32_t listenerID);
|
||||
static void removeAllCustomEventListeners(const std::string& eventName);
|
||||
static void dispatchCustomEvent(const CustomEvent& event);
|
||||
|
||||
private:
|
||||
struct Node
|
||||
{
|
||||
CustomEventListener listener;
|
||||
uint32_t listenerID;
|
||||
struct Node* next;
|
||||
};
|
||||
static std::unordered_map<std::string, Node*> _listeners;
|
||||
};
|
||||
|
||||
} // end of namespace cocos2d
|
||||
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "HandleObject.hpp"
|
||||
#include "Object.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
HandleObject::HandleObject(Object* obj)
|
||||
: _obj(obj)
|
||||
{
|
||||
if (_obj != nullptr)
|
||||
{
|
||||
// se::HandleObject could not be used for native binding object.
|
||||
assert(!_obj->_getClass());
|
||||
_obj->root();
|
||||
}
|
||||
}
|
||||
|
||||
HandleObject::~HandleObject()
|
||||
{
|
||||
if (_obj != nullptr)
|
||||
{
|
||||
_obj->unroot();
|
||||
_obj->decRef();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* HandleObject is a helper class for easily release, root and unroot an non-native-binding se::Object.
|
||||
|
||||
{
|
||||
se::HandleObject obj(se::Object::createPlainObject());
|
||||
obj->setProperty(...);
|
||||
otherObject->setProperty("foo", se::Value(obj));
|
||||
}
|
||||
|
||||
is equal to:
|
||||
|
||||
{
|
||||
se::Object* obj = se::Object::createPlainObject();
|
||||
obj->root(); // root after object created to avoid object is garbage collected
|
||||
|
||||
obj->setProperty(...);
|
||||
otherObject->setProperty("foo", se::Value(obj));
|
||||
|
||||
obj->unroot(); // unroot object after obj is used.
|
||||
obj->decRef(); // Decrement referent count to avoid memory leak.
|
||||
}
|
||||
|
||||
HandleObject should not be used to create a native binding object since the created binding object
|
||||
should be holded by JavaScript VM and released in finalize callback internally.
|
||||
|
||||
*/
|
||||
class HandleObject
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief The constructor of HandleObject
|
||||
* @param[in] obj The se::Object to attach.
|
||||
*/
|
||||
HandleObject(Object* obj);
|
||||
|
||||
/**
|
||||
* @brief The destructor of HandleObject
|
||||
*/
|
||||
~HandleObject();
|
||||
|
||||
/**
|
||||
* @brief The pointer operator
|
||||
* @return The se::Object attached.
|
||||
*/
|
||||
inline Object* operator->() const
|
||||
{
|
||||
return _obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the se::Object attached.
|
||||
* @return The se::Object attached.
|
||||
*/
|
||||
inline Object* get() const
|
||||
{
|
||||
return _obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests whether HandleObject holds an invalid se::Object.
|
||||
* @return true if HandleObject holds an invalid se::Object, otherwise false.
|
||||
*/
|
||||
inline bool isEmpty() const
|
||||
{
|
||||
return (_obj == nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
HandleObject(const HandleObject&) = delete;
|
||||
void operator=(const HandleObject&) = delete;
|
||||
HandleObject(HandleObject&&) = delete;
|
||||
void operator=(HandleObject&&) = delete;
|
||||
|
||||
void* operator new(size_t size) = delete;
|
||||
void operator delete(void*, size_t) = delete;
|
||||
|
||||
Object* _obj;
|
||||
friend class Object;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
// NativePtrToObjectMap
|
||||
NativePtrToObjectMap::Map* NativePtrToObjectMap::__nativePtrToObjectMap = nullptr;
|
||||
|
||||
bool NativePtrToObjectMap::init()
|
||||
{
|
||||
if (__nativePtrToObjectMap == nullptr)
|
||||
__nativePtrToObjectMap = new (std::nothrow) NativePtrToObjectMap::Map();
|
||||
|
||||
return __nativePtrToObjectMap != nullptr;
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::destroy()
|
||||
{
|
||||
if (__nativePtrToObjectMap != nullptr)
|
||||
{
|
||||
delete __nativePtrToObjectMap;
|
||||
__nativePtrToObjectMap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::emplace(void* nativeObj, Object* seObj)
|
||||
{
|
||||
__nativePtrToObjectMap->emplace(nativeObj, seObj);
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::find(void* nativeObj)
|
||||
{
|
||||
return __nativePtrToObjectMap->find(nativeObj);
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::erase(Map::iterator iter)
|
||||
{
|
||||
return __nativePtrToObjectMap->erase(iter);
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::erase(void* nativeObj)
|
||||
{
|
||||
__nativePtrToObjectMap->erase(nativeObj);
|
||||
}
|
||||
|
||||
void NativePtrToObjectMap::clear()
|
||||
{
|
||||
__nativePtrToObjectMap->clear();
|
||||
}
|
||||
|
||||
size_t NativePtrToObjectMap::size()
|
||||
{
|
||||
return __nativePtrToObjectMap->size();
|
||||
}
|
||||
|
||||
const NativePtrToObjectMap::Map& NativePtrToObjectMap::instance()
|
||||
{
|
||||
return *__nativePtrToObjectMap;
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::begin()
|
||||
{
|
||||
return __nativePtrToObjectMap->begin();
|
||||
}
|
||||
|
||||
NativePtrToObjectMap::Map::iterator NativePtrToObjectMap::end()
|
||||
{
|
||||
return __nativePtrToObjectMap->end();
|
||||
}
|
||||
|
||||
// NonRefNativePtrCreatedByCtorMap
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map* NonRefNativePtrCreatedByCtorMap::__nonRefNativeObjectCreatedByCtorMap = nullptr;
|
||||
|
||||
bool NonRefNativePtrCreatedByCtorMap::init()
|
||||
{
|
||||
if (__nonRefNativeObjectCreatedByCtorMap == nullptr)
|
||||
__nonRefNativeObjectCreatedByCtorMap = new (std::nothrow) NonRefNativePtrCreatedByCtorMap::Map();
|
||||
|
||||
return __nonRefNativeObjectCreatedByCtorMap != nullptr;
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::destroy()
|
||||
{
|
||||
if (__nonRefNativeObjectCreatedByCtorMap != nullptr)
|
||||
{
|
||||
delete __nonRefNativeObjectCreatedByCtorMap;
|
||||
__nonRefNativeObjectCreatedByCtorMap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::emplace(void* nativeObj)
|
||||
{
|
||||
__nonRefNativeObjectCreatedByCtorMap->emplace(nativeObj, true);
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::find(void* nativeObj)
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->find(nativeObj);
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::erase(Map::iterator iter)
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->erase(iter);
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::erase(void* nativeObj)
|
||||
{
|
||||
__nonRefNativeObjectCreatedByCtorMap->erase(nativeObj);
|
||||
}
|
||||
|
||||
void NonRefNativePtrCreatedByCtorMap::clear()
|
||||
{
|
||||
__nonRefNativeObjectCreatedByCtorMap->clear();
|
||||
}
|
||||
|
||||
size_t NonRefNativePtrCreatedByCtorMap::size()
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->size();
|
||||
}
|
||||
|
||||
const NonRefNativePtrCreatedByCtorMap::Map& NonRefNativePtrCreatedByCtorMap::instance()
|
||||
{
|
||||
return *__nonRefNativeObjectCreatedByCtorMap;
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::begin()
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->begin();
|
||||
}
|
||||
|
||||
NonRefNativePtrCreatedByCtorMap::Map::iterator NonRefNativePtrCreatedByCtorMap::end()
|
||||
{
|
||||
return __nonRefNativeObjectCreatedByCtorMap->end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
class NativePtrToObjectMap
|
||||
{
|
||||
public:
|
||||
// key: native ptr, value: se::Object
|
||||
using Map = std::unordered_map<void*, Object*>;
|
||||
|
||||
static bool init();
|
||||
static void destroy();
|
||||
|
||||
static Map::iterator find(void* nativeObj);
|
||||
static Map::iterator erase(Map::iterator iter);
|
||||
static void erase(void* nativeObj);
|
||||
static void clear();
|
||||
static size_t size();
|
||||
|
||||
static const Map& instance();
|
||||
|
||||
static Map::iterator begin();
|
||||
static Map::iterator end();
|
||||
|
||||
private:
|
||||
static void emplace(void* nativeObj, Object* seObj);
|
||||
static Map* __nativePtrToObjectMap;
|
||||
|
||||
friend class Object;
|
||||
};
|
||||
|
||||
class NonRefNativePtrCreatedByCtorMap
|
||||
{
|
||||
public:
|
||||
// key: native ptr, value: non-ref object created by ctor
|
||||
using Map = std::unordered_map<void*, bool>;
|
||||
|
||||
static bool init();
|
||||
static void destroy();
|
||||
|
||||
static void emplace(void* nativeObj);
|
||||
static Map::iterator find(void* nativeObj);
|
||||
static Map::iterator erase(Map::iterator iter);
|
||||
static void erase(void* nativeObj);
|
||||
static void clear();
|
||||
static size_t size();
|
||||
|
||||
static const Map& instance();
|
||||
|
||||
static Map::iterator begin();
|
||||
static Map::iterator end();
|
||||
|
||||
private:
|
||||
static Map* __nonRefNativeObjectCreatedByCtorMap;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
#include "sm/Object.hpp"
|
||||
#endif
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8
|
||||
#include "v8/Object.hpp"
|
||||
#endif
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
#include "jsc/Object.hpp"
|
||||
#endif
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
#include "chakracore/Object.hpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "RefCounter.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
void RefCounter::incRef()
|
||||
{
|
||||
++_refCount;
|
||||
}
|
||||
|
||||
void RefCounter::decRef()
|
||||
{
|
||||
--_refCount;
|
||||
if (_refCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int RefCounter::getRefCount()
|
||||
{
|
||||
return _refCount;
|
||||
}
|
||||
|
||||
RefCounter::RefCounter()
|
||||
: _refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
RefCounter::~RefCounter()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
namespace se {
|
||||
|
||||
/**
|
||||
* This class is used to manage reference-counting providing a simple interface and a counter.
|
||||
*
|
||||
*/
|
||||
class RefCounter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Increases reference count by one.
|
||||
*/
|
||||
void incRef();
|
||||
|
||||
/**
|
||||
* @brief Decrements the reference count, if it reaches zero, destroys this instance of RefCounter to release its memory.
|
||||
* @note Please note that after calling this function, the caller should absolutely avoid to use the pointer to this instance since it may not be valid anymore.
|
||||
*/
|
||||
void decRef();
|
||||
|
||||
/**
|
||||
* @brief Gets reference count.
|
||||
* @return The reference count.
|
||||
* @note When this goes to zero during a decRef() call, the object will auto-delete itself.
|
||||
*/
|
||||
unsigned int getRefCount();
|
||||
|
||||
protected:
|
||||
// Default constructor
|
||||
// Initialises the internal reference count to 1.
|
||||
RefCounter();
|
||||
// Destructor
|
||||
virtual ~RefCounter();
|
||||
|
||||
private:
|
||||
unsigned int _refCount;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
#include "sm/SeApi.h"
|
||||
#endif
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8
|
||||
#include "v8/SeApi.h"
|
||||
#endif
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
#include "jsc/SeApi.h"
|
||||
#endif
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
#include "chakracore/SeApi.h"
|
||||
#endif
|
||||
|
||||
#include "Value.hpp"
|
||||
#include "Object.hpp"
|
||||
#include "State.hpp"
|
||||
#include "HandleObject.hpp"
|
||||
#include "MappingUtils.hpp"
|
||||
@@ -0,0 +1,97 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "State.hpp"
|
||||
#include "Object.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
State::State()
|
||||
: _nativeThisObject(nullptr)
|
||||
, _thisObject(nullptr)
|
||||
, _args(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
State::~State()
|
||||
{
|
||||
SAFE_DEC_REF(_thisObject);
|
||||
}
|
||||
|
||||
State::State(void* nativeThisObject)
|
||||
: _nativeThisObject(nativeThisObject)
|
||||
, _thisObject(nullptr)
|
||||
, _args(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
State::State(void* nativeThisObject, const ValueArray& args)
|
||||
: _nativeThisObject(nativeThisObject)
|
||||
, _thisObject(nullptr)
|
||||
, _args(&args)
|
||||
{
|
||||
}
|
||||
|
||||
State::State(Object* thisObject, const ValueArray& args)
|
||||
: _nativeThisObject(nullptr)
|
||||
, _thisObject(thisObject)
|
||||
, _args(&args)
|
||||
{
|
||||
if (_thisObject != nullptr)
|
||||
{
|
||||
_thisObject->incRef();
|
||||
}
|
||||
}
|
||||
|
||||
void* State::nativeThisObject() const
|
||||
{
|
||||
return _nativeThisObject;
|
||||
}
|
||||
|
||||
const ValueArray& State::args() const
|
||||
{
|
||||
if (_args != nullptr)
|
||||
{
|
||||
return *(_args);
|
||||
}
|
||||
return EmptyValueArray;
|
||||
}
|
||||
|
||||
Object* State::thisObject()
|
||||
{
|
||||
if (nullptr == _thisObject && nullptr != _nativeThisObject)
|
||||
{
|
||||
_thisObject = se::Object::getObjectWithPtr(_nativeThisObject);
|
||||
}
|
||||
// _nativeThisObject in Static method will be nullptr
|
||||
// assert(_thisObject != nullptr);
|
||||
return _thisObject;
|
||||
}
|
||||
|
||||
Value& State::rval()
|
||||
{
|
||||
return _retVal;
|
||||
}
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Value.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* State represents an environment while a function or an accesstor is invoked from JavaScript.
|
||||
*/
|
||||
class State final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Gets void* pointer of `this` object's private data.
|
||||
* @return A void* pointer of `this` object's private data.
|
||||
*/
|
||||
void* nativeThisObject() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the arguments of native binding functions or accesstors.
|
||||
* @return The arguments of native binding functions or accesstors.
|
||||
*/
|
||||
const ValueArray& args() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the JavaScript `this` object wrapped in se::Object.
|
||||
* @return The JavaScript `this` object wrapped in se::Object.
|
||||
*/
|
||||
Object* thisObject();
|
||||
|
||||
/**
|
||||
* @brief Gets the return value reference. Used for setting return value for a function.
|
||||
* @return The return value reference.
|
||||
*/
|
||||
Value& rval();
|
||||
|
||||
// Private API used in wrapper
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
State();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
~State();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
State(void* nativeThisObject);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
State(void* nativeThisObject, const ValueArray& args);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param[in]
|
||||
* @return
|
||||
*/
|
||||
State(Object* thisObject, const ValueArray& args);
|
||||
private:
|
||||
|
||||
// Disable copy/move constructor, copy/move assigment
|
||||
State(const State&);
|
||||
State(State&&);
|
||||
State& operator=(const State&);
|
||||
State& operator=(State&&);
|
||||
|
||||
void* _nativeThisObject; //weak ref
|
||||
Object* _thisObject; //weak ref
|
||||
const ValueArray* _args; //weak ref
|
||||
Value _retVal; //weak ref
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,583 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Value.hpp"
|
||||
#include "Object.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
ValueArray EmptyValueArray;
|
||||
|
||||
Value Value::Null = Value(Type::Null);
|
||||
Value Value::Undefined = Value(Type::Undefined);
|
||||
|
||||
Value::Value()
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
memset(&_u, 0, sizeof(_u));
|
||||
}
|
||||
|
||||
Value::Value(Type type)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
memset(&_u, 0, sizeof(_u));
|
||||
reset(type);
|
||||
}
|
||||
|
||||
Value::Value(const Value& v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
*this = v;
|
||||
}
|
||||
|
||||
Value::Value(Value&& v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
*this = std::move(v);
|
||||
}
|
||||
|
||||
Value::Value(bool v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setBoolean(v);
|
||||
}
|
||||
|
||||
Value::Value(int8_t v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setInt8(v);
|
||||
}
|
||||
|
||||
Value::Value(uint8_t v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setUint8(v);
|
||||
}
|
||||
|
||||
Value::Value(int32_t v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setInt32(v);
|
||||
}
|
||||
|
||||
Value::Value(uint32_t v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setUint32(v);
|
||||
}
|
||||
|
||||
Value::Value(int16_t v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setInt16(v);
|
||||
}
|
||||
|
||||
Value::Value(uint16_t v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setUint16(v);
|
||||
}
|
||||
|
||||
Value::Value(long v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setLong(v);
|
||||
}
|
||||
|
||||
Value::Value(unsigned long v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setUlong(v);
|
||||
}
|
||||
|
||||
Value::Value(float v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setFloat(v);
|
||||
}
|
||||
|
||||
Value::Value(double v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setNumber(v);
|
||||
}
|
||||
|
||||
Value::Value(const char* v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setString(v);
|
||||
}
|
||||
|
||||
Value::Value(const std::string& v)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setString(v);
|
||||
}
|
||||
|
||||
Value::Value(Object* o, bool autoRootUnroot/* = false*/)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setObject(o, autoRootUnroot);
|
||||
}
|
||||
|
||||
Value::Value(const HandleObject& o, bool autoRootUnroot/* = false*/)
|
||||
: _type(Type::Undefined)
|
||||
, _autoRootUnroot(false)
|
||||
{
|
||||
setObject(o, autoRootUnroot);
|
||||
}
|
||||
|
||||
Value::~Value()
|
||||
{
|
||||
reset(Type::Undefined);
|
||||
}
|
||||
|
||||
Value& Value::operator=(const Value& v)
|
||||
{
|
||||
if (this != &v)
|
||||
{
|
||||
reset(v.getType());
|
||||
|
||||
switch (_type) {
|
||||
case Type::Null:
|
||||
case Type::Undefined:
|
||||
{
|
||||
memset(&_u, 0, sizeof(_u));
|
||||
break;
|
||||
}
|
||||
case Type::Number:
|
||||
_u._number = v._u._number;
|
||||
break;
|
||||
case Type::String:
|
||||
*_u._string = *v._u._string;
|
||||
break;
|
||||
case Type::Boolean:
|
||||
_u._boolean = v._u._boolean;
|
||||
break;
|
||||
case Type::Object:
|
||||
{
|
||||
setObject(v._u._object, v._autoRootUnroot);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Value& Value::operator=(Value&& v)
|
||||
{
|
||||
if (this != &v)
|
||||
{
|
||||
reset(v.getType());
|
||||
|
||||
switch (_type) {
|
||||
case Type::Null:
|
||||
case Type::Undefined:
|
||||
{
|
||||
memset(&_u, 0, sizeof(_u));
|
||||
break;
|
||||
}
|
||||
case Type::Number:
|
||||
_u._number = v._u._number;
|
||||
break;
|
||||
case Type::String:
|
||||
*_u._string = std::move(*v._u._string);
|
||||
break;
|
||||
case Type::Boolean:
|
||||
_u._boolean = v._u._boolean;
|
||||
break;
|
||||
case Type::Object:
|
||||
{
|
||||
if (_u._object != nullptr) // When old value is also an Object, reset will take no effect, therefore, _u._object may not be nullptr.
|
||||
{
|
||||
if (_autoRootUnroot)
|
||||
{
|
||||
_u._object->unroot();
|
||||
}
|
||||
_u._object->decRef();
|
||||
}
|
||||
_u._object = v._u._object;
|
||||
_autoRootUnroot = v._autoRootUnroot;
|
||||
v._u._object = nullptr; // Reset to nullptr here to avoid 'release' operation in v.reset(Type::Undefined) since it's a move operation here.
|
||||
v._autoRootUnroot = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
v.reset(Type::Undefined);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Value& Value::operator=(bool v)
|
||||
// {
|
||||
// setBoolean(v);
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// Value& Value::operator=(double v)
|
||||
// {
|
||||
// setNumber(v);
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// Value& Value::operator=(const std::string& v)
|
||||
// {
|
||||
// setString(v);
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// Value& Value::operator=(Object* o)
|
||||
// {
|
||||
// setObject(o);
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// Value& Value::operator=(const HandleObject& o)
|
||||
// {
|
||||
// setObject(o);
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
void Value::setUndefined()
|
||||
{
|
||||
reset(Type::Undefined);
|
||||
}
|
||||
|
||||
void Value::setNull()
|
||||
{
|
||||
reset(Type::Null);
|
||||
}
|
||||
|
||||
void Value::setBoolean(bool v)
|
||||
{
|
||||
reset(Type::Boolean);
|
||||
_u._boolean = v;
|
||||
}
|
||||
|
||||
void Value::setInt8(int8_t v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setUint8(uint8_t v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setInt32(int32_t v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setUint32(uint32_t v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setInt16(int16_t v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setUint16(uint16_t v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setLong(long v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setUlong(unsigned long v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setFloat(float v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = (double)v;
|
||||
}
|
||||
|
||||
void Value::setNumber(double v)
|
||||
{
|
||||
reset(Type::Number);
|
||||
_u._number = v;
|
||||
}
|
||||
|
||||
void Value::setString(const char* v)
|
||||
{
|
||||
if (v != nullptr)
|
||||
{
|
||||
reset(Type::String);
|
||||
*_u._string = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
reset(Type::Null);
|
||||
}
|
||||
}
|
||||
|
||||
void Value::setString(const std::string& v)
|
||||
{
|
||||
reset(Type::String);
|
||||
*_u._string = v;
|
||||
}
|
||||
|
||||
void Value::setObject(Object* object, bool autoRootUnroot/* = false*/)
|
||||
{
|
||||
if (object == nullptr)
|
||||
{
|
||||
reset(Type::Null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_type != Type::Object)
|
||||
{
|
||||
reset(Type::Object);
|
||||
}
|
||||
|
||||
if (_u._object != object)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->incRef();
|
||||
if (autoRootUnroot)
|
||||
{
|
||||
object->root();
|
||||
}
|
||||
}
|
||||
|
||||
if (_u._object != nullptr) // When old value is also an Object, reset will take no effect, therefore, _u._object may not be nullptr.
|
||||
{
|
||||
if (_autoRootUnroot)
|
||||
{
|
||||
_u._object->unroot();
|
||||
}
|
||||
_u._object->decRef();
|
||||
}
|
||||
_u._object = object;
|
||||
_autoRootUnroot = autoRootUnroot;
|
||||
}
|
||||
else
|
||||
{
|
||||
_autoRootUnroot = autoRootUnroot;
|
||||
if (_autoRootUnroot)
|
||||
{
|
||||
_u._object->root();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Value::setObject(const HandleObject& o, bool autoRootUnroot/* = false*/)
|
||||
{
|
||||
setObject(o.get(), autoRootUnroot);
|
||||
}
|
||||
|
||||
int8_t Value::toInt8() const
|
||||
{
|
||||
return static_cast<int8_t>(toNumber());
|
||||
}
|
||||
|
||||
uint8_t Value::toUint8() const
|
||||
{
|
||||
return static_cast<uint8_t>(toNumber());
|
||||
}
|
||||
|
||||
int16_t Value::toInt16() const
|
||||
{
|
||||
return static_cast<int16_t>(toNumber());
|
||||
}
|
||||
|
||||
uint16_t Value::toUint16() const
|
||||
{
|
||||
return static_cast<uint16_t>(toNumber());
|
||||
}
|
||||
|
||||
int32_t Value::toInt32() const
|
||||
{
|
||||
return static_cast<int32_t>(toNumber());
|
||||
}
|
||||
|
||||
uint32_t Value::toUint32() const
|
||||
{
|
||||
return static_cast<uint32_t>(toNumber());
|
||||
}
|
||||
|
||||
long Value::toLong() const
|
||||
{
|
||||
return static_cast<long>(toNumber());
|
||||
}
|
||||
|
||||
unsigned long Value::toUlong() const
|
||||
{
|
||||
return static_cast<unsigned long>(toNumber());
|
||||
}
|
||||
|
||||
float Value::toFloat() const
|
||||
{
|
||||
return static_cast<float>(toNumber());
|
||||
}
|
||||
|
||||
double Value::toNumber() const
|
||||
{
|
||||
assert(_type == Type::Number || _type == Type::Boolean);
|
||||
if (_type == Type::Boolean)
|
||||
{
|
||||
if (_u._boolean)
|
||||
return 1.0;
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
return _u._number;
|
||||
}
|
||||
|
||||
bool Value::toBoolean() const
|
||||
{
|
||||
assert(_type == Type::Boolean);
|
||||
return _u._boolean;
|
||||
}
|
||||
|
||||
const std::string& Value::toString() const
|
||||
{
|
||||
assert(_type == Type::String);
|
||||
return *_u._string;
|
||||
}
|
||||
|
||||
std::string Value::toStringForce() const
|
||||
{
|
||||
std::string ret;
|
||||
if (_type == Type::String)
|
||||
{
|
||||
ret = *_u._string;
|
||||
}
|
||||
else if (_type == Type::Boolean)
|
||||
{
|
||||
ret = _u._boolean ? "true" : "false";
|
||||
}
|
||||
else if (_type == Type::Number)
|
||||
{
|
||||
char tmp[50] = {0};
|
||||
snprintf(tmp, sizeof(tmp), "%.17g", _u._number);
|
||||
ret = tmp;
|
||||
}
|
||||
else if (_type == Type::Object)
|
||||
{
|
||||
ret = toObject()->toString();
|
||||
}
|
||||
else if (_type == Type::Null)
|
||||
{
|
||||
ret = "null";
|
||||
}
|
||||
else if (_type == Type::Undefined)
|
||||
{
|
||||
ret = "undefined";
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object* Value::toObject() const
|
||||
{
|
||||
assert(isObject());
|
||||
return _u._object;
|
||||
}
|
||||
|
||||
void Value::reset(Type type)
|
||||
{
|
||||
if (_type != type)
|
||||
{
|
||||
switch (_type) {
|
||||
case Type::String:
|
||||
delete _u._string;
|
||||
break;
|
||||
case Type::Object:
|
||||
{
|
||||
if (_u._object != nullptr)
|
||||
{
|
||||
if (_autoRootUnroot)
|
||||
{
|
||||
_u._object->unroot();
|
||||
}
|
||||
_u._object->decRef();
|
||||
_u._object = nullptr;
|
||||
}
|
||||
|
||||
_autoRootUnroot = false;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
memset(&_u, 0, sizeof(_u));
|
||||
|
||||
switch (type) {
|
||||
case Type::String:
|
||||
_u._string = new std::string();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
_type = type;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
@@ -0,0 +1,421 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "HandleObject.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* se::Value represents a JavaScript Value.
|
||||
* It could be undefined, null, number, boolean, string and object which exists in JavaScript.
|
||||
*/
|
||||
class Value final
|
||||
{
|
||||
public:
|
||||
enum class Type : char
|
||||
{
|
||||
Undefined = 0,
|
||||
Null,
|
||||
Number,
|
||||
Boolean,
|
||||
String,
|
||||
Object
|
||||
};
|
||||
|
||||
static Value Null;
|
||||
static Value Undefined;
|
||||
|
||||
/**
|
||||
* @brief The default constructor.
|
||||
*/
|
||||
Value();
|
||||
|
||||
/**
|
||||
* @brief The copy constructor.
|
||||
*/
|
||||
Value(const Value& v);
|
||||
|
||||
/**
|
||||
* @brief The move constructor.
|
||||
*/
|
||||
Value(Value&& v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a boolean arguement.
|
||||
*/
|
||||
explicit Value(bool v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a int8_t arguement.
|
||||
*/
|
||||
explicit Value(int8_t v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a uint8_t arguement.
|
||||
*/
|
||||
explicit Value(uint8_t v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a int16_t arguement.
|
||||
*/
|
||||
explicit Value(int16_t v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a uint16_t arguement.
|
||||
*/
|
||||
explicit Value(uint16_t v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a int32_t arguement.
|
||||
*/
|
||||
explicit Value(int32_t v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a uint32_t arguement.
|
||||
*/
|
||||
explicit Value(uint32_t v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a long arguement.
|
||||
*/
|
||||
explicit Value(long v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a unsigned long arguement.
|
||||
*/
|
||||
explicit Value(unsigned long v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a float arguement.
|
||||
*/
|
||||
explicit Value(float v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a double arguement.
|
||||
*/
|
||||
explicit Value(double v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with an UTF8 null-terminated string argument.
|
||||
*/
|
||||
explicit Value(const char* v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with an UTF8 string argument.
|
||||
*/
|
||||
explicit Value(const std::string& v);
|
||||
|
||||
/**
|
||||
* @brief The constructor with an Object.
|
||||
* @param o A se::Object to be set.
|
||||
* @param[in] autoRootUnroot Whether to root se::Object and unroot it in se::Value's destructor or unroot it while object is replaced. Default value is false.
|
||||
*/
|
||||
explicit Value(Object* o, bool autoRootUnroot = false);
|
||||
|
||||
/**
|
||||
* @brief The constructor with a HandleObject.
|
||||
* @param o A se::HandleObject to be set.
|
||||
* @param[in] autoRootUnroot Whether to root se::HandleObject and unroot it in se::Value's destructor or unroot it while object is replaced. Default value is false.
|
||||
*/
|
||||
explicit Value(const HandleObject& o, bool autoRootUnroot = false);
|
||||
|
||||
/**
|
||||
* @brief The destructor of se::Value
|
||||
*/
|
||||
~Value();
|
||||
|
||||
/**
|
||||
* @brief The copy assignment operator.
|
||||
*/
|
||||
Value& operator=(const Value& v);
|
||||
|
||||
/**
|
||||
* @brief The move assignment operator.
|
||||
*/
|
||||
Value& operator=(Value&& v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to undefined.
|
||||
*/
|
||||
void setUndefined();
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to null.
|
||||
*/
|
||||
void setNull();
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a boolean value.
|
||||
* @param[in] v The boolean value to be set.
|
||||
*/
|
||||
void setBoolean(bool v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a int8_t value.
|
||||
* @param[in] v The int8_t value to be set.
|
||||
*/
|
||||
void setInt8(int8_t v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a uint8_t value.
|
||||
* @param[in] v The uint8_t value to be set.
|
||||
*/
|
||||
void setUint8(uint8_t v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a int16_t value.
|
||||
* @param[in] v The int16_t value to be set.
|
||||
*/
|
||||
void setInt16(int16_t v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a uint16_t value.
|
||||
* @param[in] v The uint16_t value to be set.
|
||||
*/
|
||||
void setUint16(uint16_t v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a int32_t value.
|
||||
* @param[in] v The int32_t value to be set.
|
||||
*/
|
||||
void setInt32(int32_t v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a uint32_t value.
|
||||
* @param[in] v The uint32_t value to be set.
|
||||
*/
|
||||
void setUint32(uint32_t v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a long value.
|
||||
* @param[in] v The long value to be set.
|
||||
*/
|
||||
void setLong(long v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a unsigned long value.
|
||||
* @param[in] v The unsigned long value to be set.
|
||||
*/
|
||||
void setUlong(unsigned long v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a float value.
|
||||
* @param[in] v The float value to be set.
|
||||
*/
|
||||
void setFloat(float v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to a double value.
|
||||
* @param[in] v The double value to be set.
|
||||
*/
|
||||
void setNumber(double v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to an UTF8 null-terminated string value.
|
||||
* @param[in] v The UTF8 null-terminated string value to be set.
|
||||
*/
|
||||
void setString(const char* v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to string value.
|
||||
* @param[in] v The string value to be set.
|
||||
*/
|
||||
void setString(const std::string& v);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to se::Object value.
|
||||
* @param[in] o The se::Object to be set.
|
||||
* @param[in] autoRootUnroot Whether to root se::Object and unroot it in se::Value's destructor or unroot it while object is replaced. Default value is false.
|
||||
*/
|
||||
void setObject(Object* o, bool autoRootUnroot = false);
|
||||
|
||||
/**
|
||||
* @brief Sets se::Value to se::HandleObject value.
|
||||
* @param[in] o The se::Object to be set.
|
||||
* @param[in] autoRootUnroot Whether to root se::HandleObject and unroot it in se::Value's destructor or unroot it while object is replaced. Default value is false.
|
||||
*/
|
||||
void setObject(const HandleObject& o, bool autoRootUnroot = false);
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to int8_t.
|
||||
* @return int8_t integer.
|
||||
*/
|
||||
int8_t toInt8() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to uint8_t.
|
||||
* @return uint8_t integer.
|
||||
*/
|
||||
uint8_t toUint8() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to int16_t.
|
||||
* @return int16_t integer.
|
||||
*/
|
||||
int16_t toInt16() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to uint16_t.
|
||||
* @return uint16_t integer.
|
||||
*/
|
||||
uint16_t toUint16() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to int32_t.
|
||||
* @return int32_t integer.
|
||||
*/
|
||||
int32_t toInt32() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to uint32_t.
|
||||
* @return uint32_t integer.
|
||||
*/
|
||||
uint32_t toUint32() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to long.
|
||||
* @return long integer.
|
||||
*/
|
||||
long toLong() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to unsigned long.
|
||||
* @return unsigned long integer.
|
||||
*/
|
||||
unsigned long toUlong() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to float number.
|
||||
* @return float number.
|
||||
*/
|
||||
float toFloat() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to double number.
|
||||
* @return double number.
|
||||
*/
|
||||
double toNumber() const;
|
||||
|
||||
/**
|
||||
* @brief Converts se::Value to boolean.
|
||||
* @return boolean.
|
||||
*/
|
||||
bool toBoolean() const;
|
||||
|
||||
/**
|
||||
* @brief Gets std::string if se::Value stores a string. It will trigger an assertion if se::Value isn't a string.
|
||||
* @return A std::string reference.
|
||||
* @see toStringForce
|
||||
*/
|
||||
const std::string& toString() const;
|
||||
|
||||
/**
|
||||
* @brief Converts a se::Value to std::string. Could be invoked even when se::Value isn't a string.
|
||||
* @return A copied std::string value.
|
||||
* @see toString
|
||||
*/
|
||||
std::string toStringForce() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the se::Object pointer if se::Value stores an object. It will trigger an assertion if se::Value isn't a object.
|
||||
* @return A se::Object pointer.
|
||||
*/
|
||||
Object* toObject() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the type of se::Value.
|
||||
* @return The type of se::Value.
|
||||
*/
|
||||
inline Type getType() const { return _type; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores a number.
|
||||
* @return true if se::Value stores a number, otherwise false.
|
||||
*/
|
||||
inline bool isNumber() const { return _type == Type::Number; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores a string.
|
||||
* @return true if se::Value stores a string, otherwise false.
|
||||
*/
|
||||
inline bool isString() const { return _type == Type::String; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores an object.
|
||||
* @return true if se::Value stores an object, otherwise false.
|
||||
*/
|
||||
inline bool isObject() const { return _type == Type::Object; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores a boolean.
|
||||
* @return true if se::Value stores a boolean, otherwise false.
|
||||
*/
|
||||
inline bool isBoolean() const { return _type == Type::Boolean; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores an undefined value.
|
||||
* @return true if se::Value stores an undefined value, otherwise false.
|
||||
*/
|
||||
inline bool isUndefined() const { return _type == Type::Undefined; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores a null value.
|
||||
* @return true if se::Value stores a null value, otherwise false.
|
||||
*/
|
||||
inline bool isNull() const { return _type == Type::Null; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether se::Value stores a null or an undefined value.
|
||||
* @return true if se::Value stores a null or an undefined value, otherwise false.
|
||||
*/
|
||||
inline bool isNullOrUndefined() const { return (isNull() || isUndefined()); }
|
||||
|
||||
private:
|
||||
explicit Value(Type type);
|
||||
void reset(Type type);
|
||||
|
||||
union {
|
||||
bool _boolean;
|
||||
double _number;
|
||||
std::string* _string;
|
||||
Object* _object;
|
||||
} _u;
|
||||
|
||||
Type _type;
|
||||
bool _autoRootUnroot;
|
||||
};
|
||||
|
||||
using ValueArray = std::vector<Value>;
|
||||
extern ValueArray EmptyValueArray;
|
||||
|
||||
} // namespace se {
|
||||
|
||||
typedef se::Object* se_object_ptr;
|
||||
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "ChakraCore.h"
|
||||
#include "ChakraCoreVersion.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <assert.h>
|
||||
|
||||
#include "HelperMacros.h"
|
||||
@@ -0,0 +1,247 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Class.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "State.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../HandleObject.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
#define JS_FN(name, func) {name, func}
|
||||
#define JS_FS_END JS_FN(0, 0)
|
||||
#define JS_PSGS(name, getter, setter) {name, getter, setter}
|
||||
#define JS_PS_END JS_PSGS(0, 0, 0)
|
||||
|
||||
namespace {
|
||||
// std::unordered_map<std::string, Class *> __clsMap;
|
||||
std::vector<Class*> __allClasses;
|
||||
|
||||
JsValueRef emptyContructor(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
|
||||
{
|
||||
return JS_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
void defaultFinalizeCallback(void* nativeThisObject)
|
||||
{
|
||||
if (nativeThisObject != nullptr)
|
||||
{
|
||||
State state(nativeThisObject);
|
||||
Object* _thisObject = state.thisObject();
|
||||
if (_thisObject) _thisObject->_cleanup(nativeThisObject);
|
||||
SAFE_DEC_REF(_thisObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Class::Class()
|
||||
: _parent(nullptr)
|
||||
, _proto(nullptr)
|
||||
, _parentProto(nullptr)
|
||||
, _ctor(nullptr)
|
||||
, _finalizeOp(nullptr)
|
||||
{
|
||||
__allClasses.push_back(this);
|
||||
}
|
||||
|
||||
Class::~Class()
|
||||
{
|
||||
}
|
||||
|
||||
Class* Class::create(const std::string& className, Object* obj, Object* parentProto, JsNativeFunction ctor)
|
||||
{
|
||||
Class* cls = new Class();
|
||||
if (cls != nullptr && !cls->init(className, obj, parentProto, ctor))
|
||||
{
|
||||
delete cls;
|
||||
cls = nullptr;
|
||||
}
|
||||
return cls;
|
||||
}
|
||||
|
||||
bool Class::init(const std::string &clsName, Object* parent, Object *parentProto, JsNativeFunction ctor)
|
||||
{
|
||||
_name = clsName;
|
||||
_parent = parent;
|
||||
if (_parent != nullptr)
|
||||
_parent->incRef();
|
||||
_parentProto = parentProto;
|
||||
|
||||
if (_parentProto != nullptr)
|
||||
_parentProto->incRef();
|
||||
_ctor = ctor;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::install()
|
||||
{
|
||||
JsValueRef funcName;
|
||||
_CHECK(JsCreateString(_name.c_str(), _name.length(), &funcName));
|
||||
JsValueRef jsConstructor;
|
||||
if (_ctor == nullptr)
|
||||
{
|
||||
_ctor = emptyContructor;
|
||||
}
|
||||
_CHECK(JsCreateNamedFunction(funcName, _ctor, nullptr, &jsConstructor));
|
||||
|
||||
HandleObject ctorObj(Object::_createJSObject(nullptr, jsConstructor));
|
||||
|
||||
// create class's prototype and project its member functions
|
||||
JsValueRef prototype;
|
||||
_CHECK(JsCreateObject(&prototype));
|
||||
|
||||
Object* prototypeObj = Object::_createJSObject(this, prototype);
|
||||
prototypeObj->root();
|
||||
|
||||
for (const auto& func : _funcs)
|
||||
{
|
||||
prototypeObj->defineFunction(func.name, func.func);
|
||||
}
|
||||
|
||||
for (const auto& property : _properties)
|
||||
{
|
||||
internal::defineProperty(prototype, property.name, property.getter, property.setter, true, true);
|
||||
}
|
||||
|
||||
prototypeObj->setProperty("constructor", Value(ctorObj));
|
||||
|
||||
ctorObj->setProperty("prototype", Value(prototypeObj));
|
||||
|
||||
if (_parentProto != nullptr)
|
||||
{
|
||||
_CHECK(JsSetPrototype(prototype, _parentProto->_getJSObject()));
|
||||
}
|
||||
|
||||
for (const auto& sfunc : _staticFuncs)
|
||||
{
|
||||
ctorObj->defineFunction(sfunc.name, sfunc.func);
|
||||
}
|
||||
|
||||
for (const auto& property : _staticProperties)
|
||||
{
|
||||
internal::defineProperty(jsConstructor, property.name, property.getter, property.setter, true, true);
|
||||
}
|
||||
|
||||
_proto = prototypeObj;
|
||||
_parent->setProperty(_name.c_str(), Value(ctorObj));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineFunction(const char *name, JsNativeFunction func)
|
||||
{
|
||||
JSFunctionSpec cb = JS_FN(name, func);
|
||||
_funcs.push_back(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter)
|
||||
{
|
||||
JSPropertySpec property = JS_PSGS(name, getter, setter);
|
||||
_properties.push_back(property);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineStaticFunction(const char *name, JsNativeFunction func)
|
||||
{
|
||||
JSFunctionSpec cb = JS_FN(name, func);
|
||||
_staticFuncs.push_back(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineStaticProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter)
|
||||
{
|
||||
JSPropertySpec property = JS_PSGS(name, getter, setter);
|
||||
_staticProperties.push_back(property);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineFinalizeFunction(JsFinalizeCallback func)
|
||||
{
|
||||
_finalizeOp = func;
|
||||
return true;
|
||||
}
|
||||
|
||||
// JsValueRef Class::_createJSObject(const std::string &clsName, Class** outCls)
|
||||
// {
|
||||
// auto iter = __clsMap.find(clsName);
|
||||
// if (iter == __clsMap.end())
|
||||
// {
|
||||
// *outCls = nullptr;
|
||||
// return nullptr;
|
||||
// }
|
||||
//
|
||||
// Class* thiz = iter->second;
|
||||
// *outCls = thiz;
|
||||
// return _createJSObjectWithClass(thiz);
|
||||
// }
|
||||
|
||||
JsValueRef Class::_createJSObjectWithClass(Class* cls)
|
||||
{
|
||||
JsValueRef obj;
|
||||
|
||||
JsFinalizeCallback finalizeCb = cls->_finalizeOp == nullptr ? defaultFinalizeCallback : cls->_finalizeOp;
|
||||
_CHECK(JsCreateExternalObject(nullptr, finalizeCb, &obj));
|
||||
|
||||
_CHECK(JsSetPrototype(obj, cls->getProto()->_getJSObject()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Class::getProto()
|
||||
{
|
||||
return _proto;
|
||||
}
|
||||
|
||||
void Class::destroy()
|
||||
{
|
||||
SAFE_DEC_REF(_parent);
|
||||
SAFE_DEC_REF(_proto);
|
||||
SAFE_DEC_REF(_parentProto);
|
||||
}
|
||||
|
||||
void Class::cleanup()
|
||||
{
|
||||
for (auto cls : __allClasses)
|
||||
{
|
||||
cls->destroy();
|
||||
}
|
||||
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
for (auto cls : __allClasses)
|
||||
{
|
||||
delete cls;
|
||||
}
|
||||
__allClasses.clear();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
@@ -0,0 +1,160 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* se::Class represents a definition of how to create a native binding object.
|
||||
*/
|
||||
class Class final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a class used for creating relevant native binding objects.
|
||||
* @param[in] className A null-terminated UTF8 string containing the class's name.
|
||||
* @param[in] obj The object that current class proto object attaches to. Should not be nullptr.
|
||||
* @param[in] parentProto The parent proto object that current class inherits from. Passing nullptr means a new class has no parent.
|
||||
* @param[in] ctor A callback to invoke when your constructor is used in a 'new' expression. Pass nullptr to use the default object constructor.
|
||||
* @return A class instance used for creating relevant native binding objects.
|
||||
* @note Don't need to delete the pointer return by this method, it's managed internally.
|
||||
*/
|
||||
static Class* create(const std::string& className, Object* obj, Object* parentProto, JsNativeFunction ctor);
|
||||
|
||||
/**
|
||||
* @brief Defines a member function with a callback. Each objects created by class will have this function property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the function name.
|
||||
* @param[in] func A callback to invoke when the property is called as a function.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFunction(const char *name, JsNativeFunction func);
|
||||
|
||||
/**
|
||||
* @brief Defines a property with accessor callbacks. Each objects created by class will have this property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the property name.
|
||||
* @param[in] getter A callback to invoke when the property is read.
|
||||
* @param[in] setter A callback to invoke when the property is set.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter);
|
||||
|
||||
/**
|
||||
* @brief Defines a static function with a callback. Only JavaScript constructor object will have this function.
|
||||
* @param[in] name A null-terminated UTF8 string containing the function name.
|
||||
* @param[in] func A callback to invoke when the constructor's property is called as a function.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineStaticFunction(const char *name, JsNativeFunction func);
|
||||
|
||||
/**
|
||||
* @brief Defines a static property with accessor callbacks. Only JavaScript constructor object will have this property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the property name.
|
||||
* @param[in] getter A callback to invoke when the constructor's property is read.
|
||||
* @param[in] setter A callback to invoke when the constructor's property is set.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineStaticProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter);
|
||||
|
||||
/**
|
||||
* @brief Defines the finalize function with a callback.
|
||||
* @param[in] func The callback to invoke when a JavaScript object is garbage collected.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFinalizeFunction(JsFinalizeCallback func);
|
||||
|
||||
/**
|
||||
* @brief Installs class to JavaScript VM.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note After this method, an object could be created by `var foo = new Foo();`.
|
||||
*/
|
||||
bool install();
|
||||
|
||||
/**
|
||||
* @brief Gets the proto object of this class.
|
||||
* @return The proto object of this class.
|
||||
* @note Don't need to be released in user code.
|
||||
*/
|
||||
Object* getProto();
|
||||
|
||||
/**
|
||||
* @brief Gets the class name.
|
||||
* @return The class name.
|
||||
*/
|
||||
const char* getName() const { return _name.c_str(); }
|
||||
|
||||
private:
|
||||
Class();
|
||||
~Class();
|
||||
|
||||
bool init(const std::string& clsName, Object* obj, Object* parentProto, JsNativeFunction ctor);
|
||||
void destroy();
|
||||
|
||||
// static JsValueRef _createJSObject(const std::string &clsName, Class** outCls);
|
||||
static JsValueRef _createJSObjectWithClass(Class* cls);
|
||||
|
||||
static void cleanup();
|
||||
|
||||
struct JSFunctionSpec
|
||||
{
|
||||
const char* name;
|
||||
JsNativeFunction func;
|
||||
};
|
||||
|
||||
struct JSPropertySpec
|
||||
{
|
||||
const char* name;
|
||||
JsNativeFunction getter;
|
||||
JsNativeFunction setter;
|
||||
};
|
||||
|
||||
std::string _name;
|
||||
Object* _parent;
|
||||
Object* _proto;
|
||||
Object* _parentProto;
|
||||
|
||||
JsNativeFunction _ctor;
|
||||
|
||||
std::vector<JSFunctionSpec> _funcs;
|
||||
std::vector<JSFunctionSpec> _staticFuncs;
|
||||
std::vector<JSPropertySpec> _properties;
|
||||
std::vector<JSPropertySpec> _staticProperties;
|
||||
JsFinalizeCallback _finalizeOp;
|
||||
|
||||
friend class ScriptEngine;
|
||||
friend class Object;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define SE_UNUSED __attribute__ ((unused))
|
||||
#else
|
||||
#define SE_UNUSED
|
||||
#endif
|
||||
|
||||
#define SAFE_INC_REF(obj) if (obj != nullptr) obj->incRef()
|
||||
#define SAFE_DEC_REF(obj) if ((obj) != nullptr) { (obj)->decRef(); (obj) = nullptr; }
|
||||
|
||||
#define _SE(name) name##Registry
|
||||
|
||||
|
||||
#define SE_DECLARE_FUNC(funcName) \
|
||||
JsValueRef funcName##Registry(JsValueRef _callee, bool _isConstructCall, JsValueRef* _argv, unsigned short argc, void* _callbackState)
|
||||
|
||||
#define SE_BIND_FUNC(funcName) \
|
||||
JsValueRef funcName##Registry(JsValueRef _callee, bool _isConstructCall, JsValueRef* _argv, unsigned short argc, void* _callbackState) \
|
||||
{ \
|
||||
assert(argc > 0); \
|
||||
--argc; \
|
||||
JsValueRef _jsRet = JS_INVALID_REFERENCE; \
|
||||
bool ret = true; \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(argc, _argv+1, &args); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_argv[0]); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
se::internal::seToJsValue(state.rval(), &_jsRet); \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
#define SE_BIND_FINALIZE_FUNC(funcName) \
|
||||
void funcName##Registry(void* nativeThisObject) \
|
||||
{ \
|
||||
if (nativeThisObject != nullptr) \
|
||||
{ \
|
||||
auto se = se::ScriptEngine::getInstance(); \
|
||||
se->_setGarbageCollecting(true); \
|
||||
bool ret = false; \
|
||||
se::State state(nativeThisObject); \
|
||||
se::Object* _thisObject = state.thisObject(); \
|
||||
if (_thisObject) _thisObject->_cleanup(nativeThisObject); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
SAFE_DEC_REF(_thisObject); \
|
||||
se->_setGarbageCollecting(false); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SE_DECLARE_FINALIZE_FUNC(funcName) \
|
||||
void funcName##Registry(void* nativeThisObject);
|
||||
|
||||
|
||||
// NOTE: se::Object::createObjectWithClass(cls) will return a se::Object pointer which is watched by garbage collector.
|
||||
// If there is a '_ctor' function of current class, '_property.toObject->call(...)' will be invoked which is an operation that may
|
||||
// make garbage collector to mark the created JS object as a garbage and set it to an invalid state.
|
||||
// If this happens, crash will be triggered. So please take care of the value returned from se::Object::createObjectWithClass.
|
||||
// HOW TO FIX: Use a rooted se::Value to save the se::Object poiner returned by se::Object::createObjectWithClass.
|
||||
#define SE_BIND_CTOR(funcName, cls, finalizeCb) \
|
||||
JsValueRef funcName##Registry(JsValueRef _callee, bool _isConstructCall, JsValueRef* _argv, unsigned short argc, void* _callbackState) \
|
||||
{ \
|
||||
assert(argc > 0); \
|
||||
--argc; \
|
||||
bool ret = true; \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(argc, _argv+1, &args); \
|
||||
se::Value thisVal(se::Object::createObjectWithClass(cls), true); \
|
||||
se::Object* thisObject = thisVal.toObject(); \
|
||||
JsValueRef _jsRet = thisObject->_getJSObject(); \
|
||||
se::State state(thisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (ret) \
|
||||
{ \
|
||||
se::Value _property; \
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
#define SE_BIND_SUB_CLS_CTOR(funcName, cls, finalizeCb) \
|
||||
JsValueRef funcName##Registry(JsValueRef _callee, bool _isConstructCall, JsValueRef* _argv, unsigned short argc, void* _callbackState) \
|
||||
{ \
|
||||
assert(argc > 0); \
|
||||
--argc; \
|
||||
JsValueRef _jsRet = JS_INVALID_REFERENCE; \
|
||||
bool ret = true; \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(argc, _argv+1, &args); \
|
||||
se::Object* thisObject = se::Object::_createJSObject(cls, _argv[0]); \
|
||||
thisObject->_setFinalizeCallback(_SE(finalizeCb)); \
|
||||
se::State state(thisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (ret) \
|
||||
{ \
|
||||
se::Value _property; \
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_PROP_GET(funcName) \
|
||||
JsValueRef funcName##Registry(JsValueRef _callee, bool _isConstructCall, JsValueRef* _argv, unsigned short _argc, void* _callbackState) \
|
||||
{ \
|
||||
assert(_argc == 1); \
|
||||
JsValueRef _jsRet = JS_INVALID_REFERENCE; \
|
||||
bool ret = true; \
|
||||
void* nativeThisObject = se::internal::getPrivate(_argv[0]); \
|
||||
se::State state(nativeThisObject); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
se::internal::seToJsValue(state.rval(), &_jsRet); \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_PROP_SET(funcName) \
|
||||
JsValueRef funcName##Registry(JsValueRef _callee, bool _isConstructCall, JsValueRef* _argv, unsigned short _argc, void* _callbackState) \
|
||||
{ \
|
||||
assert(_argc == 2); \
|
||||
bool ret = true; \
|
||||
void* nativeThisObject = se::internal::getPrivate(_argv[0]); \
|
||||
se::Value data; \
|
||||
se::internal::jsToSeValue(_argv[1], &data); \
|
||||
se::ValueArray args; \
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return JS_INVALID_REFERENCE; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_TYPE_NAME(t) typeid(t).name()
|
||||
|
||||
#define SE_QUOTEME_(x) #x
|
||||
#define SE_QUOTEME(x) SE_QUOTEME_(x)
|
||||
|
||||
//IDEA: implement this macro
|
||||
#define SE_REPORT_ERROR(fmt, ...) SE_LOGE("[ERROR] (" __FILE__ ", " SE_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
#if COCOS2D_DEBUG > 0
|
||||
|
||||
#define SE_ASSERT(cond, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (!(cond)) \
|
||||
{ \
|
||||
SE_LOGE("ASSERT (" __FILE__ ", " SE_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__); \
|
||||
assert(false); \
|
||||
} \
|
||||
} while(false)
|
||||
|
||||
#else
|
||||
|
||||
#define SE_ASSERT(cond, fmt, ...)
|
||||
|
||||
#endif // #if COCOS2D_DEBUG > 0
|
||||
|
||||
#define _CHECK(cmd) \
|
||||
do \
|
||||
{ \
|
||||
JsErrorCode _errCode = cmd; \
|
||||
if (_errCode != JsNoError) \
|
||||
{ \
|
||||
SE_LOGE("Error 0x%x at '%s, %s, %d'\n", \
|
||||
_errCode, #cmd, __FILE__, __LINE__); \
|
||||
assert(false); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
@@ -0,0 +1,811 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Object.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
Object::Object()
|
||||
: _cls(nullptr)
|
||||
, _obj(JS_INVALID_REFERENCE)
|
||||
, _privateData(nullptr)
|
||||
, _finalizeCb(nullptr)
|
||||
, _rootCount(0)
|
||||
, _isCleanup(false)
|
||||
{
|
||||
_currentVMId = ScriptEngine::getInstance()->getVMId();
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
{
|
||||
_cleanup();
|
||||
}
|
||||
|
||||
Object* Object::createPlainObject()
|
||||
{
|
||||
JsValueRef jsobj;
|
||||
_CHECK(JsCreateObject(&jsobj));
|
||||
Object* obj = _createJSObject(nullptr, jsobj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createArrayObject(size_t length)
|
||||
{
|
||||
JsValueRef jsObj = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreateArray((unsigned int)length, &jsObj));
|
||||
Object* obj = _createJSObject(nullptr, jsObj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createArrayBufferObject(void* data, size_t byteLength)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
JsValueRef jsobj;
|
||||
_CHECK(JsCreateArrayBuffer((unsigned int)byteLength, &jsobj));
|
||||
ChakraBytePtr buffer = nullptr;
|
||||
unsigned int bufferLength = 0;
|
||||
if (JsNoError == JsGetArrayBufferStorage(jsobj, &buffer, &bufferLength))
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
memcpy((void*)buffer, data, byteLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset((void*)buffer, 0, byteLength);
|
||||
}
|
||||
obj = Object::_createJSObject(nullptr, jsobj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createTypedArray(TypedArrayType type, void* data, size_t byteLength)
|
||||
{
|
||||
if (type == TypedArrayType::NONE)
|
||||
{
|
||||
SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (type == TypedArrayType::UINT8_CLAMPED)
|
||||
{
|
||||
SE_LOGE("Doesn't support to create Uint8ClampedArray with Object::createTypedArray API!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JsTypedArrayType typedArrayType;
|
||||
size_t elementLength = 0;
|
||||
|
||||
switch (type) {
|
||||
case TypedArrayType::INT8:
|
||||
typedArrayType = JsArrayTypeInt8;
|
||||
elementLength = byteLength;
|
||||
break;
|
||||
case TypedArrayType::INT16:
|
||||
typedArrayType = JsArrayTypeInt16;
|
||||
elementLength = byteLength / 2;
|
||||
break;
|
||||
case TypedArrayType::INT32:
|
||||
typedArrayType = JsArrayTypeInt32;
|
||||
elementLength = byteLength / 4;
|
||||
break;
|
||||
case TypedArrayType::UINT8:
|
||||
typedArrayType = JsArrayTypeUint8;
|
||||
elementLength = byteLength;
|
||||
break;
|
||||
case TypedArrayType::UINT16:
|
||||
typedArrayType = JsArrayTypeUint16;
|
||||
elementLength = byteLength / 2;
|
||||
break;
|
||||
case TypedArrayType::UINT32:
|
||||
typedArrayType = JsArrayTypeUint32;
|
||||
elementLength = byteLength / 4;
|
||||
break;
|
||||
case TypedArrayType::FLOAT32:
|
||||
typedArrayType = JsArrayTypeFloat32;
|
||||
elementLength = byteLength / 4;
|
||||
break;
|
||||
case TypedArrayType::FLOAT64:
|
||||
typedArrayType = JsArrayTypeFloat64;
|
||||
elementLength = byteLength / 8;
|
||||
break;
|
||||
default:
|
||||
assert(false); // Should never go here.
|
||||
break;
|
||||
}
|
||||
|
||||
Object* obj = nullptr;
|
||||
JsValueRef jsobj;
|
||||
_CHECK(JsCreateTypedArray(typedArrayType, JS_INVALID_REFERENCE, 0, (unsigned int)elementLength, &jsobj));
|
||||
ChakraBytePtr buffer = nullptr;
|
||||
unsigned int bufferLength = 0;
|
||||
JsTypedArrayType arrType;
|
||||
int elementSize = 0;
|
||||
if (JsNoError == JsGetTypedArrayStorage(jsobj, &buffer, &bufferLength, &arrType, &elementSize))
|
||||
{
|
||||
//If data has content,then will copy data into buffer,or will only clear buffer.
|
||||
if (data) {
|
||||
memcpy((void*)buffer, data, byteLength);
|
||||
}else{
|
||||
memset((void*)buffer, 0, byteLength);
|
||||
}
|
||||
|
||||
obj = Object::_createJSObject(nullptr, jsobj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createUint8TypedArray(uint8_t* data, size_t dataCount)
|
||||
{
|
||||
return createTypedArray(TypedArrayType::UINT8, data, dataCount);
|
||||
}
|
||||
|
||||
Object* Object::createJSONObject(const std::string& jsonStr)
|
||||
{
|
||||
bool ok = false;
|
||||
Object* obj = nullptr;
|
||||
|
||||
Object* global = ScriptEngine::getInstance()->getGlobalObject();
|
||||
Value jsonVal;
|
||||
ok = global->getProperty("JSON", &jsonVal);
|
||||
assert(ok);
|
||||
|
||||
Value parseVal;
|
||||
ok = jsonVal.toObject()->getProperty("parse", &parseVal);
|
||||
assert(ok);
|
||||
|
||||
Value ret;
|
||||
ValueArray args;
|
||||
args.push_back(Value(jsonStr));
|
||||
if (parseVal.toObject()->call(args, jsonVal.toObject(), &ret))
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, ret.toObject());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::getObjectWithPtr(void* ptr)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
auto iter = NativePtrToObjectMap::find(ptr);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
obj->incRef();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::_createJSObject(Class* cls, JsValueRef obj)
|
||||
{
|
||||
Object* ret = new Object();
|
||||
if (!ret->init(obj))
|
||||
{
|
||||
delete ret;
|
||||
ret = nullptr;
|
||||
}
|
||||
|
||||
ret->_cls = cls;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object* Object::createObjectWithClass(Class* cls)
|
||||
{
|
||||
JsValueRef jsobj = Class::_createJSObjectWithClass(cls);
|
||||
Object* obj = Object::_createJSObject(cls, jsobj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
bool Object::init(JsValueRef obj)
|
||||
{
|
||||
_obj = obj;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Object::_cleanup(void* nativeObject/* = nullptr*/)
|
||||
{
|
||||
if (_isCleanup)
|
||||
return;
|
||||
|
||||
auto se = ScriptEngine::getInstance();
|
||||
if (_currentVMId == se->getVMId())
|
||||
{
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
if (_obj != nullptr)
|
||||
{
|
||||
if (nativeObject == nullptr)
|
||||
{
|
||||
nativeObject = internal::getPrivate(_obj);
|
||||
}
|
||||
|
||||
if (nativeObject != nullptr)
|
||||
{
|
||||
auto iter = NativePtrToObjectMap::find(nativeObject);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
NativePtrToObjectMap::erase(iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_rootCount > 0)
|
||||
{
|
||||
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
|
||||
if (!se->isInCleanup() && !se->isGarbageCollecting())
|
||||
{
|
||||
unsigned int count = 0;
|
||||
_CHECK(JsRelease(_obj, &count));
|
||||
}
|
||||
_rootCount = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SE_LOGD("Object::_cleanup, ScriptEngine was initialized again, ignore cleanup work, oldVMId: %u, newVMId: %u\n", _currentVMId, se->getVMId());
|
||||
}
|
||||
|
||||
_isCleanup = true;
|
||||
}
|
||||
|
||||
void Object::cleanup()
|
||||
{
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
const auto& instance = NativePtrToObjectMap::instance();
|
||||
se::Object* obj = nullptr;
|
||||
for (const auto& e : instance)
|
||||
{
|
||||
obj = e.second;
|
||||
obj->_isCleanup = true; // _cleanup will invoke NativePtrToObjectMap::erase method which will break this for loop. It isn't needed at ScriptEngine::cleanup step.
|
||||
obj->decRef();
|
||||
}
|
||||
NativePtrToObjectMap::clear();
|
||||
NonRefNativePtrCreatedByCtorMap::clear();
|
||||
});
|
||||
}
|
||||
|
||||
void Object::_setFinalizeCallback(JsFinalizeCallback finalizeCb)
|
||||
{
|
||||
_finalizeCb = finalizeCb;
|
||||
}
|
||||
|
||||
bool Object::getProperty(const char* name, Value* data)
|
||||
{
|
||||
assert(data != nullptr);
|
||||
data->setUndefined();
|
||||
|
||||
JsPropertyIdRef propertyId;
|
||||
_CHECK(JsCreatePropertyId(name, strlen(name), &propertyId));
|
||||
|
||||
bool exist = false;
|
||||
JsHasProperty(_obj, propertyId, &exist);
|
||||
|
||||
if (exist)
|
||||
{
|
||||
JsValueRef jsValue;
|
||||
_CHECK(JsGetProperty(_obj, propertyId, &jsValue));
|
||||
internal::jsToSeValue(jsValue, data);
|
||||
}
|
||||
|
||||
return exist;
|
||||
}
|
||||
|
||||
bool Object::setProperty(const char* name, const Value& v)
|
||||
{
|
||||
JsValueRef jsValue = JS_INVALID_REFERENCE;
|
||||
internal::seToJsValue(v, &jsValue);
|
||||
JsPropertyIdRef propertyId;
|
||||
_CHECK(JsCreatePropertyId(name, strlen(name), &propertyId));
|
||||
_CHECK(JsSetProperty(_obj, propertyId, jsValue, true));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter)
|
||||
{
|
||||
return internal::defineProperty(_obj, name, getter, setter, true, true);
|
||||
}
|
||||
|
||||
bool Object::call(const ValueArray& args, Object* thisObject, Value* rval/* = nullptr*/)
|
||||
{
|
||||
assert(isFunction());
|
||||
|
||||
JsValueRef contextObject;
|
||||
|
||||
if (thisObject != nullptr)
|
||||
{
|
||||
contextObject = thisObject->_obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
_CHECK(JsGetUndefinedValue(&contextObject));
|
||||
}
|
||||
|
||||
JsValueRef* jsArgs = (JsValueRef*)malloc(sizeof(JsValueRef) * (args.size() + 1)); // Requires thisArg as first argument of arguments.
|
||||
|
||||
std::vector<Object*> toUnrootedObjects;
|
||||
|
||||
for (auto& arg : args)
|
||||
{
|
||||
if (arg.isObject())
|
||||
{
|
||||
if (!arg.toObject()->isRooted())
|
||||
{
|
||||
arg.toObject()->root();
|
||||
toUnrootedObjects.push_back(arg.toObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!args.empty())
|
||||
{
|
||||
internal::seToJsArgs(args, jsArgs + 1);
|
||||
}
|
||||
|
||||
jsArgs[0] = contextObject;
|
||||
|
||||
JsValueRef rcValue = JS_INVALID_REFERENCE;
|
||||
JsErrorCode errCode = JsCallFunction(_obj, jsArgs, args.size() + 1, &rcValue);
|
||||
free(jsArgs);
|
||||
|
||||
for (auto& obj: toUnrootedObjects)
|
||||
{
|
||||
obj->unroot();
|
||||
}
|
||||
|
||||
if (errCode == JsNoError)
|
||||
{
|
||||
if (rval != nullptr)
|
||||
{
|
||||
JsValueType type;
|
||||
JsGetValueType(rcValue, &type);
|
||||
if (rval != JS_INVALID_REFERENCE && type != JsUndefined)
|
||||
{
|
||||
internal::jsToSeValue(rcValue, rval);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Object::defineFunction(const char* funcName, JsNativeFunction func)
|
||||
{
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreatePropertyId(funcName, strlen(funcName), &propertyId));
|
||||
|
||||
JsValueRef funcVal = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreateFunction(func, nullptr, &funcVal));
|
||||
|
||||
_CHECK(JsSetProperty(_obj, propertyId, funcVal, true));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isArrayOfObject(JsValueRef obj)
|
||||
{
|
||||
JsValueType type;
|
||||
if (JsNoError == JsGetValueType(obj, &type))
|
||||
{
|
||||
return type == JsArray;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool getArrayLengthOfObject(JsValueRef arrObj, uint32_t* length)
|
||||
{
|
||||
assert(isArrayOfObject(arrObj));
|
||||
assert(length != nullptr);
|
||||
|
||||
JsErrorCode err = JsNoError;
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
const char* lengthName = "length";
|
||||
err = JsCreatePropertyId(lengthName, strlen(lengthName), &propertyId);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
JsValueRef jsLen = JS_INVALID_REFERENCE;
|
||||
err = JsGetProperty(arrObj, propertyId, &jsLen);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
int intVal = 0;
|
||||
err = JsNumberToInt(jsLen, &intVal);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
*length = (uint32_t)intVal;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::isArray() const
|
||||
{
|
||||
return isArrayOfObject(_obj);
|
||||
}
|
||||
|
||||
bool Object::getArrayLength(uint32_t* length) const
|
||||
{
|
||||
return getArrayLengthOfObject(_obj, length);
|
||||
}
|
||||
|
||||
bool Object::getArrayElement(uint32_t index, Value* data) const
|
||||
{
|
||||
assert(isArray());
|
||||
assert(data != nullptr);
|
||||
|
||||
JsErrorCode err = JsNoError;
|
||||
JsValueRef result = JS_INVALID_REFERENCE;
|
||||
JsValueRef jsIndex = JS_INVALID_REFERENCE;
|
||||
err = JsIntToNumber(index, &jsIndex);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
err = JsGetIndexedProperty(_obj, jsIndex, &result);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
internal::jsToSeValue(result, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::setArrayElement(uint32_t index, const Value& data)
|
||||
{
|
||||
assert(isArray());
|
||||
|
||||
JsErrorCode err = JsNoError;
|
||||
JsValueRef jsIndex = JS_INVALID_REFERENCE;
|
||||
err = JsIntToNumber(index, &jsIndex);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
JsValueRef value = JS_INVALID_REFERENCE;
|
||||
internal::seToJsValue(data, &value);
|
||||
|
||||
err = JsSetIndexedProperty(_obj, jsIndex, value);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::getAllKeys(std::vector<std::string>* allKeys) const
|
||||
{
|
||||
assert(allKeys != nullptr);
|
||||
|
||||
JsErrorCode err = JsNoError;
|
||||
JsValueRef keys = JS_INVALID_REFERENCE;
|
||||
err = JsGetOwnPropertyNames(_obj, &keys);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
uint32_t len = 0;
|
||||
bool ok = false;
|
||||
ok = getArrayLengthOfObject(keys, &len);
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
std::string key;
|
||||
for (uint32_t index = 0; index < len; ++index)
|
||||
{
|
||||
JsValueRef indexValue = JS_INVALID_REFERENCE;
|
||||
err = JsIntToNumber(index, &indexValue);
|
||||
if (err != JsNoError)
|
||||
return false;
|
||||
|
||||
JsValueRef nameValue = JS_INVALID_REFERENCE;
|
||||
JsGetIndexedProperty(keys, indexValue, &nameValue);
|
||||
|
||||
internal::jsStringToStdString(nameValue, &key);
|
||||
allKeys->push_back(key);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::isFunction() const
|
||||
{
|
||||
JsValueType type;
|
||||
_CHECK(JsGetValueType(_obj, &type));
|
||||
if (_obj != JS_INVALID_REFERENCE && type == JsFunction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Object::_isNativeFunction() const
|
||||
{
|
||||
if (isFunction())
|
||||
{
|
||||
std::string info = toString();
|
||||
if (info.find("[native code]") != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Object::isTypedArray() const
|
||||
{
|
||||
JsValueType type;
|
||||
if (JsNoError == JsGetValueType(_obj, &type))
|
||||
{
|
||||
return type == JsTypedArray;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Object::TypedArrayType Object::getTypedArrayType() const
|
||||
{
|
||||
TypedArrayType ret = TypedArrayType::NONE;
|
||||
if (!isTypedArray())
|
||||
return ret;
|
||||
|
||||
JsTypedArrayType type;
|
||||
JsValueRef arrayBuffer = JS_INVALID_REFERENCE;
|
||||
unsigned int byteOffset = 0;
|
||||
unsigned int byteLength = 0;
|
||||
|
||||
if (JsNoError == JsGetTypedArrayInfo(_obj, &type, &arrayBuffer, &byteOffset, &byteLength))
|
||||
{
|
||||
if (type == JsArrayTypeInt8)
|
||||
ret = TypedArrayType::INT8;
|
||||
else if (type == JsArrayTypeInt16)
|
||||
ret = TypedArrayType::INT16;
|
||||
else if (type == JsArrayTypeInt32)
|
||||
ret = TypedArrayType::INT32;
|
||||
else if (type == JsArrayTypeUint8)
|
||||
ret = TypedArrayType::UINT8;
|
||||
else if (type == JsArrayTypeUint8Clamped)
|
||||
ret = TypedArrayType::UINT8_CLAMPED;
|
||||
else if (type == JsArrayTypeUint16)
|
||||
ret = TypedArrayType::UINT16;
|
||||
else if (type == JsArrayTypeUint32)
|
||||
ret = TypedArrayType::UINT32;
|
||||
else if (type == JsArrayTypeFloat32)
|
||||
ret = TypedArrayType::FLOAT32;
|
||||
else if (type == JsArrayTypeFloat64)
|
||||
ret = TypedArrayType::FLOAT64;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Object::getTypedArrayData(uint8_t** ptr, size_t* length) const
|
||||
{
|
||||
assert(isTypedArray());
|
||||
JsTypedArrayType arrayType;
|
||||
ChakraBytePtr buffer = nullptr;
|
||||
unsigned int bufferLength = 0;
|
||||
int elementSize = 0;
|
||||
bool ret = false;
|
||||
if (JsNoError == JsGetTypedArrayStorage(_obj, &buffer, &bufferLength, &arrayType, &elementSize))
|
||||
{
|
||||
*ptr = buffer;
|
||||
*length = bufferLength;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr = nullptr;
|
||||
*length = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Object::isArrayBuffer() const
|
||||
{
|
||||
JsValueType type;
|
||||
if (JsNoError == JsGetValueType(_obj, &type))
|
||||
{
|
||||
return type == JsArrayBuffer;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Object::getArrayBufferData(uint8_t** ptr, size_t* length) const
|
||||
{
|
||||
assert(isArrayBuffer());
|
||||
ChakraBytePtr buffer = nullptr;
|
||||
unsigned int bufferLength = 0;
|
||||
bool ret = false;
|
||||
if (JsNoError == JsGetArrayBufferStorage(_obj, &buffer, &bufferLength))
|
||||
{
|
||||
*ptr = buffer;
|
||||
*length = bufferLength;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr = nullptr;
|
||||
*length = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* Object::getPrivateData() const
|
||||
{
|
||||
if (_privateData == nullptr)
|
||||
{
|
||||
const_cast<Object*>(this)->_privateData = internal::getPrivate(_obj);
|
||||
}
|
||||
return _privateData;
|
||||
}
|
||||
|
||||
void Object::setPrivateData(void* data)
|
||||
{
|
||||
assert(_privateData == nullptr);
|
||||
assert(NativePtrToObjectMap::find(data) == NativePtrToObjectMap::end());
|
||||
internal::setPrivate(_obj, data, _finalizeCb);
|
||||
NativePtrToObjectMap::emplace(data, this);
|
||||
_privateData = data;
|
||||
}
|
||||
|
||||
void Object::clearPrivateData(bool clearMapping)
|
||||
{
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
if (clearMapping)
|
||||
NativePtrToObjectMap::erase(_privateData);
|
||||
internal::clearPrivate(_obj);
|
||||
_privateData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
JsValueRef Object::_getJSObject() const
|
||||
{
|
||||
return _obj;
|
||||
}
|
||||
|
||||
Class* Object::_getClass() const
|
||||
{
|
||||
return _cls;
|
||||
}
|
||||
|
||||
void Object::root()
|
||||
{
|
||||
if (_rootCount == 0)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
_CHECK(JsAddRef(_obj, &count));
|
||||
}
|
||||
++_rootCount;
|
||||
}
|
||||
|
||||
void Object::unroot()
|
||||
{
|
||||
if (_rootCount > 0)
|
||||
{
|
||||
--_rootCount;
|
||||
if (_rootCount == 0)
|
||||
{
|
||||
// Don't unprotect if it's in cleanup, otherwise, it will trigger crash.
|
||||
auto se = ScriptEngine::getInstance();
|
||||
if (_currentVMId == se->getVMId())
|
||||
{
|
||||
if (!se->isInCleanup() && !se->isGarbageCollecting())
|
||||
{
|
||||
unsigned int count = 0;
|
||||
_CHECK(JsRelease(_obj, &count));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SE_LOGD("Object::unroot, ScriptEngine was initialized again, ignore cleanup work, oldVMId: %u, newVMId: %u\n", _currentVMId, se->getVMId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Object::isRooted() const
|
||||
{
|
||||
return _rootCount > 0;
|
||||
}
|
||||
|
||||
bool Object::strictEquals(Object* o) const
|
||||
{
|
||||
bool same = false;
|
||||
_CHECK(JsStrictEquals(_obj, o->_obj, &same));
|
||||
return same;
|
||||
}
|
||||
|
||||
bool Object::attachObject(Object* obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
||||
Object* global = ScriptEngine::getInstance()->getGlobalObject();
|
||||
Value jsbVal;
|
||||
if (!global->getProperty("jsb", &jsbVal))
|
||||
return false;
|
||||
Object* jsbObj = jsbVal.toObject();
|
||||
|
||||
Value func;
|
||||
|
||||
if (!jsbObj->getProperty("registerNativeRef", &func))
|
||||
return false;
|
||||
|
||||
ValueArray args;
|
||||
args.push_back(Value(this));
|
||||
args.push_back(Value(obj));
|
||||
func.toObject()->call(args, global);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::detachObject(Object* obj)
|
||||
{
|
||||
assert(obj);
|
||||
Object* global = ScriptEngine::getInstance()->getGlobalObject();
|
||||
Value jsbVal;
|
||||
if (!global->getProperty("jsb", &jsbVal))
|
||||
return false;
|
||||
Object* jsbObj = jsbVal.toObject();
|
||||
|
||||
Value func;
|
||||
|
||||
if (!jsbObj->getProperty("unregisterNativeRef", &func))
|
||||
return false;
|
||||
|
||||
ValueArray args;
|
||||
args.push_back(Value(this));
|
||||
args.push_back(Value(obj));
|
||||
func.toObject()->call(args, global);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Object::toString() const
|
||||
{
|
||||
std::string ret;
|
||||
if (isFunction() || isArray() || isTypedArray())
|
||||
{
|
||||
internal::forceConvertJsValueToStdString(_obj, &ret);
|
||||
}
|
||||
else if (isArrayBuffer())
|
||||
{
|
||||
ret = "[object ArrayBuffer]";
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = "[object Object]";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
@@ -0,0 +1,386 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Base.h"
|
||||
#include "../Value.hpp"
|
||||
#include "../RefCounter.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Class;
|
||||
|
||||
/**
|
||||
* se::Object represents JavaScript Object.
|
||||
*/
|
||||
class Object final : public RefCounter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a JavaScript Object like `{} or new Object()`.
|
||||
* @return A JavaScript Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createPlainObject();
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Array Object like `[] or new Array()`.
|
||||
* @param[in] length The initical length of array.
|
||||
* @return A JavaScript Array Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createArrayObject(size_t length);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Typed Array Object with uint8 format from an existing pointer.
|
||||
* @param[in] bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object.
|
||||
* @param[in] byteLength The number of bytes pointed to by the parameter bytes.
|
||||
* @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
SE_DEPRECATED_ATTRIBUTE static Object* createUint8TypedArray(uint8_t* bytes, size_t byteLength);
|
||||
|
||||
enum class TypedArrayType
|
||||
{
|
||||
NONE,
|
||||
INT8,
|
||||
INT16,
|
||||
INT32,
|
||||
UINT8,
|
||||
UINT8_CLAMPED,
|
||||
UINT16,
|
||||
UINT32,
|
||||
FLOAT32,
|
||||
FLOAT64
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Typed Array Object with specified format from an existing pointer,
|
||||
if provide a null pointer,then will create a empty JavaScript Typed Array Object.
|
||||
* @param[in] type The format of typed array.
|
||||
* @param[in] data A pointer to the byte buffer to be used as the backing store of the Typed Array object.
|
||||
* @param[in] byteLength The number of bytes pointed to by the parameter bytes.
|
||||
* @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createTypedArray(TypedArrayType type, void* data, size_t byteLength);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Array Buffer object from an existing pointer.
|
||||
* @param[in] bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object.
|
||||
* @param[in] byteLength The number of bytes pointed to by the parameter bytes.
|
||||
* @return A Array Buffer Object whose backing store is the same as the one pointed to data, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createArrayBufferObject(void* bytes, size_t byteLength);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Object from a JSON formatted string.
|
||||
* @param[in] jsonStr The utf-8 string containing the JSON string to be parsed.
|
||||
* @return A JavaScript Object containing the parsed value, or nullptr if the input is invalid.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createJSONObject(const std::string& jsonStr);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Native Binding Object from an existing se::Class instance.
|
||||
* @param[in] cls The se::Class instance which stores native callback informations.
|
||||
* @return A JavaScript Native Binding Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createObjectWithClass(Class* cls);
|
||||
|
||||
/**
|
||||
* @brief Gets a se::Object from an existing native object pointer.
|
||||
* @param[in] ptr The native object pointer associated with the se::Object
|
||||
* @return A JavaScript Native Binding Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* getObjectWithPtr(void* ptr);
|
||||
|
||||
/**
|
||||
* @brief Gets a property from an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @param[out] value The property's value if object has the property, otherwise the undefined value.
|
||||
* @return true if object has the property, otherwise false.
|
||||
*/
|
||||
bool getProperty(const char* name, Value* value);
|
||||
|
||||
/**
|
||||
* @brief Sets a property to an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @param[in] value A value to be used as the property's value.
|
||||
* @return true if the property is set successfully, otherwise false.
|
||||
*/
|
||||
bool setProperty(const char* name, const Value& value);
|
||||
|
||||
/**
|
||||
* @brief Defines a property with native accessor callbacks for an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @param[in] getter The native callback for getter.
|
||||
* @param[in] setter The native callback for setter.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineProperty(const char *name, JsNativeFunction getter, JsNativeFunction setter);
|
||||
|
||||
/**
|
||||
* @brief Defines a function with a native callback for an object.
|
||||
* @param[in] funcName A utf-8 string containing the function name.
|
||||
* @param[in] func The native callback triggered by JavaScript code.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFunction(const char *funcName, JsNativeFunction func);
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object can be called as a function.
|
||||
* @return true if object can be called as a function, otherwise false.
|
||||
*/
|
||||
bool isFunction() const;
|
||||
|
||||
/**
|
||||
* @brief Calls an object as a function.
|
||||
* @param[in] args A se::Value array of arguments to pass to the function. Pass se::EmptyValueArray if argumentCount is 0.
|
||||
* @param[in] thisObject The object to use as "this," or NULL to use the global object as "this."
|
||||
* @param[out] rval The se::Value that results from calling object as a function, passing nullptr if return value is ignored.
|
||||
* @return true if object is a function and there isn't any errors, otherwise false.
|
||||
*/
|
||||
bool call(const ValueArray& args, Object* thisObject, Value* rval = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object is an array.
|
||||
* @return true if object is an array, otherwise false.
|
||||
*/
|
||||
bool isArray() const;
|
||||
|
||||
/**
|
||||
* @brief Gets array length of an array object.
|
||||
* @param[out] length The array length to be stored. It's set to 0 if there is an error.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getArrayLength(uint32_t* length) const;
|
||||
|
||||
/**
|
||||
* @brief Gets an element from an array object by numeric index.
|
||||
* @param[in] index An integer value for index.
|
||||
* @param[out] data The se::Value to be stored for the element in certain index.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getArrayElement(uint32_t index, Value* data) const;
|
||||
|
||||
/**
|
||||
* @brief Sets an element to an array object by numeric index.
|
||||
* @param[in] index An integer value for index.
|
||||
* @param[in] data The se::Value to be set to array with certain index.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool setArrayElement(uint32_t index, const Value& data);
|
||||
|
||||
/** @brief Tests whether an object is a typed array.
|
||||
* @return true if object is a typed array, otherwise false.
|
||||
*/
|
||||
bool isTypedArray() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the type of a typed array object.
|
||||
* @return The type of a typed array object.
|
||||
*/
|
||||
TypedArrayType getTypedArrayType() const;
|
||||
|
||||
/**
|
||||
* @brief Gets backing store of a typed array object.
|
||||
* @param[out] ptr A temporary pointer to the backing store of a JavaScript Typed Array object.
|
||||
* @param[out] length The byte length of a JavaScript Typed Array object.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getTypedArrayData(uint8_t** ptr, size_t* length) const;
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object is an array buffer object.
|
||||
* @return true if object is an array buffer object, otherwise false.
|
||||
*/
|
||||
bool isArrayBuffer() const;
|
||||
|
||||
/**
|
||||
* @brief Gets buffer data of an array buffer object.
|
||||
* @param[out] ptr A pointer to the data buffer that serves as the backing store for a JavaScript Typed Array object.
|
||||
* @param[out] length The number of bytes in a JavaScript data object.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getArrayBufferData(uint8_t** ptr, size_t* length) const;
|
||||
|
||||
/**
|
||||
* @brief Gets all property names of an object.
|
||||
* @param[out] allKeys A string vector to store all property names.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getAllKeys(std::vector<std::string>* allKeys) const;
|
||||
|
||||
/**
|
||||
* @brief Sets a pointer to private data on an object.
|
||||
* @param[in] data A void* to set as the object's private data.
|
||||
* @note This method will associate private data with se::Object by std::unordered_map::emplace.
|
||||
* It's used for search a se::Object via a void* private data.
|
||||
*/
|
||||
void setPrivateData(void* data);
|
||||
|
||||
/**
|
||||
* @brief Gets an object's private data.
|
||||
* @return A void* that is the object's private data, if the object has private data, otherwise nullptr.
|
||||
*/
|
||||
void* getPrivateData() const;
|
||||
|
||||
/**
|
||||
* @brief Clears private data of an object.
|
||||
* @param clearMapping Whether to clear the mapping of native object & se::Object.
|
||||
*/
|
||||
void clearPrivateData(bool clearMapping = true);
|
||||
|
||||
/**
|
||||
* @brief Roots an object from garbage collection.
|
||||
* @note Use this method when you want to store an object in a global or on the heap, where the garbage collector will not be able to discover your reference to it.
|
||||
* An object may be rooted multiple times and must be unrooted an equal number of times before becoming eligible for garbage collection.
|
||||
*/
|
||||
void root();
|
||||
|
||||
/**
|
||||
* @brief Unroots an object from garbage collection.
|
||||
* @note An object may be rooted multiple times and must be unrooted an equal number of times before becoming eligible for garbage collection.
|
||||
*/
|
||||
void unroot();
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object is rooted.
|
||||
* @return true if it has been already rooted, otherwise false.
|
||||
*/
|
||||
bool isRooted() const;
|
||||
|
||||
/**
|
||||
* @brief Tests whether two objects are strict equal, as compared by the JS === operator.
|
||||
* @param[in] o The object to be tested with this object.
|
||||
* @return true if the two values are strict equal, otherwise false.
|
||||
*/
|
||||
bool strictEquals(Object* obj) const;
|
||||
|
||||
/**
|
||||
* @brief Attaches an object to current object.
|
||||
* @param[in] obj The object to be attached.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note This method will set `obj` as a property of current object, therefore the lifecycle of child object will depend on current object,
|
||||
* which means `obj` may be garbage collected only after current object is garbage collected.
|
||||
* It's normally used in binding a native callback method. For example:
|
||||
|
||||
```javascript
|
||||
var self = this;
|
||||
someObject.setCallback(function(){}, self);
|
||||
```
|
||||
|
||||
```c++
|
||||
static bool SomeObject_setCallback(se::State& s)
|
||||
{
|
||||
SomeObject* cobj = (SomeObject*)s.nativeThisObject();
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 2) {
|
||||
std::function<void()> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(args[1]);
|
||||
se::Value jsFunc(args[0]);
|
||||
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
|
||||
auto lambda = [=]() -> void {
|
||||
...
|
||||
// Call jsFunc stuff...
|
||||
...
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
cobj->setCallback(arg0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
```
|
||||
*/
|
||||
bool attachObject(Object* obj);
|
||||
|
||||
/**
|
||||
* @brief Detaches an object from current object.
|
||||
* @param[in] obj The object to be detached.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note The attached object will not be released if current object is not garbage collected.
|
||||
*/
|
||||
bool detachObject(Object* obj);
|
||||
|
||||
/**
|
||||
* @brief Returns the string for describing current object.
|
||||
* @return The string for describing current object.
|
||||
*/
|
||||
std::string toString() const;
|
||||
|
||||
// Private API used in wrapper
|
||||
static Object* _createJSObject(Class* cls, JsValueRef obj);
|
||||
JsValueRef _getJSObject() const;
|
||||
Class* _getClass() const;
|
||||
void _cleanup(void* nativeObject = nullptr);
|
||||
void _setFinalizeCallback(JsFinalizeCallback finalizeCb);
|
||||
bool _isNativeFunction() const;
|
||||
//
|
||||
private:
|
||||
static void cleanup();
|
||||
|
||||
Object();
|
||||
virtual ~Object();
|
||||
bool init(JsValueRef obj);
|
||||
|
||||
Class* _cls;
|
||||
JsValueRef _obj;
|
||||
void* _privateData;
|
||||
JsFinalizeCallback _finalizeCb;
|
||||
|
||||
uint32_t _rootCount;
|
||||
uint32_t _currentVMId;
|
||||
bool _isCleanup;
|
||||
|
||||
friend class ScriptEngine;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
@@ -0,0 +1,539 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "../State.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
Class* __jsb_CCPrivateData_class = nullptr;
|
||||
|
||||
namespace {
|
||||
ScriptEngine* __instance = nullptr;
|
||||
|
||||
JsValueRef __forceGC(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
|
||||
{
|
||||
ScriptEngine::getInstance()->garbageCollect();
|
||||
return JS_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
JsValueRef __log(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
|
||||
{
|
||||
if (argumentCount > 1)
|
||||
{
|
||||
std::string str;
|
||||
internal::forceConvertJsValueToStdString(arguments[1], &str);
|
||||
SE_LOGD("JS: %s\n", str.c_str());
|
||||
}
|
||||
return JS_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
void myJsBeforeCollectCallback(void *callbackState)
|
||||
{
|
||||
SE_LOGD("GC start ...\n");
|
||||
}
|
||||
|
||||
JsValueRef privateDataContructor(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
|
||||
{
|
||||
return JS_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
void privateDataFinalize(void *data)
|
||||
{
|
||||
internal::PrivateData* p = (internal::PrivateData*)data;
|
||||
if (p->finalizeCb != nullptr)
|
||||
p->finalizeCb(p->data);
|
||||
free(p);
|
||||
}
|
||||
|
||||
// For console stuff
|
||||
bool JSB_console_format_log(State& s, const char* prefix, int msgIndex = 0)
|
||||
{
|
||||
if (msgIndex < 0)
|
||||
return false;
|
||||
|
||||
const auto& args = s.args();
|
||||
int argc = (int)args.size();
|
||||
if ((argc - msgIndex) == 1)
|
||||
{
|
||||
std::string msg = args[msgIndex].toStringForce();
|
||||
SE_LOGD("JS: %s%s\n", prefix, msg.c_str());
|
||||
}
|
||||
else if (argc > 1)
|
||||
{
|
||||
std::string msg = args[msgIndex].toStringForce();
|
||||
size_t pos;
|
||||
for (int i = (msgIndex+1); i < argc; ++i)
|
||||
{
|
||||
pos = msg.find("%");
|
||||
if (pos != std::string::npos && pos != (msg.length()-1) && (msg[pos+1] == 'd' || msg[pos+1] == 's' || msg[pos+1] == 'f'))
|
||||
{
|
||||
msg.replace(pos, 2, args[i].toStringForce());
|
||||
}
|
||||
else
|
||||
{
|
||||
msg += " " + args[i].toStringForce();
|
||||
}
|
||||
}
|
||||
|
||||
SE_LOGD("JS: %s%s\n", prefix, msg.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JSB_console_log(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_log)
|
||||
|
||||
bool JSB_console_debug(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[DEBUG]: ");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_debug)
|
||||
|
||||
bool JSB_console_info(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[INFO]: ");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_info)
|
||||
|
||||
bool JSB_console_warn(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[WARN]: ");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_warn)
|
||||
|
||||
bool JSB_console_error(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[ERROR]: ");
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_error)
|
||||
|
||||
bool JSB_console_assert(State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
if (!args.empty())
|
||||
{
|
||||
if (args[0].isBoolean() && !args[0].toBoolean())
|
||||
{
|
||||
JSB_console_format_log(s, "[ASSERT]: ", 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_assert)
|
||||
|
||||
} // namespace {
|
||||
|
||||
ScriptEngine *ScriptEngine::getInstance()
|
||||
{
|
||||
if (__instance == nullptr)
|
||||
{
|
||||
__instance = new ScriptEngine();
|
||||
}
|
||||
|
||||
return __instance;
|
||||
}
|
||||
|
||||
void ScriptEngine::destroyInstance()
|
||||
{
|
||||
delete __instance;
|
||||
__instance = nullptr;
|
||||
}
|
||||
|
||||
ScriptEngine::ScriptEngine()
|
||||
: _rt(JS_INVALID_RUNTIME_HANDLE)
|
||||
, _cx(JS_INVALID_REFERENCE)
|
||||
, _globalObj(nullptr)
|
||||
, _exceptionCallback(nullptr)
|
||||
, _currentSourceContext(0)
|
||||
, _vmId(0)
|
||||
, _isValid(false)
|
||||
, _isInCleanup(false)
|
||||
, _isErrorHandleWorking(false)
|
||||
, _isGarbageCollecting(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool ScriptEngine::init()
|
||||
{
|
||||
cleanup();
|
||||
SE_LOGD("Initializing ChakraCore, version: %d.%d.%d\n", CHAKRA_CORE_MAJOR_VERSION, CHAKRA_CORE_MINOR_VERSION, CHAKRA_CORE_PATCH_VERSION);
|
||||
|
||||
++_vmId;
|
||||
for (const auto& hook : _beforeInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeInitHookArray.clear();
|
||||
|
||||
_CHECK(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &_rt));
|
||||
_CHECK(JsCreateContext(_rt, &_cx));
|
||||
_CHECK(JsSetCurrentContext(_cx));
|
||||
|
||||
NativePtrToObjectMap::init();
|
||||
NonRefNativePtrCreatedByCtorMap::init();
|
||||
|
||||
// Set up ES6 Promise
|
||||
// if (JsSetPromiseContinuationCallback(PromiseContinuationCallback, &taskQueue) != JsNoError)
|
||||
|
||||
JsValueRef globalObj = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsGetGlobalObject(&globalObj));
|
||||
|
||||
_CHECK(JsSetRuntimeBeforeCollectCallback(_rt, nullptr, myJsBeforeCollectCallback));
|
||||
|
||||
_globalObj = Object::_createJSObject(nullptr, globalObj);
|
||||
_globalObj->root();
|
||||
_globalObj->setProperty("window", Value(_globalObj));
|
||||
|
||||
// ChakraCore isn't shipped with a console variable. Make a fake one.
|
||||
Value consoleVal;
|
||||
bool hasConsole = _globalObj->getProperty("console", &consoleVal) && consoleVal.isObject();
|
||||
assert(!hasConsole);
|
||||
|
||||
HandleObject consoleObj(Object::createPlainObject());
|
||||
consoleObj->defineFunction("log", _SE(JSB_console_log));
|
||||
consoleObj->defineFunction("debug", _SE(JSB_console_debug));
|
||||
consoleObj->defineFunction("info", _SE(JSB_console_info));
|
||||
consoleObj->defineFunction("warn", _SE(JSB_console_warn));
|
||||
consoleObj->defineFunction("error", _SE(JSB_console_error));
|
||||
consoleObj->defineFunction("assert", _SE(JSB_console_assert));
|
||||
|
||||
_globalObj->setProperty("console", Value(consoleObj));
|
||||
|
||||
_globalObj->setProperty("scriptEngineType", Value("ChakraCore"));
|
||||
|
||||
_globalObj->defineFunction("log", __log);
|
||||
_globalObj->defineFunction("forceGC", __forceGC);
|
||||
|
||||
__jsb_CCPrivateData_class = Class::create("__PrivateData", _globalObj, nullptr, privateDataContructor);
|
||||
__jsb_CCPrivateData_class->defineFinalizeFunction(privateDataFinalize);
|
||||
__jsb_CCPrivateData_class->install();
|
||||
|
||||
_isValid = true;
|
||||
|
||||
for (const auto& hook : _afterInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterInitHookArray.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ScriptEngine::~ScriptEngine()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void ScriptEngine::cleanup()
|
||||
{
|
||||
if (!_isValid)
|
||||
return;
|
||||
|
||||
_isInCleanup = true;
|
||||
for (const auto& hook : _beforeCleanupHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeCleanupHookArray.clear();
|
||||
|
||||
SAFE_DEC_REF(_globalObj);
|
||||
Object::cleanup();
|
||||
Class::cleanup();
|
||||
garbageCollect();
|
||||
|
||||
_CHECK(JsSetCurrentContext(JS_INVALID_REFERENCE));
|
||||
_CHECK(JsDisposeRuntime(_rt));
|
||||
|
||||
_cx = nullptr;
|
||||
_globalObj = nullptr;
|
||||
_isValid = false;
|
||||
|
||||
_registerCallbackArray.clear();
|
||||
|
||||
for (const auto& hook : _afterCleanupHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterCleanupHookArray.clear();
|
||||
_isInCleanup = false;
|
||||
|
||||
NativePtrToObjectMap::destroy();
|
||||
NonRefNativePtrCreatedByCtorMap::destroy();
|
||||
}
|
||||
|
||||
ScriptEngine::ExceptionInfo ScriptEngine::formatException(JsValueRef exception)
|
||||
{
|
||||
ExceptionInfo ret;
|
||||
if (exception == JS_INVALID_REFERENCE)
|
||||
return ret;
|
||||
|
||||
std::vector<std::string> allKeys;
|
||||
Object* exceptionObj = Object::_createJSObject(nullptr, exception);
|
||||
exceptionObj->getAllKeys(&allKeys);
|
||||
|
||||
for (const auto& key : allKeys)
|
||||
{
|
||||
Value tmp;
|
||||
if (exceptionObj->getProperty(key.c_str(), &tmp))
|
||||
{
|
||||
// SE_LOGD("[%s]=%s\n", key.c_str(), tmp.toStringForce().c_str());
|
||||
if (key == "message")
|
||||
{
|
||||
ret.message = tmp.toString();
|
||||
}
|
||||
else if (key == "stack")
|
||||
{
|
||||
ret.stack = tmp.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exceptionObj->decRef();
|
||||
|
||||
ret.location = "(see stack)";
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object* ScriptEngine::getGlobalObject()
|
||||
{
|
||||
return _globalObj;
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeCleanupHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterCleanupHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addRegisterCallback(RegisterCallback cb)
|
||||
{
|
||||
assert(std::find(_registerCallbackArray.begin(), _registerCallbackArray.end(), cb) == _registerCallbackArray.end());
|
||||
_registerCallbackArray.push_back(cb);
|
||||
}
|
||||
|
||||
bool ScriptEngine::start()
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
_startTime = std::chrono::steady_clock::now();
|
||||
|
||||
for (auto cb : _registerCallbackArray)
|
||||
{
|
||||
ok = cb(_globalObj);
|
||||
assert(ok);
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
// After ScriptEngine is started, _registerCallbackArray isn't needed. Therefore, clear it here.
|
||||
_registerCallbackArray.clear();
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ScriptEngine::isGarbageCollecting()
|
||||
{
|
||||
return _isGarbageCollecting;
|
||||
}
|
||||
|
||||
void ScriptEngine::_setGarbageCollecting(bool isGarbageCollecting)
|
||||
{
|
||||
_isGarbageCollecting = isGarbageCollecting;
|
||||
}
|
||||
|
||||
void ScriptEngine::garbageCollect()
|
||||
{
|
||||
SE_LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
_CHECK(JsCollectGarbage(_rt));
|
||||
SE_LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
}
|
||||
|
||||
void ScriptEngine::clearException()
|
||||
{
|
||||
bool hasException = false;
|
||||
_CHECK(JsHasException(&hasException));
|
||||
|
||||
if (hasException)
|
||||
{
|
||||
JsValueRef exception;
|
||||
_CHECK(JsGetAndClearException(&exception));
|
||||
|
||||
ExceptionInfo exceptionInfo = formatException(exception);
|
||||
SE_LOGD("ERROR: %s, location: %s, \nSTACK:\n%s\n", exceptionInfo.message.c_str(), exceptionInfo.location.c_str(), exceptionInfo.stack.c_str());
|
||||
|
||||
if (_exceptionCallback != nullptr)
|
||||
{
|
||||
_exceptionCallback(exceptionInfo.location.c_str(), exceptionInfo.message.c_str(), exceptionInfo.stack.c_str());
|
||||
}
|
||||
|
||||
if (!_isErrorHandleWorking)
|
||||
{
|
||||
_isErrorHandleWorking = true;
|
||||
|
||||
Value errorHandler;
|
||||
if (_globalObj->getProperty("__errorHandler", &errorHandler) && errorHandler.isObject() && errorHandler.toObject()->isFunction())
|
||||
{
|
||||
ValueArray args;
|
||||
args.push_back(Value(exceptionInfo.location));
|
||||
args.push_back(Value(0));
|
||||
args.push_back(Value(exceptionInfo.message));
|
||||
args.push_back(Value(exceptionInfo.stack));
|
||||
errorHandler.toObject()->call(args, _globalObj);
|
||||
}
|
||||
|
||||
_isErrorHandleWorking = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SE_LOGE("ERROR: __errorHandler has exception\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::setExceptionCallback(const ExceptionCallback& cb)
|
||||
{
|
||||
_exceptionCallback = cb;
|
||||
}
|
||||
|
||||
bool ScriptEngine::evalString(const char* script, ssize_t length/* = -1 */, Value* ret/* = nullptr */, const char* fileName/* = nullptr */)
|
||||
{
|
||||
assert(script != nullptr);
|
||||
if (length < 0)
|
||||
length = strlen(script);
|
||||
|
||||
if (fileName == nullptr)
|
||||
fileName = "(no filename)";
|
||||
|
||||
JsValueRef fname;
|
||||
_CHECK(JsCreateString(fileName, strlen(fileName), &fname));
|
||||
|
||||
JsValueRef scriptSource;
|
||||
_CHECK(JsCreateString(script, length, &scriptSource));
|
||||
|
||||
JsValueRef result;
|
||||
// Run the script.
|
||||
JsErrorCode errCode = JsRun(scriptSource, _currentSourceContext++, fname, JsParseScriptAttributeNone, &result);
|
||||
|
||||
if (errCode != JsNoError)
|
||||
{
|
||||
SE_LOGE("ScriptEngine::evalString script %s, failed!\n", fileName);
|
||||
clearException();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ret != nullptr)
|
||||
{
|
||||
JsValueType type;
|
||||
JsGetValueType(result, &type);
|
||||
if (type != JsUndefined)
|
||||
{
|
||||
internal::jsToSeValue(result, ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret->setUndefined();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScriptEngine::setFileOperationDelegate(const FileOperationDelegate& delegate)
|
||||
{
|
||||
_fileOperationDelegate = delegate;
|
||||
}
|
||||
|
||||
const ScriptEngine::FileOperationDelegate& ScriptEngine::getFileOperationDelegate() const
|
||||
{
|
||||
return _fileOperationDelegate;
|
||||
}
|
||||
|
||||
bool ScriptEngine::runScript(const std::string& path, Value* ret/* = nullptr */)
|
||||
{
|
||||
assert(!path.empty());
|
||||
assert(_fileOperationDelegate.isValid());
|
||||
|
||||
std::string scriptBuffer = _fileOperationDelegate.onGetStringFromFile(path);
|
||||
|
||||
if (!scriptBuffer.empty())
|
||||
{
|
||||
return evalString(scriptBuffer.c_str(), scriptBuffer.length(), ret, path.c_str());
|
||||
}
|
||||
|
||||
SE_LOGE("ScriptEngine::runScript script buffer is empty!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait)
|
||||
{
|
||||
//IDEA:
|
||||
}
|
||||
|
||||
bool ScriptEngine::isDebuggerEnabled() const
|
||||
{
|
||||
//IDEA:
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptEngine::mainLoopUpdate()
|
||||
{
|
||||
//IDEA:
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
@@ -0,0 +1,311 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
class Class;
|
||||
class Value;
|
||||
|
||||
extern Class* __jsb_CCPrivateData_class;
|
||||
|
||||
/**
|
||||
* A stack-allocated class that governs a number of local handles.
|
||||
* It's only implemented for v8 wrapper now.
|
||||
* Other script engine wrappers have empty implementation for this class.
|
||||
* It's used at the beginning of executing any wrapper API.
|
||||
*/
|
||||
class AutoHandleScope
|
||||
{
|
||||
public:
|
||||
AutoHandleScope() {}
|
||||
~AutoHandleScope() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* ScriptEngine is a sington which represents a context of JavaScript VM.
|
||||
*/
|
||||
class ScriptEngine final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Gets or creates the instance of script engine.
|
||||
* @return The script engine instance.
|
||||
*/
|
||||
static ScriptEngine* getInstance();
|
||||
|
||||
/**
|
||||
* @brief Destroys the instance of script engine.
|
||||
*/
|
||||
static void destroyInstance();
|
||||
|
||||
/**
|
||||
* @brief Gets the global object of JavaScript VM.
|
||||
* @return The se::Object stores the global JavaScript object.
|
||||
*/
|
||||
Object* getGlobalObject();
|
||||
|
||||
typedef bool (*RegisterCallback)(Object*);
|
||||
|
||||
/**
|
||||
* @brief Adds a callback for registering a native binding module.
|
||||
* @param[in] cb A callback for registering a native binding module.
|
||||
* @note This method just add a callback to a vector, callbacks is invoked in `start` method.
|
||||
*/
|
||||
void addRegisterCallback(RegisterCallback cb);
|
||||
|
||||
/**
|
||||
* @brief Starts the script engine.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note This method will invoke all callbacks of native binding modules by the order of registration.
|
||||
*/
|
||||
bool start();
|
||||
|
||||
/**
|
||||
* @brief Initializes script engine.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note This method will create JavaScript context and global object.
|
||||
*/
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Cleanups script engine.
|
||||
* @note This method will removes all objects in JavaScript VM even whose are rooted, then shutdown JavaScript VMf.
|
||||
*/
|
||||
void cleanup();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before cleanuping script engine.
|
||||
* @param[in] hook A hook function to be invoked before cleanuping script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after cleanuping script engine.
|
||||
* @param[in] hook A hook function to be invoked after cleanuping script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Executes a utf-8 string buffer which contains JavaScript code.
|
||||
* @param[in] scriptStr A utf-8 string buffer, if it isn't null-terminated, parameter `length` should be assigned and > 0.
|
||||
* @param[in] length The length of parameter `scriptStr`, it will be set to string length internally if passing < 0 and parameter `scriptStr` is null-terminated.
|
||||
* @param[in] rval The se::Value that results from evaluating script. Passing nullptr if you don't care about the result.
|
||||
* @param[in] fileName A string containing a URL for the script's source file. This is used by debuggers and when reporting exceptions. Pass NULL if you do not care to include source file information.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool evalString(const char* scriptStr, ssize_t length = -1, Value* rval = nullptr, const char* fileName = nullptr);
|
||||
|
||||
/**
|
||||
* Delegate class for file operation
|
||||
*/
|
||||
class FileOperationDelegate
|
||||
{
|
||||
public:
|
||||
FileOperationDelegate()
|
||||
: onGetDataFromFile(nullptr)
|
||||
, onGetStringFromFile(nullptr)
|
||||
, onCheckFileExist(nullptr)
|
||||
, onGetFullPath(nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Tests whether delegate is valid.
|
||||
*/
|
||||
bool isValid() const {
|
||||
return onGetDataFromFile != nullptr
|
||||
&& onGetStringFromFile != nullptr
|
||||
&& onCheckFileExist != nullptr
|
||||
&& onGetFullPath != nullptr; }
|
||||
|
||||
// path, buffer, buffer size
|
||||
std::function<void(const std::string&, const std::function<void(const uint8_t*, size_t)>& )> onGetDataFromFile;
|
||||
// path, return file string content.
|
||||
std::function<std::string(const std::string&)> onGetStringFromFile;
|
||||
// path
|
||||
std::function<bool(const std::string&)> onCheckFileExist;
|
||||
// path, return full path
|
||||
std::function<std::string(const std::string&)> onGetFullPath;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Sets the delegate for file operation.
|
||||
* @param delegate[in] The delegate instance for file operation.
|
||||
*/
|
||||
void setFileOperationDelegate(const FileOperationDelegate& delegate);
|
||||
|
||||
/**
|
||||
* @brief Gets the delegate for file operation.
|
||||
* @return The delegate for file operation
|
||||
*/
|
||||
const FileOperationDelegate& getFileOperationDelegate() const;
|
||||
|
||||
/**
|
||||
* @brief Executes a file which contains JavaScript code.
|
||||
* @param[in] path Script file path.
|
||||
* @param[in] rval The se::Value that results from evaluating script. Passing nullptr if you don't care about the result.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool runScript(const std::string& path, Value* rval = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Tests whether script engine is doing garbage collection.
|
||||
* @return true if it's in garbage collection, otherwise false.
|
||||
*/
|
||||
bool isGarbageCollecting();
|
||||
|
||||
/**
|
||||
* @brief Performs a JavaScript garbage collection.
|
||||
*/
|
||||
void garbageCollect();
|
||||
|
||||
/**
|
||||
* @brief Tests whether script engine is being cleaned up.
|
||||
* @return true if it's in cleaning up, otherwise false.
|
||||
*/
|
||||
bool isInCleanup() { return _isInCleanup; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether script engine is valid.
|
||||
* @return true if it's valid, otherwise false.
|
||||
*/
|
||||
bool isValid() { return _isValid; }
|
||||
|
||||
/**
|
||||
* @brief Clears all exceptions.
|
||||
*/
|
||||
void clearException();
|
||||
|
||||
using ExceptionCallback = std::function<void(const char*, const char*, const char*)>; // location, message, stack
|
||||
|
||||
/**
|
||||
* @brief Sets the callback function while an exception is fired.
|
||||
* @param[in] cb The callback function to notify that an exception is fired.
|
||||
*/
|
||||
void setExceptionCallback(const ExceptionCallback& cb);
|
||||
|
||||
/**
|
||||
* @brief Gets the start time of script engine.
|
||||
* @return The start time of script engine.
|
||||
*/
|
||||
const std::chrono::steady_clock::time_point& getStartTime() const { return _startTime; }
|
||||
|
||||
/**
|
||||
* @brief Enables JavaScript debugger
|
||||
* @param[in] serverAddr The address of debugger server.
|
||||
* @param[in] port The port of debugger server will use.
|
||||
* @param[in] isWait Whether wait debugger attach when loading.
|
||||
*/
|
||||
void enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait = false);
|
||||
|
||||
/**
|
||||
* @brief Tests whether JavaScript debugger is enabled
|
||||
* @return true if JavaScript debugger is enabled, otherwise false.
|
||||
*/
|
||||
bool isDebuggerEnabled() const;
|
||||
|
||||
/**
|
||||
* @brief Main loop update trigger, it's need to invoked in main thread every frame.
|
||||
*/
|
||||
void mainLoopUpdate();
|
||||
|
||||
/**
|
||||
* @brief Gets script virtual machine instance ID. Default value is 1, increase by 1 if `init` is invoked.
|
||||
*/
|
||||
uint32_t getVMId() const { return _vmId; }
|
||||
|
||||
// Private API used in wrapper
|
||||
void _setGarbageCollecting(bool isGarbageCollecting);
|
||||
void _retainScriptObject(void* owner, void* target);
|
||||
void _releaseScriptObject(void* owner, void* target);
|
||||
//
|
||||
private:
|
||||
ScriptEngine();
|
||||
~ScriptEngine();
|
||||
|
||||
struct ExceptionInfo
|
||||
{
|
||||
std::string location;
|
||||
std::string message;
|
||||
std::string stack;
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return !message.empty();
|
||||
}
|
||||
};
|
||||
ExceptionInfo formatException(JsValueRef exception);
|
||||
|
||||
std::chrono::steady_clock::time_point _startTime;
|
||||
std::vector<RegisterCallback> _registerCallbackArray;
|
||||
std::vector<std::function<void()>> _beforeInitHookArray;
|
||||
std::vector<std::function<void()>> _afterInitHookArray;
|
||||
std::vector<std::function<void()>> _beforeCleanupHookArray;
|
||||
std::vector<std::function<void()>> _afterCleanupHookArray;
|
||||
|
||||
JsRuntimeHandle _rt;
|
||||
JsContextRef _cx;
|
||||
Object* _globalObj;
|
||||
|
||||
FileOperationDelegate _fileOperationDelegate;
|
||||
ExceptionCallback _exceptionCallback;
|
||||
|
||||
uint32_t _currentSourceContext;
|
||||
uint32_t _vmId;
|
||||
|
||||
bool _isValid;
|
||||
bool _isInCleanup;
|
||||
bool _isGarbageCollecting;
|
||||
bool _isErrorHandleWorking;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Object.hpp"
|
||||
#include "HelperMacros.h"
|
||||
#include "Utils.hpp"
|
||||
@@ -0,0 +1,336 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Utils.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../HandleObject.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
namespace internal {
|
||||
|
||||
bool defineProperty(JsValueRef obj, const char* name, JsNativeFunction getter, JsNativeFunction setter, bool enumerable, bool configurable)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreatePropertyId(name, strlen(name), &propertyId));
|
||||
JsValueRef propertyDescriptor;
|
||||
_CHECK(JsCreateObject(&propertyDescriptor));
|
||||
|
||||
const char* tmp = nullptr;
|
||||
JsValueRef jsValue = JS_INVALID_REFERENCE;
|
||||
JsPropertyIdRef id = JS_INVALID_REFERENCE;
|
||||
|
||||
if (getter != nullptr)
|
||||
{
|
||||
tmp = "get";
|
||||
_CHECK(JsCreateFunction(getter, nullptr, &jsValue));
|
||||
_CHECK(JsCreatePropertyId(tmp, strlen(tmp), &id));
|
||||
_CHECK(JsSetProperty(propertyDescriptor, id, jsValue, true));
|
||||
}
|
||||
|
||||
if (setter != nullptr)
|
||||
{
|
||||
tmp = "set";
|
||||
_CHECK(JsCreateFunction(setter, nullptr, &jsValue));
|
||||
_CHECK(JsCreatePropertyId(tmp, strlen(tmp), &id));
|
||||
_CHECK(JsSetProperty(propertyDescriptor, id, jsValue, true));
|
||||
}
|
||||
|
||||
JsValueRef trueValue;
|
||||
_CHECK(JsGetTrueValue(&trueValue));
|
||||
|
||||
tmp = "enumerable";
|
||||
_CHECK(JsCreatePropertyId(tmp, strlen(tmp), &id));
|
||||
_CHECK(JsSetProperty(propertyDescriptor, id, trueValue, true));
|
||||
|
||||
tmp = "configurable";
|
||||
_CHECK(JsCreatePropertyId(tmp, strlen(tmp), &id));
|
||||
_CHECK(JsSetProperty(propertyDescriptor, id, trueValue, true));
|
||||
|
||||
_CHECK(JsDefineProperty(obj, propertyId, propertyDescriptor, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
void jsToSeArgs(int argc, const JsValueRef* argv, ValueArray* outArr)
|
||||
{
|
||||
outArr->reserve(argc);
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
Value v;
|
||||
jsToSeValue(argv[i], &v);
|
||||
outArr->push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
void seToJsArgs(const ValueArray& args, JsValueRef* outArr)
|
||||
{
|
||||
for (size_t i = 0, len = args.size(); i < len; ++i)
|
||||
{
|
||||
seToJsValue(args[i], &outArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void jsToSeValue(JsValueRef jsValue, Value* data)
|
||||
{
|
||||
JsValueType type;
|
||||
_CHECK(JsGetValueType(jsValue, &type));
|
||||
|
||||
if (type == JsNull)
|
||||
{
|
||||
data->setNull();
|
||||
}
|
||||
else if (type == JsUndefined)
|
||||
{
|
||||
data->setUndefined();
|
||||
}
|
||||
else if (type == JsNumber)
|
||||
{
|
||||
double v = 0.0;
|
||||
_CHECK(JsNumberToDouble(jsValue, &v));
|
||||
data->setNumber(v);
|
||||
}
|
||||
else if (type == JsBoolean)
|
||||
{
|
||||
bool v = false;
|
||||
_CHECK(JsBooleanToBool(jsValue, &v));
|
||||
data->setBoolean(v);
|
||||
}
|
||||
else if (type == JsString)
|
||||
{
|
||||
std::string str;
|
||||
forceConvertJsValueToStdString(jsValue, &str);
|
||||
data->setString(str);
|
||||
}
|
||||
else if (type == JsObject || type == JsFunction || type == JsArrayBuffer
|
||||
|| type == JsTypedArray || type == JsArray)
|
||||
{
|
||||
void* nativePtr = internal::getPrivate(jsValue);
|
||||
Object* obj = nullptr;
|
||||
if (nativePtr != nullptr)
|
||||
{
|
||||
obj = Object::getObjectWithPtr(nativePtr);
|
||||
}
|
||||
|
||||
if (obj == nullptr)
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, jsValue);
|
||||
}
|
||||
data->setObject(obj, true);
|
||||
obj->decRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void seToJsValue(const Value& v, JsValueRef* jsval)
|
||||
{
|
||||
switch (v.getType()) {
|
||||
case Value::Type::Null:
|
||||
_CHECK(JsGetNullValue(jsval));
|
||||
break;
|
||||
|
||||
case Value::Type::Number:
|
||||
_CHECK(JsDoubleToNumber(v.toNumber(), jsval));
|
||||
break;
|
||||
|
||||
case Value::Type::String:
|
||||
{
|
||||
_CHECK(JsCreateString(v.toString().c_str(), v.toString().length(), jsval));
|
||||
}
|
||||
break;
|
||||
|
||||
case Value::Type::Boolean:
|
||||
_CHECK(JsBoolToBoolean(v.toBoolean(), jsval));
|
||||
break;
|
||||
|
||||
case Value::Type::Object:
|
||||
*jsval = v.toObject()->_getJSObject();
|
||||
break;
|
||||
|
||||
default: // Undefined
|
||||
_CHECK(JsGetUndefinedValue(jsval));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void forceConvertJsValueToStdString(JsValueRef jsval, std::string* ret)
|
||||
{
|
||||
JsValueRef strVal = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsConvertValueToString(jsval, &strVal));
|
||||
jsStringToStdString(strVal, ret);
|
||||
}
|
||||
|
||||
void jsStringToStdString(JsValueRef strVal, std::string* ret)
|
||||
{
|
||||
// Get the buffer size
|
||||
size_t bufSize = 0;
|
||||
_CHECK(JsCopyString(strVal, nullptr, 0, &bufSize));
|
||||
// Allocate buffer
|
||||
char* buf = (char*)malloc(bufSize + 1);
|
||||
memset(buf, 0, bufSize + 1);
|
||||
// Copy
|
||||
_CHECK(JsCopyString(strVal, buf, bufSize, nullptr));
|
||||
*ret = buf;
|
||||
free(buf);
|
||||
}
|
||||
|
||||
const char* KEY_PRIVATE_DATA = "__cc_private_data";
|
||||
|
||||
bool hasPrivate(JsValueRef obj)
|
||||
{
|
||||
JsValueType type;
|
||||
_CHECK(JsGetValueType(obj, &type));
|
||||
if (type != JsObject && type != JsFunction
|
||||
&& type != JsArray && type != JsSymbol
|
||||
&& type != JsArrayBuffer && type != JsTypedArray
|
||||
&& type != JsDataView)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool isExist = false;
|
||||
JsErrorCode err = JsHasExternalData(obj, &isExist);
|
||||
assert(err == JsNoError);
|
||||
if (isExist)
|
||||
return true;
|
||||
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreatePropertyId(KEY_PRIVATE_DATA, strlen(KEY_PRIVATE_DATA), &propertyId));
|
||||
_CHECK(JsHasProperty(obj, propertyId, &isExist));
|
||||
return isExist;
|
||||
}
|
||||
|
||||
void setPrivate(JsValueRef obj, void* data, JsFinalizeCallback finalizeCb)
|
||||
{
|
||||
bool isExist = false;
|
||||
_CHECK(JsHasExternalData(obj, &isExist));
|
||||
if (isExist)
|
||||
{
|
||||
_CHECK(JsSetExternalData(obj, data));
|
||||
return;
|
||||
}
|
||||
|
||||
assert(finalizeCb);
|
||||
Object* privateObj = Object::createObjectWithClass(__jsb_CCPrivateData_class);
|
||||
privateObj->root();
|
||||
|
||||
internal::PrivateData* privateData = (internal::PrivateData*)malloc(sizeof(internal::PrivateData));
|
||||
privateData->data = data;
|
||||
privateData->finalizeCb = finalizeCb;
|
||||
_CHECK(JsSetExternalData(privateObj->_getJSObject(), privateData));
|
||||
// SE_LOGD("setPrivate: %p\n", data);
|
||||
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
JsCreatePropertyId(KEY_PRIVATE_DATA, strlen(KEY_PRIVATE_DATA), &propertyId);
|
||||
_CHECK(JsSetProperty(obj, propertyId, privateObj->_getJSObject(), true));
|
||||
|
||||
privateObj->unroot();
|
||||
privateObj->decRef();
|
||||
}
|
||||
|
||||
void* getPrivate(JsValueRef obj)
|
||||
{
|
||||
JsValueType type;
|
||||
_CHECK(JsGetValueType(obj, &type));
|
||||
if (type != JsObject && type != JsFunction
|
||||
&& type != JsArray && type != JsSymbol
|
||||
&& type != JsArrayBuffer && type != JsTypedArray
|
||||
&& type != JsDataView)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* data = nullptr;
|
||||
bool isExist = false;
|
||||
_CHECK(JsHasExternalData(obj, &isExist));
|
||||
if (isExist)
|
||||
{
|
||||
_CHECK(JsGetExternalData(obj, &data));
|
||||
return data;
|
||||
}
|
||||
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreatePropertyId(KEY_PRIVATE_DATA, strlen(KEY_PRIVATE_DATA), &propertyId));
|
||||
_CHECK(JsHasProperty(obj, propertyId, &isExist));
|
||||
if (isExist)
|
||||
{
|
||||
JsValueRef privateDataVal;
|
||||
_CHECK(JsGetProperty(obj, propertyId, &privateDataVal));
|
||||
void* tmpPrivateData = nullptr;
|
||||
_CHECK(JsGetExternalData(privateDataVal, &tmpPrivateData));
|
||||
internal::PrivateData* privateData = (internal::PrivateData*)tmpPrivateData;
|
||||
assert(privateData);
|
||||
data = privateData->data;
|
||||
}
|
||||
// SE_LOGD("getPrivate: %p\n", data);
|
||||
return data;
|
||||
}
|
||||
|
||||
void clearPrivate(JsValueRef obj)
|
||||
{
|
||||
JsValueType type;
|
||||
_CHECK(JsGetValueType(obj, &type));
|
||||
if (type != JsObject && type != JsFunction
|
||||
&& type != JsArray && type != JsSymbol
|
||||
&& type != JsArrayBuffer && type != JsTypedArray
|
||||
&& type != JsDataView)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isExist = false;
|
||||
JsErrorCode err = JsHasExternalData(obj, &isExist);
|
||||
assert(err == JsNoError);
|
||||
if (isExist)
|
||||
{
|
||||
_CHECK(JsSetExternalData(obj, nullptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
|
||||
_CHECK(JsCreatePropertyId(KEY_PRIVATE_DATA, strlen(KEY_PRIVATE_DATA), &propertyId));
|
||||
_CHECK(JsHasProperty(obj, propertyId, &isExist));
|
||||
if (isExist)
|
||||
{
|
||||
void* data = nullptr;
|
||||
_CHECK(JsGetExternalData(obj, &data));
|
||||
internal::PrivateData* privateData = (internal::PrivateData*)data;
|
||||
free(privateData);
|
||||
JsSetExternalData(obj, nullptr);
|
||||
_CHECK(JsDeleteProperty(obj, propertyId, true, nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace se { namespace internal {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
#include "../Value.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct PrivateData
|
||||
{
|
||||
void* data;
|
||||
JsFinalizeCallback finalizeCb;
|
||||
};
|
||||
|
||||
bool defineProperty(JsValueRef obj, const char* name, JsNativeFunction getter, JsNativeFunction setter, bool enumerable, bool configurable);
|
||||
|
||||
void jsToSeArgs(int argc, const JsValueRef* argv, ValueArray* outArr);
|
||||
void seToJsArgs(const ValueArray& args, JsValueRef* outArr);
|
||||
void jsToSeValue(JsValueRef jsval, Value* v);
|
||||
void seToJsValue(const Value& v, JsValueRef* jsval);
|
||||
|
||||
void forceConvertJsValueToStdString(JsValueRef jsval, std::string* ret);
|
||||
void jsStringToStdString(JsValueRef jsStr, std::string* ret);
|
||||
|
||||
bool hasPrivate(JsValueRef obj);
|
||||
void setPrivate(JsValueRef obj, void* data, JsFinalizeCallback finalizeCb);
|
||||
void* getPrivate(JsValueRef obj);
|
||||
void clearPrivate(JsValueRef obj);
|
||||
|
||||
} // namespace internal {
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_CHAKRACORE
|
||||
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "config.hpp"
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(_WIN32) && defined(_WINDOWS)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static void _winLog(FILE* fp, const char *format, va_list args)
|
||||
{
|
||||
static const int MAX_LOG_LENGTH = 16 * 1024;
|
||||
int bufferSize = MAX_LOG_LENGTH;
|
||||
char* buf = nullptr;
|
||||
|
||||
do
|
||||
{
|
||||
buf = new (std::nothrow) char[bufferSize];
|
||||
if (buf == nullptr)
|
||||
return; // not enough memory
|
||||
|
||||
int ret = vsnprintf(buf, bufferSize - 3, format, args);
|
||||
if (ret < 0)
|
||||
{
|
||||
bufferSize *= 2;
|
||||
|
||||
delete[] buf;
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
} while (true);
|
||||
|
||||
int pos = 0;
|
||||
int len = strlen(buf);
|
||||
char tempBuf[MAX_LOG_LENGTH + 1] = { 0 };
|
||||
WCHAR wszBuf[MAX_LOG_LENGTH + 1] = { 0 };
|
||||
|
||||
do
|
||||
{
|
||||
std::copy(buf + pos, buf + pos + MAX_LOG_LENGTH, tempBuf);
|
||||
|
||||
tempBuf[MAX_LOG_LENGTH] = 0;
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, tempBuf, -1, wszBuf, sizeof(wszBuf));
|
||||
OutputDebugStringW(wszBuf);
|
||||
WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, tempBuf, sizeof(tempBuf), nullptr, FALSE);
|
||||
|
||||
fprintf(fp, "%s", tempBuf);
|
||||
fflush(fp);
|
||||
|
||||
pos += MAX_LOG_LENGTH;
|
||||
|
||||
} while (pos < len);
|
||||
|
||||
fflush(stdout);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void seLogD(const char * format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
_winLog(stdout, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void seLogE(const char * format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
_winLog(stderr, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#endif // #if defined(_WIN32) && defined(_WINDOWS)
|
||||
@@ -0,0 +1,139 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#define SCRIPT_ENGINE_NONE 0
|
||||
//#define SCRIPT_ENGINE_SM 1
|
||||
#define SCRIPT_ENGINE_V8 2
|
||||
#define SCRIPT_ENGINE_JSC 3
|
||||
//#define SCRIPT_ENGINE_CHAKRACORE 4
|
||||
|
||||
#define SCRIPT_ENGINE_V8_ON_MAC 1 // default using v8 on macOS, set 0 to disable
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#if TARGET_OS_OSX
|
||||
#if (SCRIPT_ENGINE_V8_ON_MAC == 0)
|
||||
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_JSC
|
||||
#else
|
||||
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
#ifdef __arm64__
|
||||
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
|
||||
#else
|
||||
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_JSC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//TODO how to make simulator build with v8 too? Because in release mode, it will build
|
||||
// which means it will build armv7, but v8 doesn't support armv7.
|
||||
#else
|
||||
#define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef USE_V8_DEBUGGER
|
||||
#if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0
|
||||
#define USE_V8_DEBUGGER 1
|
||||
#else
|
||||
#define USE_V8_DEBUGGER 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SE_LOG_TO_JS_ENV 0 // print log to JavaScript environment, for example DevTools
|
||||
|
||||
#if !defined(ANDROID_INSTANT) && defined(USE_V8_DEBUGGER) && USE_V8_DEBUGGER > 0
|
||||
#define SE_ENABLE_INSPECTOR 1
|
||||
#define SE_DEBUG 2
|
||||
#define HAVE_INSPECTOR 1
|
||||
#else
|
||||
#define SE_ENABLE_INSPECTOR 0
|
||||
#define SE_DEBUG 0
|
||||
#define HAVE_INSPECTOR 0
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG_TAG "jswrapper"
|
||||
#define SE_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
|
||||
#define SE_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
||||
|
||||
#elif defined(_WIN32) && defined(_WINDOWS)
|
||||
|
||||
#ifndef QUOTEME_
|
||||
#define QUOTEME_(x) #x
|
||||
#endif
|
||||
|
||||
#ifndef QUOTEME
|
||||
#define QUOTEME(x) QUOTEME_(x)
|
||||
#endif
|
||||
|
||||
void seLogD(const char * format, ...);
|
||||
void seLogE(const char * format, ...);
|
||||
|
||||
#define LOG_TAG "jswrapper"
|
||||
#define SE_LOGD(fmt, ...) seLogD("D/" LOG_TAG " (" QUOTEME(__LINE__) "): " fmt "", ##__VA_ARGS__)
|
||||
#define SE_LOGE(fmt, ...) seLogE("E/" LOG_TAG " (" QUOTEME(__LINE__) "): " fmt "", ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
#define SE_LOGD(...) do { fprintf(stdout, __VA_ARGS__); fflush(stdout); } while (false)
|
||||
#define SE_LOGE(...) do { fprintf(stderr, __VA_ARGS__); fflush(stderr); } while (false)
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||
|
||||
#define __POSIX__
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && defined(_WINDOWS)
|
||||
#include <BaseTsd.h>
|
||||
|
||||
#ifndef __SSIZE_T
|
||||
#define __SSIZE_T
|
||||
typedef SSIZE_T ssize_t;
|
||||
#define _SSIZE_T_DEFINED // libuv also defines ssize_t, use the one defined here.
|
||||
#endif // __SSIZE_T
|
||||
|
||||
#endif // #if defined(_WIN32) && defined(_WINDOWS)
|
||||
|
||||
/** @def SE_DEPRECATED_ATTRIBUTE
|
||||
* Only certain compilers support __attribute__((deprecated)).
|
||||
*/
|
||||
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
||||
#define SE_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
|
||||
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
||||
#define SE_DEPRECATED_ATTRIBUTE __declspec(deprecated)
|
||||
#else
|
||||
#define SE_DEPRECATED_ATTRIBUTE
|
||||
#endif // SE_DEPRECATED_ATTRIBUTE
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "HelperMacros.h"
|
||||
@@ -0,0 +1,282 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Class.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "State.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
#define JS_FN(name, func, attr) {name, func, attr}
|
||||
#define JS_FS_END JS_FN(0, 0, 0)
|
||||
#define JS_PSGS(name, getter, setter, attr) {name, getter, setter, attr}
|
||||
#define JS_PS_END JS_PSGS(0, 0, 0, 0)
|
||||
|
||||
namespace {
|
||||
// std::unordered_map<std::string, Class *> __clsMap;
|
||||
JSContextRef __cx = nullptr;
|
||||
std::vector<Class*> __allClasses;
|
||||
|
||||
void defaultFinalizeCallback(JSObjectRef _obj)
|
||||
{
|
||||
void* nativeThisObject = JSObjectGetPrivate(_obj);
|
||||
if (nativeThisObject != nullptr)
|
||||
{
|
||||
State state(nativeThisObject);
|
||||
Object* _thisObject = state.thisObject();
|
||||
if (_thisObject) _thisObject->_cleanup(nativeThisObject);
|
||||
JSObjectSetPrivate(_obj, nullptr);
|
||||
SAFE_DEC_REF(_thisObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Class::Class()
|
||||
: _parent(nullptr)
|
||||
, _proto(nullptr)
|
||||
, _parentProto(nullptr)
|
||||
, _ctor(nullptr)
|
||||
, _jsCls(nullptr)
|
||||
, _finalizeOp(nullptr)
|
||||
{
|
||||
_jsClsDef = kJSClassDefinitionEmpty;
|
||||
__allClasses.push_back(this);
|
||||
}
|
||||
|
||||
Class::~Class()
|
||||
{
|
||||
}
|
||||
|
||||
Class* Class::create(const std::string& className, Object* obj, Object* parentProto, JSObjectCallAsConstructorCallback ctor)
|
||||
{
|
||||
Class* cls = new Class();
|
||||
if (cls != nullptr && !cls->init(className, obj, parentProto, ctor))
|
||||
{
|
||||
delete cls;
|
||||
cls = nullptr;
|
||||
}
|
||||
return cls;
|
||||
}
|
||||
|
||||
bool Class::init(const std::string &clsName, Object* parent, Object *parentProto, JSObjectCallAsConstructorCallback ctor)
|
||||
{
|
||||
_name = clsName;
|
||||
_parent = parent;
|
||||
SAFE_INC_REF(_parent);
|
||||
_parentProto = parentProto;
|
||||
SAFE_INC_REF(_parentProto);
|
||||
_ctor = ctor;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::install()
|
||||
{
|
||||
// assert(__clsMap.find(_name) == __clsMap.end());
|
||||
//
|
||||
// __clsMap.emplace(_name, this);
|
||||
|
||||
_jsClsDef.version = 0;
|
||||
_jsClsDef.attributes = kJSClassAttributeNone;
|
||||
_jsClsDef.className = _name.c_str();
|
||||
if (_parentProto != nullptr)
|
||||
{
|
||||
_jsClsDef.parentClass = _parentProto->_getClass()->_jsCls;
|
||||
}
|
||||
|
||||
_funcs.push_back(JS_FS_END);
|
||||
// _properties.push_back(JS_PS_END);
|
||||
|
||||
// _jsClsDef.staticValues = _properties.data();
|
||||
_jsClsDef.staticFunctions = _funcs.data();
|
||||
|
||||
// _jsClsDef.getProperty = _getPropertyCallback;
|
||||
// _jsClsDef.setProperty = _setPropertyCallback;
|
||||
// _jsClsDef.hasProperty = _hasPropertyCallback;
|
||||
|
||||
if (_finalizeOp != nullptr)
|
||||
_jsClsDef.finalize = _finalizeOp;
|
||||
else
|
||||
_jsClsDef.finalize = defaultFinalizeCallback;
|
||||
|
||||
_jsCls = JSClassCreate(&_jsClsDef);
|
||||
|
||||
JSObjectRef jsCtor = JSObjectMakeConstructor(__cx, _jsCls, _ctor);
|
||||
HandleObject ctorObj(Object::_createJSObject(nullptr, jsCtor));
|
||||
|
||||
Value functionCtor;
|
||||
ScriptEngine::getInstance()->getGlobalObject()->getProperty("Function", &functionCtor);
|
||||
ctorObj->setProperty("constructor", functionCtor);
|
||||
|
||||
JSValueRef exception = nullptr;
|
||||
for (const auto& staticfunc : _staticFuncs)
|
||||
{
|
||||
JSStringRef name = JSStringCreateWithUTF8CString(staticfunc.name);
|
||||
JSObjectRef func = JSObjectMakeFunctionWithCallback(__cx, nullptr, staticfunc.callAsFunction);
|
||||
|
||||
exception = nullptr;
|
||||
JSObjectSetProperty(__cx, jsCtor, name, func, kJSPropertyAttributeNone, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
JSStringRelease(name);
|
||||
}
|
||||
|
||||
JSValueRef prototypeObj = nullptr;
|
||||
JSStringRef prototypeName = JSStringCreateWithUTF8CString("prototype");
|
||||
bool exist = JSObjectHasProperty(__cx, jsCtor, prototypeName);
|
||||
if (exist)
|
||||
{
|
||||
exception = nullptr;
|
||||
prototypeObj = JSObjectGetProperty(__cx, jsCtor, prototypeName, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
}
|
||||
JSStringRelease(prototypeName);
|
||||
assert(prototypeObj != nullptr);
|
||||
|
||||
exception = nullptr;
|
||||
JSObjectRef protoJSObj = JSValueToObject(__cx, prototypeObj, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
|
||||
//NOTE: I's weird that proto object has a private data which is an invalid adress.
|
||||
// We have to reset its private data to the max value of unsigned long.
|
||||
// Therefore, in SE_BIND_FUNC of HelperMacro.h, we could distinguish whether it's a
|
||||
// proto object. Don't set it to nullptr since static method will get private data
|
||||
// with nullptr. This line is needed by Web Inspector because it needs to extend
|
||||
// all global JS values including global proto object. However, proto objects will
|
||||
// not have a private data which will cause crash while debugging in Safari since
|
||||
// se::State::nativeThisObject() will return nullptr.
|
||||
JSObjectSetPrivate(protoJSObj, (void*)std::numeric_limits<unsigned long>::max());
|
||||
|
||||
_proto = Object::_createJSObject(this, protoJSObj);
|
||||
_proto->root();
|
||||
|
||||
// reset constructor
|
||||
_proto->setProperty("constructor", Value(ctorObj));
|
||||
|
||||
// Set instance properties
|
||||
for (const auto& property : _properties)
|
||||
{
|
||||
internal::defineProperty(_proto, property.name, property.getter, property.setter);
|
||||
}
|
||||
|
||||
// Set class properties
|
||||
for (const auto& property : _staticProperties)
|
||||
{
|
||||
internal::defineProperty(ctorObj.get(), property.name, property.getter, property.setter);
|
||||
}
|
||||
|
||||
_parent->setProperty(_name.c_str(), Value(ctorObj));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineFunction(const char *name, JSObjectCallAsFunctionCallback func)
|
||||
{
|
||||
JSStaticFunction cb = JS_FN(name, func, kJSPropertyAttributeNone);
|
||||
_funcs.push_back(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineProperty(const char *name, JSObjectCallAsFunctionCallback getter, JSObjectCallAsFunctionCallback setter)
|
||||
{
|
||||
JSPropertySpec property = JS_PSGS(name, getter, setter, kJSPropertyAttributeNone);
|
||||
_properties.push_back(property);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineStaticFunction(const char *name, JSObjectCallAsFunctionCallback func)
|
||||
{
|
||||
JSStaticFunction cb = JS_FN(name, func, kJSPropertyAttributeNone);
|
||||
_staticFuncs.push_back(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineStaticProperty(const char *name, JSObjectCallAsFunctionCallback getter, JSObjectCallAsFunctionCallback setter)
|
||||
{
|
||||
JSPropertySpec property = JS_PSGS(name, getter, setter, kJSPropertyAttributeNone);
|
||||
_staticProperties.push_back(property);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineFinalizeFunction(JSObjectFinalizeCallback func)
|
||||
{
|
||||
_finalizeOp = func;
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObjectRef Class::_createJSObjectWithClass(Class* cls)
|
||||
{
|
||||
return JSObjectMake(__cx, cls->_jsCls, nullptr);
|
||||
}
|
||||
|
||||
void Class::setContext(JSContextRef cx)
|
||||
{
|
||||
__cx = cx;
|
||||
}
|
||||
|
||||
Object *Class::getProto()
|
||||
{
|
||||
return _proto;
|
||||
}
|
||||
|
||||
void Class::destroy()
|
||||
{
|
||||
SAFE_DEC_REF(_parent);
|
||||
SAFE_DEC_REF(_proto);
|
||||
SAFE_DEC_REF(_parentProto);
|
||||
|
||||
JSClassRelease(_jsCls);
|
||||
}
|
||||
|
||||
void Class::cleanup()
|
||||
{
|
||||
for (auto cls : __allClasses)
|
||||
{
|
||||
cls->destroy();
|
||||
}
|
||||
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
for (auto cls : __allClasses)
|
||||
{
|
||||
delete cls;
|
||||
}
|
||||
__allClasses.clear();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
@@ -0,0 +1,158 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* se::Class represents a definition of how to create a native binding object.
|
||||
*/
|
||||
class Class final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a class used for creating relevant native binding objects.
|
||||
* @param[in] className A null-terminated UTF8 string containing the class's name.
|
||||
* @param[in] obj The object that current class proto object attaches to. Should not be nullptr.
|
||||
* @param[in] parentProto The parent proto object that current class inherits from. Passing nullptr means a new class has no parent.
|
||||
* @param[in] ctor A callback to invoke when your constructor is used in a 'new' expression. Pass nullptr to use the default object constructor.
|
||||
* @return A class instance used for creating relevant native binding objects.
|
||||
* @note Don't need to delete the pointer return by this method, it's managed internally.
|
||||
*/
|
||||
static Class* create(const std::string& className, Object* obj, Object* parentProto, JSObjectCallAsConstructorCallback ctor);
|
||||
|
||||
/**
|
||||
* @brief Defines a member function with a callback. Each objects created by class will have this function property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the function name.
|
||||
* @param[in] func A callback to invoke when the property is called as a function.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFunction(const char *name, JSObjectCallAsFunctionCallback func);
|
||||
|
||||
/**
|
||||
* @brief Defines a property with accessor callbacks. Each objects created by class will have this property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the property name.
|
||||
* @param[in] getter A callback to invoke when the property is read.
|
||||
* @param[in] setter A callback to invoke when the property is set.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineProperty(const char *name, JSObjectCallAsFunctionCallback getter, JSObjectCallAsFunctionCallback setter);
|
||||
|
||||
/**
|
||||
* @brief Defines a static function with a callback. Only JavaScript constructor object will have this function.
|
||||
* @param[in] name A null-terminated UTF8 string containing the function name.
|
||||
* @param[in] func A callback to invoke when the constructor's property is called as a function.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineStaticFunction(const char *name, JSObjectCallAsFunctionCallback func);
|
||||
|
||||
/**
|
||||
* @brief Defines a static property with accessor callbacks. Only JavaScript constructor object will have this property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the property name.
|
||||
* @param[in] getter A callback to invoke when the constructor's property is read.
|
||||
* @param[in] setter A callback to invoke when the constructor's property is set.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineStaticProperty(const char *name, JSObjectCallAsFunctionCallback getter, JSObjectCallAsFunctionCallback setter);
|
||||
|
||||
/**
|
||||
* @brief Defines the finalize function with a callback.
|
||||
* @param[in] func The callback to invoke when a JavaScript object is garbage collected.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFinalizeFunction(JSObjectFinalizeCallback func);
|
||||
|
||||
/**
|
||||
* @brief Installs class to JavaScript VM.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note After this method, an object could be created by `var foo = new Foo();`.
|
||||
*/
|
||||
bool install();
|
||||
|
||||
/**
|
||||
* @brief Gets the proto object of this class.
|
||||
* @return The proto object of this class.
|
||||
* @note Don't need to be released in user code.
|
||||
*/
|
||||
Object* getProto();
|
||||
|
||||
/**
|
||||
* @brief Gets the class name.
|
||||
* @return The class name.
|
||||
*/
|
||||
const char* getName() const { return _name.c_str(); }
|
||||
|
||||
private:
|
||||
Class();
|
||||
~Class();
|
||||
|
||||
bool init(const std::string& clsName, Object* obj, Object* parentProto, JSObjectCallAsConstructorCallback ctor);
|
||||
void destroy();
|
||||
|
||||
static JSObjectRef _createJSObjectWithClass(Class* cls);
|
||||
|
||||
static void setContext(JSContextRef cx);
|
||||
static void cleanup();
|
||||
|
||||
struct JSPropertySpec
|
||||
{
|
||||
const char* name;
|
||||
JSObjectCallAsFunctionCallback getter;
|
||||
JSObjectCallAsFunctionCallback setter;
|
||||
JSPropertyAttributes attributes;
|
||||
};
|
||||
|
||||
std::string _name;
|
||||
Object* _parent;
|
||||
Object* _proto;
|
||||
Object* _parentProto;
|
||||
|
||||
JSObjectCallAsConstructorCallback _ctor;
|
||||
|
||||
JSClassRef _jsCls;
|
||||
JSClassDefinition _jsClsDef;
|
||||
|
||||
std::vector<JSStaticFunction> _funcs;
|
||||
std::vector<JSStaticFunction> _staticFuncs;
|
||||
std::vector<JSPropertySpec> _properties;
|
||||
std::vector<JSPropertySpec> _staticProperties;
|
||||
JSObjectFinalizeCallback _finalizeOp;
|
||||
|
||||
friend class ScriptEngine;
|
||||
friend class Object;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <JavaScriptCore/JavaScriptCore.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
NSString *JSValueToNSString( JSContextRef ctx, JSValueRef v );
|
||||
JSValueRef NSStringToJSValue( JSContextRef ctx, NSString *string );
|
||||
double JSValueToNumberFast( JSContextRef ctx, JSValueRef v );
|
||||
void JSValueUnprotectSafe( JSContextRef ctx, JSValueRef v );
|
||||
JSValueRef NSObjectToJSValue( JSContextRef ctx, NSObject *obj );
|
||||
NSObject *JSValueToNSObject( JSContextRef ctx, JSValueRef value );
|
||||
|
||||
static inline void *JSValueGetPrivate(JSValueRef v) {
|
||||
// On 64bit systems we can not safely call JSObjectGetPrivate with any
|
||||
// JSValueRef. Doing so with immediate values (numbers, null, bool,
|
||||
// undefined) will crash the app. So we check for these first.
|
||||
|
||||
#if __LP64__
|
||||
return !((int64_t)v & 0xffff000000000002ll)
|
||||
? JSObjectGetPrivate((JSObjectRef)v)
|
||||
: NULL;
|
||||
#else
|
||||
return JSObjectGetPrivate((JSObjectRef)v);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,173 @@
|
||||
#import "EJConvert.h"
|
||||
|
||||
NSString *JSValueToNSString( JSContextRef ctx, JSValueRef v ) {
|
||||
JSStringRef jsString = JSValueToStringCopy( ctx, v, NULL );
|
||||
if( !jsString ) return nil;
|
||||
|
||||
NSString *string = (NSString *)JSStringCopyCFString( kCFAllocatorDefault, jsString );
|
||||
[string autorelease];
|
||||
JSStringRelease( jsString );
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
JSValueRef NSStringToJSValue( JSContextRef ctx, NSString *string ) {
|
||||
JSStringRef jstr = JSStringCreateWithCFString((CFStringRef)string);
|
||||
JSValueRef ret = JSValueMakeString(ctx, jstr);
|
||||
JSStringRelease(jstr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// JSValueToNumberFast blindly assumes that the given JSValueRef is a
|
||||
// a number. Everything else will be silently converted to 0.
|
||||
// This functions comes in a 64bit and 32bit flavor, since the NaN-Boxing
|
||||
// in JSC works a bit differently on each platforms. For an explanation
|
||||
// of the taggging refer to JSC/runtime/JSCJSValue.h
|
||||
// The 32bit version just calls the normal JSValueToNumber() function
|
||||
// and is thus a lot slower.
|
||||
|
||||
double JSValueToNumberFast(JSContextRef ctx, JSValueRef v) {
|
||||
#if __LP64__ // arm64 version
|
||||
union {
|
||||
int64_t asInt64;
|
||||
double asDouble;
|
||||
struct { int32_t asInt; int32_t tag; } asBits;
|
||||
} taggedValue = { .asInt64 = (int64_t)v };
|
||||
|
||||
#define DoubleEncodeOffset 0x1000000000000ll
|
||||
#define TagTypeNumber 0xffff0000
|
||||
#define ValueTrue 0x7
|
||||
|
||||
if( (taggedValue.asBits.tag & TagTypeNumber) == TagTypeNumber ) {
|
||||
return taggedValue.asBits.asInt;
|
||||
}
|
||||
else if( taggedValue.asBits.tag & TagTypeNumber ) {
|
||||
taggedValue.asInt64 -= DoubleEncodeOffset;
|
||||
return taggedValue.asDouble;
|
||||
}
|
||||
else if( taggedValue.asBits.asInt == ValueTrue ) {
|
||||
return 1.0;
|
||||
}
|
||||
else {
|
||||
return 0; // false, undefined, null, object
|
||||
}
|
||||
#else // armv7 version
|
||||
return JSValueToNumber(ctx, v, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JSValueUnprotectSafe( JSContextRef ctx, JSValueRef v ) {
|
||||
if( ctx && v ) {
|
||||
JSValueUnprotect(ctx, v);
|
||||
}
|
||||
}
|
||||
|
||||
JSValueRef NSObjectToJSValue( JSContextRef ctx, NSObject *obj ) {
|
||||
JSValueRef ret = NULL;
|
||||
|
||||
// String
|
||||
if( [obj isKindOfClass:NSString.class] ) {
|
||||
ret = NSStringToJSValue(ctx, (NSString *)obj);
|
||||
}
|
||||
|
||||
// Number or Bool
|
||||
else if( [obj isKindOfClass:NSNumber.class] ) {
|
||||
NSNumber *number = (NSNumber *)obj;
|
||||
if( strcmp(number.objCType, @encode(BOOL)) == 0 ) {
|
||||
ret = JSValueMakeBoolean(ctx, number.boolValue);
|
||||
}
|
||||
else {
|
||||
ret = JSValueMakeNumber(ctx, number.doubleValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Date
|
||||
else if( [obj isKindOfClass:NSDate.class] ) {
|
||||
NSDate *date = (NSDate *)obj;
|
||||
JSValueRef timestamp = JSValueMakeNumber(ctx, date.timeIntervalSince1970 * 1000.0);
|
||||
ret = JSObjectMakeDate(ctx, 1, ×tamp, NULL);
|
||||
}
|
||||
|
||||
// Array
|
||||
else if( [obj isKindOfClass:NSArray.class] ) {
|
||||
NSArray *array = (NSArray *)obj;
|
||||
JSValueRef *args = malloc(array.count * sizeof(JSValueRef));
|
||||
for( int i = 0; i < array.count; i++ ) {
|
||||
args[i] = NSObjectToJSValue(ctx, array[i] );
|
||||
}
|
||||
ret = JSObjectMakeArray(ctx, array.count, args, NULL);
|
||||
free(args);
|
||||
}
|
||||
|
||||
// Dictionary
|
||||
else if( [obj isKindOfClass:NSDictionary.class] ) {
|
||||
NSDictionary *dict = (NSDictionary *)obj;
|
||||
ret = JSObjectMake(ctx, NULL, NULL);
|
||||
for( NSString *key in dict ) {
|
||||
JSStringRef jsKey = JSStringCreateWithUTF8CString(key.UTF8String);
|
||||
JSValueRef value = NSObjectToJSValue(ctx, dict[key]);
|
||||
JSObjectSetProperty(ctx, (JSObjectRef)ret, jsKey, value, NULL, NULL);
|
||||
JSStringRelease(jsKey);
|
||||
}
|
||||
}
|
||||
|
||||
return ret ? ret : JSValueMakeNull(ctx);
|
||||
}
|
||||
|
||||
NSObject *JSValueToNSObject( JSContextRef ctx, JSValueRef value ) {
|
||||
JSType type = JSValueGetType(ctx, value);
|
||||
|
||||
switch( type ) {
|
||||
case kJSTypeString: return JSValueToNSString(ctx, value);
|
||||
case kJSTypeBoolean: return [NSNumber numberWithBool:JSValueToBoolean(ctx, value)];
|
||||
case kJSTypeNumber: return [NSNumber numberWithDouble:JSValueToNumberFast(ctx, value)];
|
||||
case kJSTypeNull: return nil;
|
||||
case kJSTypeUndefined: return nil;
|
||||
case kJSTypeObject: break;
|
||||
}
|
||||
|
||||
if( type == kJSTypeObject ) {
|
||||
JSObjectRef jsObj = (JSObjectRef)value;
|
||||
|
||||
// Get the Array constructor to check if this Object is an Array
|
||||
JSStringRef arrayName = JSStringCreateWithUTF8CString("Array");
|
||||
JSObjectRef arrayConstructor = (JSObjectRef)JSObjectGetProperty(ctx, JSContextGetGlobalObject(ctx), arrayName, NULL);
|
||||
JSStringRelease(arrayName);
|
||||
|
||||
if( JSValueIsInstanceOfConstructor(ctx, jsObj, arrayConstructor, NULL) ) {
|
||||
// Array
|
||||
JSStringRef lengthName = JSStringCreateWithUTF8CString("length");
|
||||
int count = JSValueToNumberFast(ctx, JSObjectGetProperty(ctx, jsObj, lengthName, NULL));
|
||||
JSStringRelease(lengthName);
|
||||
|
||||
NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
|
||||
for( int i = 0; i < count; i++ ) {
|
||||
NSObject *obj = JSValueToNSObject(ctx, JSObjectGetPropertyAtIndex(ctx, jsObj, i, NULL));
|
||||
[array addObject:(obj ? obj : NSNull.null)];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
else {
|
||||
// Plain Object
|
||||
JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(ctx, jsObj);
|
||||
size_t count = JSPropertyNameArrayGetCount(properties);
|
||||
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:count];
|
||||
for( size_t i = 0; i < count; i++ ) {
|
||||
JSStringRef jsName = JSPropertyNameArrayGetNameAtIndex(properties, i);
|
||||
NSObject *obj = JSValueToNSObject(ctx, JSObjectGetProperty(ctx, jsObj, jsName, NULL));
|
||||
|
||||
NSString *name = (NSString *)JSStringCopyCFString( kCFAllocatorDefault, jsName );
|
||||
dict[name] = obj ? obj : NSNull.null;
|
||||
[name release];
|
||||
}
|
||||
|
||||
JSPropertyNameArrayRelease(properties);
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <JavaScriptCore/JavaScriptCore.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@enum JSType
|
||||
@abstract A constant identifying the Typed Array type of a JSValue.
|
||||
@constant kEJJSTypedArrayTypeNone Not a Typed Array.
|
||||
@constant kEJJSTypedArrayTypeInt8Array Int8Array
|
||||
@constant kEJJSTypedArrayTypeInt16Array Int16Array
|
||||
@constant kEJJSTypedArrayTypeInt32Array Int32Array
|
||||
@constant kEJJSTypedArrayTypeUint8Array Int8Array
|
||||
@constant kEJJSTypedArrayTypeUint8ClampedArray Int8ClampedArray
|
||||
@constant kEJJSTypedArrayTypeUint16Array Uint16Array
|
||||
@constant kEJJSTypedArrayTypeUint32Array Uint32Array
|
||||
@constant kEJJSTypedArrayTypeFloat32Array Float32Array
|
||||
@constant kEJJSTypedArrayTypeFloat64Array Float64Array
|
||||
@constant kEJJSTypedArrayTypeArrayBuffer ArrayBuffer
|
||||
*/
|
||||
typedef enum {
|
||||
kEJJSTypedArrayTypeNone = 0,
|
||||
kEJJSTypedArrayTypeInt8Array = 1,
|
||||
kEJJSTypedArrayTypeInt16Array = 2,
|
||||
kEJJSTypedArrayTypeInt32Array = 3,
|
||||
kEJJSTypedArrayTypeUint8Array = 4,
|
||||
kEJJSTypedArrayTypeUint8ClampedArray = 5,
|
||||
kEJJSTypedArrayTypeUint16Array = 6,
|
||||
kEJJSTypedArrayTypeUint32Array = 7,
|
||||
kEJJSTypedArrayTypeFloat32Array = 8,
|
||||
kEJJSTypedArrayTypeFloat64Array = 9,
|
||||
kEJJSTypedArrayTypeArrayBuffer = 10
|
||||
} EJJSTypedArrayType;
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Setup the JSContext for use of the Typed Array functions.
|
||||
@param ctx The execution context to use
|
||||
*/
|
||||
void EJJSContextPrepareTypedArrayAPI(JSContextRef ctx);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Returns a JavaScript value's Typed Array type
|
||||
@param ctx The execution context to use.
|
||||
@param value The JSObject whose Typed Array type you want to obtain.
|
||||
@result A value of type EJJSTypedArrayType that identifies value's Typed Array type
|
||||
*/
|
||||
EJJSTypedArrayType EJJSObjectGetTypedArrayType(JSContextRef ctx, JSObjectRef object);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Creates an empty JavaScript Typed Array with the given number of elements
|
||||
@param ctx The execution context to use.
|
||||
@param arrayType A value of type EJJSTypedArrayType identifying the type of array you want to create
|
||||
@param numElements The number of elements for the array.
|
||||
@result A JSObjectRef that is a Typed Array or NULL if there was an error
|
||||
*/
|
||||
JSObjectRef EJJSObjectMakeTypedArray(JSContextRef ctx, EJJSTypedArrayType arrayType, size_t numElements);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Returns a copy of the Typed Array's data
|
||||
@param ctx The execution context to use.
|
||||
@param value The JSObject whose Typed Array data you want to obtain.
|
||||
@result A copy of the Typed Array's data or NULL if the JSObject is not a Typed Array
|
||||
*/
|
||||
NSMutableData *EJJSObjectGetTypedArrayData(JSContextRef ctx, JSObjectRef object);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Replaces a Typed Array's data
|
||||
@param ctx The execution context to use.
|
||||
@param value The JSObject whose Typed Array data you want to replace
|
||||
*/
|
||||
void EJJSObjectSetTypedArrayData(JSContextRef ctx, JSObjectRef object, NSData *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,394 @@
|
||||
#import "EJConvertTypedArray.h"
|
||||
#import "EJConvert.h"
|
||||
|
||||
#if defined __ARM_NEON__
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
// These functions deal with getting and setting a JavaScript Typed Array's data.
|
||||
// The process in which this is done is extremely backwards, prohibitively
|
||||
// memory inefficient and painfully slow.
|
||||
|
||||
// JavaScriptCore still doesn't have an API to deal with Typed Arrays directly
|
||||
// and nobody seems to care. See this WebKit bug for the details:
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=120112
|
||||
|
||||
// The naive method of getting the array's data would be to read the "length"
|
||||
// property and call JSObjectGetPropertyAtIndex() for each element. This function
|
||||
// returns a JSValue and since the array's data is just a raw memory pointer
|
||||
// internally, this JSValue has be constructed first by JSC. Afterwards this
|
||||
// JSValue has to be converted back into an int and stored in a native buffer.
|
||||
// This ordeal takes about 1200ms per megabyte on an iPhone5S.
|
||||
|
||||
// So, instead of extracting each byte on its own, we create Int32 view on the
|
||||
// Array, so that we can extract 4 bytes at a time. Now, the fastest method to
|
||||
// get to the values is to call a function with .apply(null, theInt32Array).
|
||||
// This causes the typed array to be converted into plain JSValues - we can then
|
||||
// iterate all function arguments and convert each JSValue into a Int32.
|
||||
|
||||
// There's one big caveat, though: a function can only be called with 64k
|
||||
// arguments at once, or it will blow the stack. So we have to divide the Int32
|
||||
// Array into smaller subarrays and convert the data in chunks.
|
||||
|
||||
// Setting the Array's data works about the same. We can create a plain JS
|
||||
// Array in reasonable time by treating the data as 32bit ints. This plain
|
||||
// Array can then be used to call .set() on an Int32 View of the Typed Array.
|
||||
|
||||
// To be able to quickly determine the type of a typed array, we install an
|
||||
// enum with the type id ("__ejTypedArrayType") onto each array constructor's
|
||||
// prototype.
|
||||
|
||||
// This all brings the time down to about 7ms per megabyte for reading and about
|
||||
// 20ms per megabyte for writing. Even though this 7ms/MB number may not sound
|
||||
// all too bad, keep in mind that it's still 7ms slower than what we would have
|
||||
// with a better API.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Array Types to constructor names. We need to obtain the Constructors from
|
||||
// the JSGlobalObject when creating Typed Arrays and when attaching our methods
|
||||
// to them.
|
||||
|
||||
const static char *ConstructorNames[] = {
|
||||
[kEJJSTypedArrayTypeNone] = NULL,
|
||||
[kEJJSTypedArrayTypeInt8Array] = "Int8Array",
|
||||
[kEJJSTypedArrayTypeInt16Array] = "Int16Array",
|
||||
[kEJJSTypedArrayTypeInt32Array] = "Int32Array",
|
||||
[kEJJSTypedArrayTypeUint8Array] = "Uint8Array",
|
||||
[kEJJSTypedArrayTypeUint8ClampedArray] = "Uint8ClampedArray",
|
||||
[kEJJSTypedArrayTypeUint16Array] = "Uint16Array",
|
||||
[kEJJSTypedArrayTypeUint32Array] = "Uint32Array",
|
||||
[kEJJSTypedArrayTypeFloat32Array] = "Float32Array",
|
||||
[kEJJSTypedArrayTypeFloat64Array] = "Float64Array",
|
||||
[kEJJSTypedArrayTypeArrayBuffer] = "ArrayBuffer"
|
||||
};
|
||||
|
||||
|
||||
// Data from Typed Arrays smaller than CopyInChunksThreshold will be extracted
|
||||
// one byte at a time.
|
||||
|
||||
const static int CopyInChunksThreshold = 32;
|
||||
|
||||
|
||||
// For large arrays, copy the data in Chunks of 16k elements, so that we don't
|
||||
// blow the stack.
|
||||
|
||||
const static int CopyChunkSize = 0x4000;
|
||||
|
||||
|
||||
|
||||
// Hobo version to get an Int32 from a JSValueRef. This is even faster than
|
||||
// JSValueToNumberFast() because it blindly assumes the value is an Int32.
|
||||
// A number stored as double will produce a bogus Int value. JSC stores all
|
||||
// values that are outside of the Int32 range as double.
|
||||
|
||||
// This function is only fast on 64bit systems. On 32bit systems we can't
|
||||
// easily access the integer value.
|
||||
// See JavaScriptCore/runtime/JSCJSValue.h for an explanation of the NaN-
|
||||
// boxing used in JSC.
|
||||
|
||||
// Use with extreme caution!
|
||||
|
||||
static inline int32_t GetInt32(JSContextRef ctx, JSValueRef v) {
|
||||
#if __LP64__
|
||||
return (int32_t)(0x00000000ffffffffll & (uint64_t)v);
|
||||
#else
|
||||
return JSValueToNumber(ctx, v, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Hobo version to create an Int32 fast. Falls back to JSValueMakeNumber()
|
||||
// on 32bit systems.
|
||||
|
||||
static inline JSValueRef MakeInt32(JSContextRef ctx, int32_t number) {
|
||||
#if __LP64__
|
||||
return (0xffff000000000000ll | (uint64_t)number);
|
||||
#else
|
||||
return JSValueMakeNumber(ctx, number);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Shorthand to get a property by name
|
||||
|
||||
static JSValueRef GetPropertyNamed(JSContextRef ctx, JSObjectRef object, const char *name) {
|
||||
JSStringRef jsPropertyName = JSStringCreateWithUTF8CString(name);
|
||||
JSValueRef value = JSObjectGetProperty(ctx, object, jsPropertyName, NULL);
|
||||
JSStringRelease(jsPropertyName);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// Shorthand to get the Constructor for the given EJJSTypedArrayType
|
||||
|
||||
static JSObjectRef GetConstructor(JSContextRef ctx, EJJSTypedArrayType type) {
|
||||
if( type <= kEJJSTypedArrayTypeNone || type > kEJJSTypedArrayTypeArrayBuffer ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *constructorName = ConstructorNames[type];
|
||||
JSObjectRef global = JSContextGetGlobalObject(ctx);
|
||||
return (JSObjectRef)GetPropertyNamed(ctx, global, constructorName);
|
||||
}
|
||||
|
||||
|
||||
// Create a typed array view from another typed array or arraybuffer
|
||||
|
||||
static JSObjectRef GetView(JSContextRef ctx, JSObjectRef object, EJJSTypedArrayType type, size_t count) {
|
||||
EJJSTypedArrayType currentType = EJJSObjectGetTypedArrayType(ctx, object);
|
||||
if( currentType == kEJJSTypedArrayTypeNone ) {
|
||||
return NULL;
|
||||
}
|
||||
else if( currentType == type ) {
|
||||
return object;
|
||||
}
|
||||
|
||||
JSValueRef args[3];
|
||||
if( currentType == kEJJSTypedArrayTypeArrayBuffer ) {
|
||||
args[0] = object;
|
||||
args[1] = MakeInt32(ctx, 0);
|
||||
args[2] = MakeInt32(ctx, (int)count);
|
||||
}
|
||||
else {
|
||||
args[0] = GetPropertyNamed(ctx, object, "buffer");
|
||||
args[1] = GetPropertyNamed(ctx, object, "byteOffset");
|
||||
args[2] = MakeInt32(ctx, (int)count);
|
||||
}
|
||||
JSObjectRef constructor = GetConstructor(ctx, type);
|
||||
return JSObjectCallAsConstructor(ctx, constructor, 3, args, NULL);
|
||||
}
|
||||
|
||||
|
||||
// The callback called from JSObjectGetTypedArrayData with chunks of data. This writes
|
||||
// into the state's data.
|
||||
|
||||
typedef struct {
|
||||
int32_t *currentDataPtr;
|
||||
JSObjectRef jsGetCallback;
|
||||
JSObjectRef jsGetCallbackApply;
|
||||
} AppendDataCallbackState;
|
||||
|
||||
static JSValueRef AppendDataCallback(
|
||||
JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
|
||||
size_t argc, const JSValueRef argv[], JSValueRef* exception
|
||||
) {
|
||||
AppendDataCallbackState *state = JSObjectGetPrivate(thisObject);
|
||||
int32_t *dst = state->currentDataPtr;
|
||||
int remainderStart = 0;
|
||||
|
||||
// On 64bit systems where ARM_NEON instructions are available we can use
|
||||
// some SIMD intrinsics to extract the lower 32bit of each JSValueRef.
|
||||
// Hopefully the JSValueRef encodes an Int32 so the lower 32bit corresponds
|
||||
// to that Int32 exactly.
|
||||
|
||||
#if __LP64__ && defined __ARM_NEON__
|
||||
// Iterate over the arguments in packs of 4.
|
||||
// Load arguments as 2 lanes of 4 int32 values and store the first
|
||||
// lane (the lower 32bit) into the dst buffer.
|
||||
|
||||
int argPacks4 = (int)argc/4;
|
||||
int32_t *src = (int32_t*)argv;
|
||||
|
||||
for(int i = 0; i < argPacks4; i++ ) {
|
||||
const int32x4x2_t lanes32 = vld2q_s32(src);
|
||||
vst1q_s32(dst, lanes32.val[0]);
|
||||
src += 8;
|
||||
dst += 4;
|
||||
}
|
||||
remainderStart = argPacks4 * 4;
|
||||
#endif
|
||||
|
||||
for( int i = remainderStart; i < argc; i++ ) {
|
||||
*(dst++) = GetInt32(ctx, argv[i]);
|
||||
}
|
||||
|
||||
state->currentDataPtr += argc;
|
||||
return MakeInt32(ctx, (int)argc);
|
||||
}
|
||||
|
||||
|
||||
// To store the AppendDataCallbackState and access it _per context_, we create
|
||||
// a plain JSObject where we can store a pointer to the state in the private
|
||||
// data.
|
||||
|
||||
static void FinalizeAppendDataCallbackState(JSObjectRef object) {
|
||||
AppendDataCallbackState *state = JSObjectGetPrivate(object);
|
||||
free(state);
|
||||
}
|
||||
|
||||
static JSObjectRef CreateAppendDataCallbackState(JSContextRef ctx) {
|
||||
// Create a JS function that calls the AppendDataCallback
|
||||
JSObjectRef jsAppendDataCallback = JSObjectMakeFunctionWithCallback(ctx, NULL, AppendDataCallback);
|
||||
JSValueProtect(ctx, jsAppendDataCallback);
|
||||
|
||||
// Allocate and create the state and attach the AppendDataCallback
|
||||
// function and its .apply property.
|
||||
AppendDataCallbackState *state = malloc(sizeof(AppendDataCallbackState));
|
||||
state->currentDataPtr = NULL;
|
||||
state->jsGetCallback = jsAppendDataCallback;
|
||||
state->jsGetCallbackApply = (JSObjectRef)GetPropertyNamed(ctx, jsAppendDataCallback, "apply");
|
||||
|
||||
|
||||
// Create the empty js object that holds the state in its Private data
|
||||
JSClassDefinition internalStateClassDef = kJSClassDefinitionEmpty;
|
||||
internalStateClassDef.finalize = FinalizeAppendDataCallbackState;
|
||||
|
||||
JSClassRef internalStateClass = JSClassCreate(&internalStateClassDef);
|
||||
JSObjectRef internalStateObject = JSObjectMake(ctx, internalStateClass, state);
|
||||
JSClassRelease(internalStateClass);
|
||||
return internalStateObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void EJJSContextPrepareTypedArrayAPI(JSContextRef ctx) {
|
||||
// The __ejTypedArrayType property is read only, not enumerable
|
||||
JSPropertyAttributes attributes =
|
||||
kJSPropertyAttributeReadOnly |
|
||||
kJSPropertyAttributeDontEnum |
|
||||
kJSPropertyAttributeDontDelete;
|
||||
|
||||
// Install the __ejTypedArrayType property on each Typed Array prototype
|
||||
JSStringRef jsTypeName = JSStringCreateWithUTF8CString("__ejTypedArrayType");
|
||||
|
||||
for( int type = kEJJSTypedArrayTypeInt8Array; type <= kEJJSTypedArrayTypeArrayBuffer; type++ ) {
|
||||
JSObjectRef jsConstructor = GetConstructor(ctx, type);
|
||||
JSObjectRef jsPrototype = (JSObjectRef)GetPropertyNamed(ctx, jsConstructor, "prototype");
|
||||
|
||||
JSValueRef jsType = MakeInt32(ctx, type);
|
||||
JSObjectSetProperty(ctx, jsPrototype, jsTypeName, jsType, attributes, NULL);
|
||||
}
|
||||
|
||||
JSStringRelease(jsTypeName);
|
||||
|
||||
|
||||
// Create the state object for the AppendData Callback and attach it to the global
|
||||
// object
|
||||
JSObjectRef jsCallbackStateObject = CreateAppendDataCallbackState(ctx);
|
||||
|
||||
JSStringRef jsInternalStateName = JSStringCreateWithUTF8CString("__ejTypedArrayState");
|
||||
JSObjectRef global = JSContextGetGlobalObject(ctx);
|
||||
JSObjectSetProperty(ctx, global, jsInternalStateName, jsCallbackStateObject, attributes, NULL);
|
||||
JSStringRelease(jsInternalStateName);
|
||||
}
|
||||
|
||||
|
||||
EJJSTypedArrayType EJJSObjectGetTypedArrayType(JSContextRef ctx, JSObjectRef object) {
|
||||
JSValueRef jsType = GetPropertyNamed(ctx, object, "__ejTypedArrayType");
|
||||
return jsType ? GetInt32(ctx, jsType) : kEJJSTypedArrayTypeNone;
|
||||
}
|
||||
|
||||
JSObjectRef EJJSObjectMakeTypedArray(JSContextRef ctx, EJJSTypedArrayType arrayType, size_t numElements) {
|
||||
JSObjectRef jsConstructor = GetConstructor(ctx, arrayType);
|
||||
if( !jsConstructor ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSValueRef jsNumElements = MakeInt32(ctx, (int)numElements);
|
||||
return JSObjectCallAsConstructor(ctx, jsConstructor, 1, (JSValueRef[]){jsNumElements}, NULL);
|
||||
}
|
||||
|
||||
|
||||
NSMutableData *EJJSObjectGetTypedArrayData(JSContextRef ctx, JSObjectRef object) {
|
||||
size_t length = GetInt32(ctx, GetPropertyNamed(ctx, object, "byteLength"));
|
||||
if( !length ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t int32Count = length / 4;
|
||||
size_t uint8Count = length % 4;
|
||||
|
||||
// For very small typed arrays it's faster to read all bytes individually
|
||||
// instead of doing the callback dance.
|
||||
if( length < CopyInChunksThreshold ) {
|
||||
int32Count = 0;
|
||||
uint8Count = length;
|
||||
}
|
||||
|
||||
NSMutableData *data = [NSMutableData dataWithLength:length];
|
||||
|
||||
// Read data in large chunks of 32bit values
|
||||
if( int32Count ) {
|
||||
JSObjectRef int32View = GetView(ctx, object, kEJJSTypedArrayTypeInt32Array, int32Count);
|
||||
if( !int32View ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSObjectRef jsState = (JSObjectRef)GetPropertyNamed(ctx, JSContextGetGlobalObject(ctx), "__ejTypedArrayState");
|
||||
AppendDataCallbackState *state = JSObjectGetPrivate(jsState);
|
||||
state->currentDataPtr = data.mutableBytes;
|
||||
|
||||
|
||||
// If the whole data is smaller than the chunk size, we only have to call our callback once, otherwise
|
||||
// we have to create subarrays and call the callback with these.
|
||||
if( int32Count < CopyChunkSize ) {
|
||||
JSValueRef getArgs[] = {jsState, int32View};
|
||||
JSObjectCallAsFunction(ctx, state->jsGetCallbackApply, state->jsGetCallback, 2, getArgs, NULL);
|
||||
}
|
||||
else {
|
||||
JSObjectRef subarrayFunc = (JSObjectRef)GetPropertyNamed(ctx, int32View, "subarray");
|
||||
|
||||
for( int i = 0; i < int32Count; i+= CopyChunkSize) {
|
||||
JSValueRef subarrayArgs[] = {MakeInt32(ctx, i), MakeInt32(ctx, i + CopyChunkSize)};
|
||||
JSObjectRef jsSubarray = (JSObjectRef)JSObjectCallAsFunction(ctx, subarrayFunc, int32View, 2, subarrayArgs, NULL);
|
||||
|
||||
JSValueRef getArgs[] = {jsState, jsSubarray};
|
||||
JSObjectCallAsFunction(ctx, state->jsGetCallbackApply, state->jsGetCallback, 2, getArgs, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read remaining bytes directly
|
||||
if( uint8Count ) {
|
||||
uint8_t *values8 = data.mutableBytes;
|
||||
JSObjectRef uint8View = GetView(ctx, object, kEJJSTypedArrayTypeUint8Array, length);
|
||||
for( int i = 0; i < uint8Count; i++ ) {
|
||||
int index = (int)int32Count * 4 + i;
|
||||
values8[index] = GetInt32(ctx, JSObjectGetPropertyAtIndex(ctx, uint8View, index, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void EJJSObjectSetTypedArrayData(JSContextRef ctx, JSObjectRef object, NSData *data) {
|
||||
size_t int32Count = data.length / 4;
|
||||
size_t uint8Count = data.length % 4;
|
||||
|
||||
if( int32Count ) {
|
||||
JSObjectRef int32View = GetView(ctx, object, kEJJSTypedArrayTypeInt32Array, int32Count);
|
||||
if( !int32View ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Construct the JSValues and create the plain JSArray
|
||||
JSValueRef *jsValues = malloc(int32Count * sizeof(JSValueRef));
|
||||
|
||||
const int32_t *values32 = data.bytes;
|
||||
for(int i = 0; i < int32Count; i++) {
|
||||
jsValues[i] = MakeInt32(ctx, values32[i]);
|
||||
}
|
||||
JSObjectRef jsArray = JSObjectMakeArray(ctx, int32Count, jsValues, NULL);
|
||||
|
||||
free(jsValues);
|
||||
|
||||
// Call the .set() function on the Typed Array
|
||||
JSObjectRef setFunction = (JSObjectRef)GetPropertyNamed(ctx, int32View, "set");
|
||||
JSObjectCallAsFunction(ctx, setFunction, int32View, 1, (JSValueRef[]){jsArray}, NULL);
|
||||
}
|
||||
|
||||
// Set remaining bytes directly
|
||||
if( uint8Count ) {
|
||||
const uint8_t *values8 = data.bytes;
|
||||
JSObjectRef uint8View = GetView(ctx, object, kEJJSTypedArrayTypeUint8Array, data.length);
|
||||
for( int i = 0; i < uint8Count; i++ ) {
|
||||
int index = (int)int32Count * 4 + i;
|
||||
JSObjectSetPropertyAtIndex(ctx, uint8View, index, MakeInt32(ctx, values8[index]), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define SE_UNUSED __attribute__ ((unused))
|
||||
#else
|
||||
#define SE_UNUSED
|
||||
#endif
|
||||
|
||||
#define SAFE_INC_REF(obj) if (obj != nullptr) obj->incRef()
|
||||
#define SAFE_DEC_REF(obj) if ((obj) != nullptr) { (obj)->decRef(); (obj) = nullptr; }
|
||||
|
||||
#define _SE(name) name##Registry
|
||||
|
||||
#define SE_DECLARE_FUNC(funcName) \
|
||||
JSValueRef funcName##Registry(JSContextRef _cx, JSObjectRef _function, JSObjectRef _thisObject, size_t argc, const JSValueRef _argv[], JSValueRef* _exception)
|
||||
|
||||
|
||||
#define SE_BIND_FUNC(funcName) \
|
||||
JSValueRef funcName##Registry(JSContextRef _cx, JSObjectRef _function, JSObjectRef _thisObject, size_t _argc, const JSValueRef _argv[], JSValueRef* _exception) \
|
||||
{ \
|
||||
unsigned short argc = (unsigned short) _argc; \
|
||||
JSValueRef _jsRet = JSValueMakeUndefined(_cx); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_thisObject); \
|
||||
if (nativeThisObject != (void*)std::numeric_limits<unsigned long>::max()) \
|
||||
{ \
|
||||
bool ret = true; \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(_cx, argc, _argv, &args); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
se::internal::seToJsValue(_cx, state.rval(), &_jsRet); \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
#define SE_BIND_FINALIZE_FUNC(funcName) \
|
||||
void funcName##Registry(JSObjectRef _obj) \
|
||||
{ \
|
||||
auto se = se::ScriptEngine::getInstance(); \
|
||||
se->_setGarbageCollecting(true); \
|
||||
void* nativeThisObject = JSObjectGetPrivate(_obj); \
|
||||
if (nativeThisObject != nullptr) \
|
||||
{ \
|
||||
bool ret = false; \
|
||||
se::State state(nativeThisObject); \
|
||||
se::Object* _thisObject = state.thisObject(); \
|
||||
if (_thisObject) _thisObject->_cleanup(nativeThisObject); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
JSObjectSetPrivate(_obj, nullptr); \
|
||||
SAFE_DEC_REF(_thisObject); \
|
||||
} \
|
||||
se->_setGarbageCollecting(false); \
|
||||
}
|
||||
|
||||
#define SE_DECLARE_FINALIZE_FUNC(funcName) \
|
||||
void funcName##Registry(JSObjectRef _obj);
|
||||
|
||||
|
||||
// NOTE: se::Object::createObjectWithClass(cls) will return a se::Object pointer which is watched by garbage collector.
|
||||
// If there is a '_ctor' function of current class, '_property.toObject->call(...)' will be invoked which is an operation that may
|
||||
// make garbage collector to mark the created JS object as a garbage and set it to an invalid state.
|
||||
// If this happens, crash will be triggered. So please take care of the value returned from se::Object::createObjectWithClass.
|
||||
// HOW TO FIX: Use a rooted se::Value to save the se::Object poiner returned by se::Object::createObjectWithClass.
|
||||
#define SE_BIND_CTOR(funcName, cls, finalizeCb) \
|
||||
JSObjectRef funcName##Registry(JSContextRef _cx, JSObjectRef _constructor, size_t argc, const JSValueRef _argv[], JSValueRef* _exception) \
|
||||
{ \
|
||||
bool ret = true; \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(_cx, argc, _argv, &args); \
|
||||
se::Value thisVal(se::Object::createObjectWithClass(cls), true); \
|
||||
se::Object* thisObject = thisVal.toObject(); \
|
||||
JSValueRef _jsRet = JSValueMakeUndefined(_cx); \
|
||||
se::State state(thisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (ret) \
|
||||
{ \
|
||||
_jsRet = thisObject->_getJSObject(); \
|
||||
se::Value _property; \
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return JSValueToObject(_cx, _jsRet, nullptr); \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_SUB_CLS_CTOR(funcName, cls, finalizeCb) \
|
||||
JSValueRef funcName##Registry(JSContextRef _cx, JSObjectRef _function, JSObjectRef _thisObject, size_t argc, const JSValueRef _argv[], JSValueRef* _exception) \
|
||||
{ \
|
||||
bool ret = true; \
|
||||
JSValueRef _jsRet = JSValueMakeUndefined(_cx); \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(_cx, argc, _argv, &args); \
|
||||
se::Object* thisObject = se::Object::_createJSObject(cls, _thisObject); \
|
||||
thisObject->_setFinalizeCallback(_SE(finalizeCb)); \
|
||||
se::State state(thisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (ret) \
|
||||
{ \
|
||||
se::Value _property; \
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_PROP_GET(funcName) \
|
||||
JSValueRef funcName##Registry(JSContextRef _cx, JSObjectRef _function, JSObjectRef _thisObject, size_t argc, const JSValueRef _argv[], JSValueRef* _exception) \
|
||||
{ \
|
||||
assert(argc == 0); \
|
||||
JSValueRef _jsRet = JSValueMakeUndefined(_cx); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_thisObject); \
|
||||
if (nativeThisObject != (void*)std::numeric_limits<unsigned long>::max()) \
|
||||
{ \
|
||||
se::State state(nativeThisObject); \
|
||||
if (funcName(state)) \
|
||||
{ \
|
||||
se::internal::seToJsValue(_cx, state.rval(), &_jsRet); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_PROP_SET(funcName) \
|
||||
JSValueRef funcName##Registry(JSContextRef _cx, JSObjectRef _function, JSObjectRef _thisObject, size_t argc, const JSValueRef _argv[], JSValueRef* _exception) \
|
||||
{ \
|
||||
assert(argc == 1); \
|
||||
JSValueRef _jsRet = JSValueMakeUndefined(_cx); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_thisObject); \
|
||||
if (nativeThisObject != (void*)std::numeric_limits<unsigned long>::max()) \
|
||||
{ \
|
||||
bool ret = true; \
|
||||
se::Value data; \
|
||||
se::internal::jsToSeValue(_cx, _argv[0], &data); \
|
||||
se::ValueArray args; \
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
} \
|
||||
return _jsRet; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define SE_TYPE_NAME(t) typeid(t).name()
|
||||
|
||||
#define SE_QUOTEME_(x) #x
|
||||
#define SE_QUOTEME(x) SE_QUOTEME_(x)
|
||||
|
||||
//IDEA: implement this macro
|
||||
#define SE_REPORT_ERROR(fmt, ...) SE_LOGE("[ERROR] (" __FILE__ ", " SE_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
#if COCOS2D_DEBUG > 0
|
||||
|
||||
#define SE_ASSERT(cond, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (!(cond)) \
|
||||
{ \
|
||||
SE_LOGE("ASSERT (" __FILE__ ", " SE_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__); \
|
||||
assert(false); \
|
||||
} \
|
||||
} while(false)
|
||||
|
||||
#else
|
||||
|
||||
#define SE_ASSERT(cond, fmt, ...)
|
||||
|
||||
#endif // #if COCOS2D_DEBUG > 0
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
@@ -0,0 +1,424 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Base.h"
|
||||
#include "../Value.hpp"
|
||||
#include "../RefCounter.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Class;
|
||||
|
||||
/**
|
||||
* se::Object represents JavaScript Object.
|
||||
*/
|
||||
class Object final : public RefCounter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a JavaScript Object like `{} or new Object()`.
|
||||
* @return A JavaScript Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createPlainObject();
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Array Object like `[] or new Array()`.
|
||||
* @param[in] length The initical length of array.
|
||||
* @return A JavaScript Array Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createArrayObject(size_t length);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Typed Array Object with uint8 format from an existing pointer.
|
||||
* @param[in] bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object.
|
||||
* @param[in] byteLength The number of bytes pointed to by the parameter bytes.
|
||||
* @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
* @deprecated This method is deprecated, please use `se::Object::createTypedArray` instead.
|
||||
*/
|
||||
SE_DEPRECATED_ATTRIBUTE static Object* createUint8TypedArray(uint8_t* bytes, size_t byteLength);
|
||||
|
||||
enum class TypedArrayType
|
||||
{
|
||||
NONE,
|
||||
INT8,
|
||||
INT16,
|
||||
INT32,
|
||||
UINT8,
|
||||
UINT8_CLAMPED,
|
||||
UINT16,
|
||||
UINT32,
|
||||
FLOAT32,
|
||||
FLOAT64
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Typed Array Object with specified format from an existing pointer,
|
||||
if provide a null pointer,then will create a empty JavaScript Typed Array Object.
|
||||
* @param[in] type The format of typed array.
|
||||
* @param[in] data A pointer to the byte buffer to be used as the backing store of the Typed Array object.
|
||||
* @param[in] byteLength The number of bytes pointed to by the parameter bytes.
|
||||
* @return A JavaScript Typed Array Object whose backing store is the same as the one pointed data, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createTypedArray(TypedArrayType type, void* data, size_t byteLength);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Array Buffer object from an existing pointer.
|
||||
* @param[in] bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object.
|
||||
* @param[in] byteLength The number of bytes pointed to by the parameter bytes.
|
||||
* @return A Array Buffer Object whose backing store is the same as the one pointed to data, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createArrayBufferObject(void* bytes, size_t byteLength);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Object from a JSON formatted string.
|
||||
* @param[in] jsonStr The utf-8 string containing the JSON string to be parsed.
|
||||
* @return A JavaScript Object containing the parsed value, or nullptr if the input is invalid.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createJSONObject(const std::string& jsonStr);
|
||||
|
||||
/**
|
||||
* @brief Creates a JavaScript Native Binding Object from an existing se::Class instance.
|
||||
* @param[in] cls The se::Class instance which stores native callback informations.
|
||||
* @return A JavaScript Native Binding Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* createObjectWithClass(Class* cls);
|
||||
|
||||
/**
|
||||
* @brief Gets a se::Object from an existing native object pointer.
|
||||
* @param[in] ptr The native object pointer associated with the se::Object
|
||||
* @return A JavaScript Native Binding Object, or nullptr if there is an error.
|
||||
* @note The return value (non-null) has to be released manually.
|
||||
*/
|
||||
static Object* getObjectWithPtr(void* ptr);
|
||||
|
||||
/**
|
||||
* @brief Gets a property from an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @param[out] value The property's value if object has the property, otherwise the undefined value.
|
||||
* @return true if object has the property, otherwise false.
|
||||
*/
|
||||
bool getProperty(const char* name, Value* value);
|
||||
|
||||
/**
|
||||
* @brief Sets a property to an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @param[in] value A value to be used as the property's value.
|
||||
* @return true if the property is set successfully, otherwise false.
|
||||
*/
|
||||
bool setProperty(const char* name, const Value& value);
|
||||
|
||||
/**
|
||||
* @brief Delete a property of an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @return true if the property is deleted successfully, otherwise false.
|
||||
*/
|
||||
bool deleteProperty(const char *name);
|
||||
|
||||
/**
|
||||
* @brief Defines a property with native accessor callbacks for an object.
|
||||
* @param[in] name A utf-8 string containing the property's name.
|
||||
* @param[in] getter The native callback for getter.
|
||||
* @param[in] setter The native callback for setter.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineProperty(const char *name, JSObjectCallAsFunctionCallback getter, JSObjectCallAsFunctionCallback setter);
|
||||
|
||||
/**
|
||||
* @brief Defines a function with a native callback for an object.
|
||||
* @param[in] funcName A utf-8 string containing the function name.
|
||||
* @param[in] func The native callback triggered by JavaScript code.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFunction(const char *funcName, JSObjectCallAsFunctionCallback func);
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object can be called as a function.
|
||||
* @return true if object can be called as a function, otherwise false.
|
||||
*/
|
||||
bool isFunction() const;
|
||||
|
||||
/**
|
||||
* @brief Calls an object as a function.
|
||||
* @param[in] args A se::Value array of arguments to pass to the function. Pass se::EmptyValueArray if argumentCount is 0.
|
||||
* @param[in] thisObject The object to use as "this," or NULL to use the global object as "this."
|
||||
* @param[out] rval The se::Value that results from calling object as a function, passing nullptr if return value is ignored.
|
||||
* @return true if object is a function and there isn't any errors, otherwise false.
|
||||
*/
|
||||
bool call(const ValueArray& args, Object* thisObject, Value* rval = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object is an array.
|
||||
* @return true if object is an array, otherwise false.
|
||||
*/
|
||||
bool isArray() const;
|
||||
|
||||
/**
|
||||
* @brief Gets array length of an array object.
|
||||
* @param[out] length The array length to be stored. It's set to 0 if there is an error.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getArrayLength(uint32_t* length) const;
|
||||
|
||||
/**
|
||||
* @brief Gets an element from an array object by numeric index.
|
||||
* @param[in] index An integer value for index.
|
||||
* @param[out] data The se::Value to be stored for the element in certain index.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getArrayElement(uint32_t index, Value* data) const;
|
||||
|
||||
/**
|
||||
* @brief Sets an element to an array object by numeric index.
|
||||
* @param[in] index An integer value for index.
|
||||
* @param[in] data The se::Value to be set to array with certain index.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool setArrayElement(uint32_t index, const Value& data);
|
||||
|
||||
/** @brief Tests whether an object is a typed array.
|
||||
* @return true if object is a typed array, otherwise false.
|
||||
*/
|
||||
bool isTypedArray() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the type of a typed array object.
|
||||
* @return The type of a typed array object.
|
||||
*/
|
||||
TypedArrayType getTypedArrayType() const;
|
||||
|
||||
/**
|
||||
* @brief Gets backing store of a typed array object.
|
||||
* @param[out] ptr A temporary pointer to the backing store of a JavaScript Typed Array object.
|
||||
* @param[out] length The byte length of a JavaScript Typed Array object.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getTypedArrayData(uint8_t** ptr, size_t* length) const;
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object is an array buffer object.
|
||||
* @return true if object is an array buffer object, otherwise false.
|
||||
*/
|
||||
bool isArrayBuffer() const;
|
||||
|
||||
/**
|
||||
* @brief Gets buffer data of an array buffer object.
|
||||
* @param[out] ptr A pointer to the data buffer that serves as the backing store for a JavaScript Typed Array object.
|
||||
* @param[out] length The number of bytes in a JavaScript data object.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getArrayBufferData(uint8_t** ptr, size_t* length) const;
|
||||
|
||||
/**
|
||||
* @brief Gets all property names of an object.
|
||||
* @param[out] allKeys A string vector to store all property names.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool getAllKeys(std::vector<std::string>* allKeys) const;
|
||||
|
||||
/**
|
||||
* @brief Sets a pointer to private data on an object.
|
||||
* @param[in] data A void* to set as the object's private data.
|
||||
* @note This method will associate private data with se::Object by std::unordered_map::emplace.
|
||||
* It's used for search a se::Object via a void* private data.
|
||||
*/
|
||||
void setPrivateData(void* data);
|
||||
|
||||
/**
|
||||
* @brief Gets an object's private data.
|
||||
* @return A void* that is the object's private data, if the object has private data, otherwise nullptr.
|
||||
*/
|
||||
void* getPrivateData() const;
|
||||
|
||||
/**
|
||||
* @brief Clears private data of an object.
|
||||
* @param clearMapping Whether to clear the mapping of native object & se::Object.
|
||||
*/
|
||||
void clearPrivateData(bool clearMapping = true);
|
||||
|
||||
/**
|
||||
* @brief Roots an object from garbage collection.
|
||||
* @note Use this method when you want to store an object in a global or on the heap, where the garbage collector will not be able to discover your reference to it.
|
||||
* An object may be rooted multiple times and must be unrooted an equal number of times before becoming eligible for garbage collection.
|
||||
*/
|
||||
void root();
|
||||
|
||||
/**
|
||||
* @brief Unroots an object from garbage collection.
|
||||
* @note An object may be rooted multiple times and must be unrooted an equal number of times before becoming eligible for garbage collection.
|
||||
*/
|
||||
void unroot();
|
||||
|
||||
/**
|
||||
* @brief Tests whether an object is rooted.
|
||||
* @return true if it has been already rooted, otherwise false.
|
||||
*/
|
||||
bool isRooted() const;
|
||||
|
||||
/**
|
||||
* @brief Tests whether two objects are strict equal, as compared by the JS === operator.
|
||||
* @param[in] o The object to be tested with this object.
|
||||
* @return true if the two values are strict equal, otherwise false.
|
||||
*/
|
||||
bool strictEquals(Object* o) const;
|
||||
|
||||
/**
|
||||
* @brief Attaches an object to current object.
|
||||
* @param[in] obj The object to be attached.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note This method will set `obj` as a property of current object, therefore the lifecycle of child object will depend on current object,
|
||||
* which means `obj` may be garbage collected only after current object is garbage collected.
|
||||
* It's normally used in binding a native callback method. For example:
|
||||
|
||||
```javascript
|
||||
var self = this;
|
||||
someObject.setCallback(function(){}, self);
|
||||
```
|
||||
|
||||
```c++
|
||||
static bool SomeObject_setCallback(se::State& s)
|
||||
{
|
||||
SomeObject* cobj = (SomeObject*)s.nativeThisObject();
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 2) {
|
||||
std::function<void()> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(args[1]);
|
||||
se::Value jsFunc(args[0]);
|
||||
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
|
||||
auto lambda = [=]() -> void {
|
||||
...
|
||||
// Call jsFunc stuff...
|
||||
...
|
||||
};
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false);
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
cobj->setCallback(arg0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
```
|
||||
*/
|
||||
bool attachObject(Object* obj);
|
||||
|
||||
/**
|
||||
* @brief Detaches an object from current object.
|
||||
* @param[in] obj The object to be detached.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note The attached object will not be released if current object is not garbage collected.
|
||||
*/
|
||||
bool detachObject(Object* obj);
|
||||
|
||||
/**
|
||||
* @brief Returns the string for describing current object.
|
||||
* @return The string for describing current object.
|
||||
*/
|
||||
std::string toString() const;
|
||||
|
||||
// Private API used in wrapper
|
||||
static Object* _createJSObject(Class* cls, JSObjectRef obj);
|
||||
JSObjectRef _getJSObject() const;
|
||||
Class* _getClass() const;
|
||||
void _setFinalizeCallback(JSObjectFinalizeCallback finalizeCb);
|
||||
|
||||
void _cleanup(void* nativeObject = nullptr);
|
||||
bool _isNativeFunction() const;
|
||||
//
|
||||
|
||||
private:
|
||||
static void setContext(JSContextRef cx);
|
||||
static void cleanup();
|
||||
|
||||
Object();
|
||||
virtual ~Object();
|
||||
|
||||
bool init(Class* cls, JSObjectRef obj);
|
||||
|
||||
enum class Type : char
|
||||
{
|
||||
UNKNOWN,
|
||||
PLAIN,
|
||||
ARRAY,
|
||||
ARRAY_BUFFER,
|
||||
TYPED_ARRAY_INT8,
|
||||
TYPED_ARRAY_INT16,
|
||||
TYPED_ARRAY_INT32,
|
||||
TYPED_ARRAY_UINT8,
|
||||
TYPED_ARRAY_UINT8_CLAMPED,
|
||||
TYPED_ARRAY_UINT16,
|
||||
TYPED_ARRAY_UINT32,
|
||||
TYPED_ARRAY_FLOAT32,
|
||||
TYPED_ARRAY_FLOAT64,
|
||||
FUNCTION
|
||||
};
|
||||
|
||||
Class* _cls;
|
||||
JSObjectRef _obj;
|
||||
void* _privateData;
|
||||
JSObjectFinalizeCallback _finalizeCb;
|
||||
|
||||
uint32_t _rootCount;
|
||||
uint32_t _currentVMId;
|
||||
#if SE_DEBUG > 0
|
||||
public:
|
||||
uint32_t _id;
|
||||
private:
|
||||
#endif
|
||||
bool _isCleanup;
|
||||
|
||||
mutable Type _type;
|
||||
|
||||
friend class ScriptEngine;
|
||||
friend class AutoHandleScope;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
namespace se {
|
||||
|
||||
bool isSupportTypedArrayAPI();
|
||||
bool isSupportArrayTestAPI();
|
||||
|
||||
} // namespace se
|
||||
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "PlatformUtils.h"
|
||||
#include "../config.hpp"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIKit.h>
|
||||
#elif TARGET_OS_MAC
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
namespace se {
|
||||
|
||||
bool isSupportTypedArrayAPI()
|
||||
{
|
||||
static bool isSupported = false;
|
||||
static bool isInited = false;
|
||||
if (!isInited)
|
||||
{
|
||||
#if TARGET_OS_IPHONE
|
||||
float version = [[UIDevice currentDevice].systemVersion floatValue];
|
||||
isSupported = (version >= 10.0f);
|
||||
#elif TARGET_OS_MAC
|
||||
NSOperatingSystemVersion minimumSupportedOSVersion = { .majorVersion = 10, .minorVersion = 12, .patchVersion = 0 };
|
||||
isSupported = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:minimumSupportedOSVersion] ? true : false;
|
||||
#else
|
||||
SE_LOGE("isSupportTypedArrayAPI: Unknown system!");
|
||||
#endif
|
||||
isInited = true;
|
||||
}
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
bool isSupportArrayTestAPI()
|
||||
{
|
||||
static bool isSupported = false;
|
||||
static bool isInited = false;
|
||||
if (!isInited)
|
||||
{
|
||||
#if TARGET_OS_IPHONE
|
||||
float version = [[UIDevice currentDevice].systemVersion floatValue];
|
||||
isSupported = (version >= 9.0f);
|
||||
#elif TARGET_OS_MAC
|
||||
NSOperatingSystemVersion minimumSupportedOSVersion = { .majorVersion = 10, .minorVersion = 11, .patchVersion = 0 };
|
||||
isSupported = [NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:minimumSupportedOSVersion] ? true : false;
|
||||
#else
|
||||
SE_LOGE("isSupportArrayTestAPI: Unknown system!");
|
||||
#endif
|
||||
isInited = true;
|
||||
}
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
} // namespace se
|
||||
@@ -0,0 +1,331 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Base.h"
|
||||
#include <thread>
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
class Class;
|
||||
class Value;
|
||||
|
||||
extern Class* __jsb_CCPrivateData_class;
|
||||
|
||||
/**
|
||||
* A stack-allocated class that governs a number of local handles.
|
||||
* It's only implemented for v8 wrapper now.
|
||||
* Other script engine wrappers have empty implementation for this class.
|
||||
* It's used at the beginning of executing any wrapper API.
|
||||
*/
|
||||
class AutoHandleScope
|
||||
{
|
||||
public:
|
||||
AutoHandleScope();
|
||||
~AutoHandleScope();
|
||||
};
|
||||
|
||||
/**
|
||||
* ScriptEngine is a sington which represents a context of JavaScript VM.
|
||||
*/
|
||||
class ScriptEngine final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Gets or creates the instance of script engine.
|
||||
* @return The script engine instance.
|
||||
*/
|
||||
static ScriptEngine* getInstance();
|
||||
|
||||
/**
|
||||
* @brief Destroys the instance of script engine.
|
||||
*/
|
||||
static void destroyInstance();
|
||||
|
||||
/**
|
||||
* @brief Gets the global object of JavaScript VM.
|
||||
* @return The se::Object stores the global JavaScript object.
|
||||
*/
|
||||
Object* getGlobalObject();
|
||||
|
||||
typedef bool (*RegisterCallback)(Object*);
|
||||
|
||||
/**
|
||||
* @brief Adds a callback for registering a native binding module.
|
||||
* @param[in] cb A callback for registering a native binding module.
|
||||
* @note This method just add a callback to a vector, callbacks is invoked in `start` method.
|
||||
*/
|
||||
void addRegisterCallback(RegisterCallback cb);
|
||||
|
||||
/**
|
||||
* @brief Starts the script engine.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note This method will invoke all callbacks of native binding modules by the order of registration.
|
||||
*/
|
||||
bool start();
|
||||
|
||||
/**
|
||||
* @brief Initializes script engine.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note This method will create JavaScript context and global object.
|
||||
*/
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after initializing script engine.
|
||||
* @param[in] hook A hook function to be invoked before initializing script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterInitHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Cleanups script engine.
|
||||
* @note This method will removes all objects in JavaScript VM even whose are rooted, then shutdown JavaScript VMf.
|
||||
*/
|
||||
void cleanup();
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function before cleanuping script engine.
|
||||
* @param[in] hook A hook function to be invoked before cleanuping script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addBeforeCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Adds a hook function after cleanuping script engine.
|
||||
* @param[in] hook A hook function to be invoked after cleanuping script engine.
|
||||
* @note Multiple hook functions could be added, they will be invoked by the order of adding.
|
||||
*/
|
||||
void addAfterCleanupHook(const std::function<void()>& hook);
|
||||
|
||||
/**
|
||||
* @brief Executes a utf-8 string buffer which contains JavaScript code.
|
||||
* @param[in] scriptStr A utf-8 string buffer, if it isn't null-terminated, parameter `length` should be assigned and > 0.
|
||||
* @param[in] length The length of parameter `scriptStr`, it will be set to string length internally if passing < 0 and parameter `scriptStr` is null-terminated.
|
||||
* @param[in] rval The se::Value that results from evaluating script. Passing nullptr if you don't care about the result.
|
||||
* @param[in] fileName A string containing a URL for the script's source file. This is used by debuggers and when reporting exceptions. Pass NULL if you do not care to include source file information.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool evalString(const char* scriptStr, ssize_t length = -1, Value* rval = nullptr, const char* fileName = nullptr);
|
||||
|
||||
/**
|
||||
* Delegate class for file operation
|
||||
*/
|
||||
class FileOperationDelegate
|
||||
{
|
||||
public:
|
||||
FileOperationDelegate()
|
||||
: onGetDataFromFile(nullptr)
|
||||
, onGetStringFromFile(nullptr)
|
||||
, onCheckFileExist(nullptr)
|
||||
, onGetFullPath(nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Tests whether delegate is valid.
|
||||
*/
|
||||
bool isValid() const {
|
||||
return onGetDataFromFile != nullptr
|
||||
&& onGetStringFromFile != nullptr
|
||||
&& onCheckFileExist != nullptr
|
||||
&& onGetFullPath != nullptr; }
|
||||
|
||||
// path, buffer, buffer size
|
||||
std::function<void(const std::string&, const std::function<void(const uint8_t*, size_t)>& )> onGetDataFromFile;
|
||||
// path, return file string content.
|
||||
std::function<std::string(const std::string&)> onGetStringFromFile;
|
||||
// path
|
||||
std::function<bool(const std::string&)> onCheckFileExist;
|
||||
// path, return full path
|
||||
std::function<std::string(const std::string&)> onGetFullPath;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Sets the delegate for file operation.
|
||||
* @param delegate[in] The delegate instance for file operation.
|
||||
*/
|
||||
void setFileOperationDelegate(const FileOperationDelegate& delegate);
|
||||
|
||||
/**
|
||||
* @brief Gets the delegate for file operation.
|
||||
* @return The delegate for file operation
|
||||
*/
|
||||
const FileOperationDelegate& getFileOperationDelegate() const;
|
||||
|
||||
/**
|
||||
* @brief Executes a file which contains JavaScript code.
|
||||
* @param[in] path Script file path.
|
||||
* @param[in] rval The se::Value that results from evaluating script. Passing nullptr if you don't care about the result.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool runScript(const std::string& path, Value* rval = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Tests whether script engine is doing garbage collection.
|
||||
* @return true if it's in garbage collection, otherwise false.
|
||||
*/
|
||||
bool isGarbageCollecting();
|
||||
|
||||
/**
|
||||
* @brief Performs a JavaScript garbage collection.
|
||||
*/
|
||||
void garbageCollect();
|
||||
|
||||
/**
|
||||
* @brief Tests whether script engine is being cleaned up.
|
||||
* @return true if it's in cleaning up, otherwise false.
|
||||
*/
|
||||
bool isInCleanup() { return _isInCleanup; }
|
||||
|
||||
/**
|
||||
* @brief Tests whether script engine is valid.
|
||||
* @return true if it's valid, otherwise false.
|
||||
*/
|
||||
bool isValid() { return _isValid; }
|
||||
|
||||
/**
|
||||
* @brief Clears all exceptions.
|
||||
*/
|
||||
void clearException();
|
||||
|
||||
using ExceptionCallback = std::function<void(const char*, const char*, const char*)>; // location, message, stack
|
||||
|
||||
/**
|
||||
* @brief Sets the callback function while an exception is fired.
|
||||
* @param[in] cb The callback function to notify that an exception is fired.
|
||||
*/
|
||||
void setExceptionCallback(const ExceptionCallback& cb);
|
||||
|
||||
/**
|
||||
* @brief Sets the callback function while an exception is fired in JS.
|
||||
* @param[in] cb The callback function to notify that an exception is fired.
|
||||
*/
|
||||
void setJSExceptionCallback(const ExceptionCallback& cb);
|
||||
/**
|
||||
* @brief Gets the start time of script engine.
|
||||
* @return The start time of script engine.
|
||||
*/
|
||||
const std::chrono::steady_clock::time_point& getStartTime() const { return _startTime; }
|
||||
|
||||
/**
|
||||
* @brief Enables JavaScript debugger
|
||||
* @param[in] serverAddr The address of debugger server.
|
||||
* @param[in] port The port of debugger server will use.
|
||||
* @param[in] isWait Whether wait debugger attach when loading.
|
||||
*/
|
||||
void enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait = false);
|
||||
|
||||
/**
|
||||
* @brief Tests whether JavaScript debugger is enabled
|
||||
* @return true if JavaScript debugger is enabled, otherwise false.
|
||||
*/
|
||||
bool isDebuggerEnabled() const;
|
||||
|
||||
/**
|
||||
* @brief Main loop update trigger, it's need to invoked in main thread every frame.
|
||||
*/
|
||||
void mainLoopUpdate();
|
||||
|
||||
/**
|
||||
* @brief Gets script virtual machine instance ID. Default value is 1, increase by 1 if `init` is invoked.
|
||||
*/
|
||||
uint32_t getVMId() const { return _vmId; }
|
||||
|
||||
// Private API used in wrapper
|
||||
void _clearException(JSValueRef exception);
|
||||
JSContextRef _getContext() const { return _cx; }
|
||||
void _setGarbageCollecting(bool isGarbageCollecting);
|
||||
//
|
||||
private:
|
||||
|
||||
ScriptEngine();
|
||||
~ScriptEngine();
|
||||
|
||||
struct ExceptionInfo
|
||||
{
|
||||
std::string location;
|
||||
std::string message;
|
||||
std::string stack;
|
||||
|
||||
// For compatibility
|
||||
std::string filePath;
|
||||
uint32_t lineno;
|
||||
|
||||
ExceptionInfo()
|
||||
: lineno(0)
|
||||
{}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return !message.empty();
|
||||
}
|
||||
};
|
||||
ExceptionInfo _formatException(JSValueRef exception);
|
||||
|
||||
void callExceptionCallback(const char*, const char*, const char*);
|
||||
|
||||
std::chrono::steady_clock::time_point _startTime;
|
||||
std::vector<RegisterCallback> _registerCallbackArray;
|
||||
std::vector<std::function<void()>> _beforeInitHookArray;
|
||||
std::vector<std::function<void()>> _afterInitHookArray;
|
||||
|
||||
std::vector<std::function<void()>> _beforeCleanupHookArray;
|
||||
std::vector<std::function<void()>> _afterCleanupHookArray;
|
||||
|
||||
JSGlobalContextRef _cx;
|
||||
|
||||
Object* _globalObj;
|
||||
FileOperationDelegate _fileOperationDelegate;
|
||||
ExceptionCallback _nativeExceptionCallback = nullptr;
|
||||
ExceptionCallback _jsExceptionCallback = nullptr;
|
||||
|
||||
uint32_t _vmId;
|
||||
|
||||
std::thread::id _engineThreadId;
|
||||
|
||||
bool _isGarbageCollecting;
|
||||
bool _isValid;
|
||||
bool _isInCleanup;
|
||||
bool _isErrorHandleWorking;
|
||||
bool _isDebuggerEnabled;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
|
||||
@@ -0,0 +1,694 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "../State.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
#include "PlatformUtils.h"
|
||||
|
||||
#import "EJConvertTypedArray.h"
|
||||
|
||||
#if SE_DEBUG > 0
|
||||
extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);
|
||||
#endif
|
||||
|
||||
namespace se {
|
||||
|
||||
AutoHandleScope::AutoHandleScope()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AutoHandleScope::~AutoHandleScope()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Class* __jsb_CCPrivateData_class = nullptr;
|
||||
//
|
||||
namespace {
|
||||
|
||||
ScriptEngine* __instance = nullptr;
|
||||
|
||||
JSValueRef __forceGC(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
|
||||
size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
|
||||
{
|
||||
if (__instance != nullptr)
|
||||
{
|
||||
__instance->garbageCollect();
|
||||
}
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
JSValueRef __log(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
|
||||
size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
|
||||
{
|
||||
if (argumentCount > 0)
|
||||
{
|
||||
std::string ret;
|
||||
internal::forceConvertJsValueToStdString(ctx, arguments[0], &ret);
|
||||
SE_LOGD("JS: %s\n", ret.c_str());
|
||||
}
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
JSObjectRef privateDataContructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void privateDataFinalize(JSObjectRef obj)
|
||||
{
|
||||
internal::PrivateData* p = (internal::PrivateData*)JSObjectGetPrivate(obj);
|
||||
JSObjectSetPrivate(obj, p->data);
|
||||
if (p->finalizeCb != nullptr)
|
||||
p->finalizeCb(obj);
|
||||
free(p);
|
||||
}
|
||||
|
||||
Value __consoleVal;
|
||||
Value __oldConsoleLog;
|
||||
Value __oldConsoleDebug;
|
||||
Value __oldConsoleInfo;
|
||||
Value __oldConsoleWarn;
|
||||
Value __oldConsoleError;
|
||||
Value __oldConsoleAssert;
|
||||
|
||||
bool JSB_console_format_log(State& s, const char* prefix, int msgIndex = 0)
|
||||
{
|
||||
if (msgIndex < 0)
|
||||
return false;
|
||||
|
||||
const auto& args = s.args();
|
||||
int argc = (int)args.size();
|
||||
if ((argc - msgIndex) == 1)
|
||||
{
|
||||
std::string msg = args[msgIndex].toStringForce();
|
||||
SE_LOGD("JS: %s%s\n", prefix, msg.c_str());
|
||||
}
|
||||
else if (argc > 1)
|
||||
{
|
||||
std::string msg = args[msgIndex].toStringForce();
|
||||
size_t pos;
|
||||
for (int i = (msgIndex+1); i < argc; ++i)
|
||||
{
|
||||
pos = msg.find("%");
|
||||
if (pos != std::string::npos && pos != (msg.length()-1) && (msg[pos+1] == 'd' || msg[pos+1] == 's' || msg[pos+1] == 'f'))
|
||||
{
|
||||
msg.replace(pos, 2, args[i].toStringForce());
|
||||
}
|
||||
else
|
||||
{
|
||||
msg += " " + args[i].toStringForce();
|
||||
}
|
||||
}
|
||||
|
||||
SE_LOGD("JS: %s%s\n", prefix, msg.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// exist potential crash in iOS, when invoke log to javascript
|
||||
void JSB_invoke_js_log(Value& v, State& s)
|
||||
{
|
||||
#if SE_LOG_TO_JS_ENV
|
||||
v.toObject()->call(s.args(), __consoleVal.toObject());
|
||||
#endif
|
||||
}
|
||||
|
||||
bool JSB_console_log(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "");
|
||||
JSB_invoke_js_log(__oldConsoleLog, s);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_log)
|
||||
|
||||
bool JSB_console_debug(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[DEBUG]: ");
|
||||
JSB_invoke_js_log(__oldConsoleDebug, s);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_debug)
|
||||
|
||||
bool JSB_console_info(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[INFO]: ");
|
||||
JSB_invoke_js_log(__oldConsoleInfo, s);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_info)
|
||||
|
||||
bool JSB_console_warn(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[WARN]: ");
|
||||
JSB_invoke_js_log(__oldConsoleWarn, s);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_warn)
|
||||
|
||||
bool JSB_console_error(State& s)
|
||||
{
|
||||
JSB_console_format_log(s, "[ERROR]: ");
|
||||
JSB_invoke_js_log(__oldConsoleError, s);
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_error)
|
||||
|
||||
bool JSB_console_assert(State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
if (!args.empty())
|
||||
{
|
||||
if (args[0].isBoolean() && !args[0].toBoolean())
|
||||
{
|
||||
JSB_console_format_log(s, "[ASSERT]: ", 1);
|
||||
JSB_invoke_js_log(__oldConsoleAssert, s);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_console_assert)
|
||||
}
|
||||
|
||||
ScriptEngine *ScriptEngine::getInstance()
|
||||
{
|
||||
if (__instance == nullptr)
|
||||
{
|
||||
__instance = new ScriptEngine();
|
||||
}
|
||||
|
||||
return __instance;
|
||||
}
|
||||
|
||||
void ScriptEngine::destroyInstance()
|
||||
{
|
||||
delete __instance;
|
||||
__instance = nullptr;
|
||||
}
|
||||
|
||||
ScriptEngine::ScriptEngine()
|
||||
: _cx(nullptr)
|
||||
, _globalObj(nullptr)
|
||||
, _vmId(0)
|
||||
, _isGarbageCollecting(false)
|
||||
, _isValid(false)
|
||||
, _isInCleanup(false)
|
||||
, _isErrorHandleWorking(false)
|
||||
, _isDebuggerEnabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool ScriptEngine::init()
|
||||
{
|
||||
cleanup();
|
||||
SE_LOGD("Initializing JavaScriptCore \n");
|
||||
++_vmId;
|
||||
|
||||
_engineThreadId = std::this_thread::get_id();
|
||||
|
||||
for (const auto& hook : _beforeInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeInitHookArray.clear();
|
||||
|
||||
_cx = JSGlobalContextCreate(nullptr);
|
||||
|
||||
if (nullptr == _cx)
|
||||
return false;
|
||||
|
||||
JSStringRef ctxName = JSStringCreateWithUTF8CString("Cocos2d-x JSB");
|
||||
JSGlobalContextSetName(_cx, ctxName);
|
||||
JSStringRelease(ctxName);
|
||||
|
||||
NativePtrToObjectMap::init();
|
||||
NonRefNativePtrCreatedByCtorMap::init();
|
||||
|
||||
internal::setContext(_cx);
|
||||
Class::setContext(_cx);
|
||||
Object::setContext(_cx);
|
||||
|
||||
JSObjectRef globalObj = JSContextGetGlobalObject(_cx);
|
||||
|
||||
if (nullptr == globalObj)
|
||||
return false;
|
||||
|
||||
_globalObj = Object::_createJSObject(nullptr, globalObj);
|
||||
_globalObj->root();
|
||||
_globalObj->setProperty("window", Value(_globalObj));
|
||||
|
||||
if (!isSupportTypedArrayAPI())
|
||||
EJJSContextPrepareTypedArrayAPI(_cx);
|
||||
|
||||
if (_globalObj->getProperty("console", &__consoleVal) && __consoleVal.isObject())
|
||||
{
|
||||
#if SE_LOG_TO_JS_ENV
|
||||
__consoleVal.toObject()->getProperty("log", &__oldConsoleLog);
|
||||
__consoleVal.toObject()->getProperty("debug", &__oldConsoleDebug);
|
||||
__consoleVal.toObject()->getProperty("info", &__oldConsoleInfo);
|
||||
__consoleVal.toObject()->getProperty("warn", &__oldConsoleWarn);
|
||||
__consoleVal.toObject()->getProperty("error", &__oldConsoleError);
|
||||
__consoleVal.toObject()->getProperty("assert", &__oldConsoleAssert);
|
||||
#endif
|
||||
__consoleVal.toObject()->defineFunction("log", _SE(JSB_console_log));
|
||||
__consoleVal.toObject()->defineFunction("debug", _SE(JSB_console_debug));
|
||||
__consoleVal.toObject()->defineFunction("info", _SE(JSB_console_info));
|
||||
__consoleVal.toObject()->defineFunction("warn", _SE(JSB_console_warn));
|
||||
__consoleVal.toObject()->defineFunction("error", _SE(JSB_console_error));
|
||||
__consoleVal.toObject()->defineFunction("assert", _SE(JSB_console_assert));
|
||||
}
|
||||
|
||||
_globalObj->setProperty("scriptEngineType", Value("JavaScriptCore"));
|
||||
|
||||
JSStringRef propertyName = JSStringCreateWithUTF8CString("log");
|
||||
JSObjectSetProperty(_cx, globalObj, propertyName, JSObjectMakeFunctionWithCallback(_cx, propertyName, __log), kJSPropertyAttributeReadOnly, nullptr);
|
||||
JSStringRelease(propertyName);
|
||||
|
||||
propertyName = JSStringCreateWithUTF8CString("forceGC");
|
||||
JSObjectSetProperty(_cx, globalObj, propertyName, JSObjectMakeFunctionWithCallback(_cx, propertyName, __forceGC), kJSPropertyAttributeReadOnly, nullptr);
|
||||
JSStringRelease(propertyName);
|
||||
|
||||
__jsb_CCPrivateData_class = Class::create("__PrivateData", _globalObj, nullptr, privateDataContructor);
|
||||
__jsb_CCPrivateData_class->defineFinalizeFunction(privateDataFinalize);
|
||||
__jsb_CCPrivateData_class->install();
|
||||
|
||||
_isValid = true;
|
||||
|
||||
for (const auto& hook : _afterInitHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterInitHookArray.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ScriptEngine::~ScriptEngine()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void ScriptEngine::cleanup()
|
||||
{
|
||||
if (!_isValid)
|
||||
return;
|
||||
|
||||
SE_LOGD("ScriptEngine::cleanup begin ...\n");
|
||||
_isInCleanup = true;
|
||||
for (const auto& hook : _beforeCleanupHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_beforeCleanupHookArray.clear();
|
||||
|
||||
SAFE_DEC_REF(_globalObj);
|
||||
Object::cleanup();
|
||||
garbageCollect();
|
||||
|
||||
__consoleVal.setUndefined();
|
||||
__oldConsoleLog.setUndefined();
|
||||
__oldConsoleDebug.setUndefined();
|
||||
__oldConsoleInfo.setUndefined();
|
||||
__oldConsoleWarn.setUndefined();
|
||||
__oldConsoleError.setUndefined();
|
||||
__oldConsoleAssert.setUndefined();
|
||||
|
||||
JSGlobalContextRelease(_cx);
|
||||
|
||||
Class::cleanup();
|
||||
|
||||
_cx = nullptr;
|
||||
_globalObj = nullptr;
|
||||
_isValid = false;
|
||||
|
||||
_registerCallbackArray.clear();
|
||||
|
||||
for (const auto& hook : _afterCleanupHookArray)
|
||||
{
|
||||
hook();
|
||||
}
|
||||
_afterCleanupHookArray.clear();
|
||||
_isInCleanup = false;
|
||||
|
||||
NativePtrToObjectMap::destroy();
|
||||
NonRefNativePtrCreatedByCtorMap::destroy();
|
||||
SE_LOGD("ScriptEngine::cleanup end ...\n");
|
||||
}
|
||||
|
||||
ScriptEngine::ExceptionInfo ScriptEngine::_formatException(JSValueRef exception)
|
||||
{
|
||||
ExceptionInfo ret;
|
||||
|
||||
// Ignore Exception in forceConvertJsValueToStdString invocation to avoid infinite loop.
|
||||
internal::forceConvertJsValueToStdString(_cx, exception, &ret.message, true);
|
||||
|
||||
JSType type = JSValueGetType(_cx, exception);
|
||||
|
||||
if (type == kJSTypeObject)
|
||||
{
|
||||
JSObjectRef obj = JSValueToObject(_cx, exception, nullptr);
|
||||
JSStringRef stackKey = JSStringCreateWithUTF8CString("stack");
|
||||
JSValueRef stackVal = JSObjectGetProperty(_cx, obj, stackKey, nullptr);
|
||||
if (stackKey != nullptr)
|
||||
{
|
||||
type = JSValueGetType(_cx, stackVal);
|
||||
if (type == kJSTypeString)
|
||||
{
|
||||
JSStringRef stackStr = JSValueToStringCopy(_cx, stackVal, nullptr);
|
||||
internal::jsStringToStdString(_cx, stackStr, &ret.stack);
|
||||
JSStringRelease(stackStr);
|
||||
}
|
||||
JSStringRelease(stackKey);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::string column;
|
||||
std::string filePath;
|
||||
JSPropertyNameArrayRef nameArr = JSObjectCopyPropertyNames(_cx, obj);
|
||||
size_t count =JSPropertyNameArrayGetCount(nameArr);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
JSStringRef jsName = JSPropertyNameArrayGetNameAtIndex(nameArr, i);
|
||||
JSValueRef jsValue = JSObjectGetProperty(_cx, obj, jsName, nullptr);
|
||||
|
||||
std::string name;
|
||||
internal::jsStringToStdString(_cx, jsName, &name);
|
||||
std::string value;
|
||||
|
||||
JSStringRef jsstr = JSValueToStringCopy(_cx, jsValue, nullptr);
|
||||
internal::jsStringToStdString(_cx, jsstr, &value);
|
||||
JSStringRelease(jsstr);
|
||||
|
||||
if (name == "line")
|
||||
{
|
||||
line = value;
|
||||
ret.lineno = (uint32_t)JSValueToNumber(_cx, jsValue, nullptr);
|
||||
}
|
||||
else if (name == "column")
|
||||
{
|
||||
column = value;
|
||||
}
|
||||
else if (name == "sourceURL")
|
||||
{
|
||||
filePath = value;
|
||||
ret.filePath = value;
|
||||
}
|
||||
}
|
||||
|
||||
ret.location = filePath + ":" + line + ":" + column;
|
||||
JSPropertyNameArrayRelease(nameArr);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScriptEngine::_clearException(JSValueRef exception)
|
||||
{
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ExceptionInfo exceptionInfo = _formatException(exception);
|
||||
if (exceptionInfo.isValid())
|
||||
{
|
||||
std::string exceptionStr = exceptionInfo.message;
|
||||
exceptionStr += ", location: " + exceptionInfo.location;
|
||||
if (!exceptionInfo.stack.empty())
|
||||
{
|
||||
exceptionStr += "\nSTACK:\n" + exceptionInfo.stack;
|
||||
}
|
||||
SE_LOGE("ERROR: %s\n", exceptionStr.c_str());
|
||||
|
||||
callExceptionCallback(exceptionInfo.location.c_str(), exceptionInfo.message.c_str(), exceptionInfo.stack.c_str());
|
||||
|
||||
if (!_isErrorHandleWorking)
|
||||
{
|
||||
_isErrorHandleWorking = true;
|
||||
|
||||
Value errorHandler;
|
||||
if (_globalObj->getProperty("__errorHandler", &errorHandler) && errorHandler.isObject() && errorHandler.toObject()->isFunction())
|
||||
{
|
||||
ValueArray args;
|
||||
args.push_back(Value(exceptionInfo.filePath));
|
||||
args.push_back(Value(exceptionInfo.lineno));
|
||||
args.push_back(Value(exceptionInfo.message));
|
||||
args.push_back(Value(exceptionInfo.stack));
|
||||
errorHandler.toObject()->call(args, _globalObj);
|
||||
}
|
||||
|
||||
_isErrorHandleWorking = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
SE_LOGE("ERROR: __errorHandler has exception\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::callExceptionCallback(const char * location, const char * message, const char * stack)
|
||||
{
|
||||
if(_nativeExceptionCallback) {
|
||||
_nativeExceptionCallback(location, message, stack);
|
||||
}
|
||||
if(_jsExceptionCallback) {
|
||||
_jsExceptionCallback(location, message, stack);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::setExceptionCallback(const ExceptionCallback& cb)
|
||||
{
|
||||
_nativeExceptionCallback = cb;
|
||||
}
|
||||
|
||||
void ScriptEngine::setJSExceptionCallback(const ExceptionCallback& cb)
|
||||
{
|
||||
_jsExceptionCallback = cb;
|
||||
}
|
||||
|
||||
bool ScriptEngine::isGarbageCollecting()
|
||||
{
|
||||
return _isGarbageCollecting;
|
||||
}
|
||||
|
||||
void ScriptEngine::_setGarbageCollecting(bool isGarbageCollecting)
|
||||
{
|
||||
_isGarbageCollecting = isGarbageCollecting;
|
||||
}
|
||||
|
||||
Object* ScriptEngine::getGlobalObject()
|
||||
{
|
||||
return _globalObj;
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterInitHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterInitHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addBeforeCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_beforeCleanupHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addAfterCleanupHook(const std::function<void()>& hook)
|
||||
{
|
||||
_afterCleanupHookArray.push_back(hook);
|
||||
}
|
||||
|
||||
void ScriptEngine::addRegisterCallback(RegisterCallback cb)
|
||||
{
|
||||
assert(std::find(_registerCallbackArray.begin(), _registerCallbackArray.end(), cb) == _registerCallbackArray.end());
|
||||
_registerCallbackArray.push_back(cb);
|
||||
}
|
||||
|
||||
bool ScriptEngine::start()
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
_startTime = std::chrono::steady_clock::now();
|
||||
|
||||
for (auto cb : _registerCallbackArray)
|
||||
{
|
||||
ok = cb(_globalObj);
|
||||
assert(ok);
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
|
||||
// After ScriptEngine is started, _registerCallbackArray isn't needed. Therefore, clear it here.
|
||||
_registerCallbackArray.clear();
|
||||
return ok;
|
||||
}
|
||||
|
||||
void ScriptEngine::garbageCollect()
|
||||
{
|
||||
// JSSynchronousGarbageCollectForDebugging is private API in JavaScriptCore framework.
|
||||
// AppStore will reject the apps reference non-public symbols.
|
||||
// Therefore, we use JSSynchronousGarbageCollectForDebugging for easily debugging memory
|
||||
// problems in debug mode, and use public API JSGarbageCollect in release mode to pass
|
||||
// the AppStore's verify check.
|
||||
#if SE_DEBUG > 0
|
||||
SE_LOGD("GC begin ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
JSSynchronousGarbageCollectForDebugging(_cx);
|
||||
SE_LOGD("GC end ..., (Native -> JS map) count: %d\n", (int)NativePtrToObjectMap::size());
|
||||
#else
|
||||
JSGarbageCollect(_cx);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ScriptEngine::evalString(const char* script, ssize_t length/* = -1 */, Value* ret/* = nullptr */, const char* fileName/* = nullptr */)
|
||||
{
|
||||
if(_engineThreadId != std::this_thread::get_id())
|
||||
{
|
||||
// `evalString` should run in main thread
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(script != nullptr);
|
||||
if (length < 0)
|
||||
length = strlen(script);
|
||||
|
||||
if (fileName == nullptr)
|
||||
fileName = "(no filename)";
|
||||
|
||||
// Fix the source url is too long displayed in Safari debugger.
|
||||
std::string sourceUrl = fileName;
|
||||
static const std::string prefixKey = "/temp/quick-scripts/";
|
||||
size_t prefixPos = sourceUrl.find(prefixKey);
|
||||
if (prefixPos != std::string::npos)
|
||||
{
|
||||
sourceUrl = sourceUrl.substr(prefixPos + prefixKey.length());
|
||||
}
|
||||
|
||||
std::string exceptionStr;
|
||||
std::string scriptStr(script, length);
|
||||
|
||||
JSValueRef exception = nullptr;
|
||||
JSStringRef jsSourceUrl = JSStringCreateWithUTF8CString(sourceUrl.c_str());
|
||||
JSStringRef jsScript = JSStringCreateWithUTF8CString(scriptStr.c_str());
|
||||
JSValueRef result = nullptr;
|
||||
|
||||
bool ok = JSCheckScriptSyntax(_cx, jsScript, jsSourceUrl, 1, &exception);;
|
||||
if (ok)
|
||||
{
|
||||
result = JSEvaluateScript(_cx, jsScript, nullptr, jsSourceUrl, 1, &exception);
|
||||
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (exception == nullptr)
|
||||
{
|
||||
SE_LOGD("Unknown syntax error parsing file %s\n", fileName);
|
||||
}
|
||||
}
|
||||
|
||||
JSStringRelease(jsScript);
|
||||
JSStringRelease(jsSourceUrl);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
if (ret != nullptr)
|
||||
internal::jsToSeValue(_cx, result, ret);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
SE_LOGE("ScriptEngine::evalString script %s, failed!\n", fileName);
|
||||
}
|
||||
|
||||
_clearException(exception);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void ScriptEngine::setFileOperationDelegate(const FileOperationDelegate& delegate)
|
||||
{
|
||||
_fileOperationDelegate = delegate;
|
||||
}
|
||||
|
||||
const ScriptEngine::FileOperationDelegate& ScriptEngine::getFileOperationDelegate() const
|
||||
{
|
||||
return _fileOperationDelegate;
|
||||
}
|
||||
|
||||
bool ScriptEngine::runScript(const std::string& path, Value* ret/* = nullptr */)
|
||||
{
|
||||
assert(!path.empty());
|
||||
assert(_fileOperationDelegate.isValid());
|
||||
|
||||
std::string scriptBuffer = _fileOperationDelegate.onGetStringFromFile(path);
|
||||
|
||||
if (!scriptBuffer.empty())
|
||||
{
|
||||
return evalString(scriptBuffer.c_str(), scriptBuffer.length(), ret, path.c_str());
|
||||
}
|
||||
|
||||
SE_LOGE("ScriptEngine::runScript script %s, buffer is empty!\n", path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptEngine::clearException()
|
||||
{
|
||||
//IDEA:
|
||||
}
|
||||
|
||||
void ScriptEngine::enableDebugger(const std::string& serverAddr, uint32_t port, bool isWait)
|
||||
{
|
||||
// empty implementation
|
||||
_isDebuggerEnabled = true;
|
||||
}
|
||||
|
||||
bool ScriptEngine::isDebuggerEnabled() const
|
||||
{
|
||||
return _isDebuggerEnabled;
|
||||
}
|
||||
|
||||
void ScriptEngine::mainLoopUpdate()
|
||||
{
|
||||
// empty implementation
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "Object.hpp"
|
||||
#include "../Value.hpp"
|
||||
#include "../State.hpp"
|
||||
#include "HelperMacros.h"
|
||||
#include "Utils.hpp"
|
||||
@@ -0,0 +1,378 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Utils.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Object.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../HandleObject.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
namespace internal {
|
||||
|
||||
namespace {
|
||||
JSContextRef __cx = nullptr;
|
||||
}
|
||||
|
||||
void setContext(JSContextRef cx)
|
||||
{
|
||||
__cx = cx;
|
||||
}
|
||||
|
||||
bool defineProperty(Object* obj, const char* name, JSObjectCallAsFunctionCallback jsGetter, JSObjectCallAsFunctionCallback jsSetter)
|
||||
{
|
||||
bool ok = true;
|
||||
Object* globalObject = ScriptEngine::getInstance()->getGlobalObject();
|
||||
Value v;
|
||||
ok = globalObject->getProperty("Object", &v);
|
||||
if (!ok || !v.isObject())
|
||||
{
|
||||
SE_LOGD("ERROR: couldn't find Object\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
Value definePropertyFunc;
|
||||
ok = v.toObject()->getProperty("defineProperty", &definePropertyFunc);
|
||||
if (!ok || !v.isObject())
|
||||
{
|
||||
SE_LOGD("ERROR: couldn't find Object.defineProperty\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
ValueArray args;
|
||||
args.reserve(3);
|
||||
args.push_back(Value(obj));
|
||||
args.push_back(Value(name));
|
||||
|
||||
HandleObject desc(Object::createPlainObject());
|
||||
|
||||
JSObjectRef getter = nullptr;
|
||||
if (jsGetter != nullptr)
|
||||
{
|
||||
getter = JSObjectMakeFunctionWithCallback(__cx, nullptr, jsGetter);
|
||||
}
|
||||
JSObjectRef setter = nullptr;
|
||||
|
||||
if (jsSetter != nullptr)
|
||||
{
|
||||
setter = JSObjectMakeFunctionWithCallback(__cx, nullptr, jsSetter);
|
||||
}
|
||||
|
||||
assert(getter != nullptr || setter != nullptr);
|
||||
|
||||
if (getter != nullptr)
|
||||
{
|
||||
HandleObject getterObj(Object::_createJSObject(nullptr, getter));
|
||||
desc->setProperty("get", Value(getterObj));
|
||||
}
|
||||
|
||||
if (setter != nullptr)
|
||||
{
|
||||
HandleObject setterObj(Object::_createJSObject(nullptr, setter));
|
||||
desc->setProperty("set", Value(setterObj));
|
||||
}
|
||||
|
||||
args.push_back(Value(desc));
|
||||
definePropertyFunc.toObject()->call(args, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void jsToSeArgs(JSContextRef cx, unsigned short argc, const JSValueRef* argv, ValueArray* outArr)
|
||||
{
|
||||
outArr->reserve(argc);
|
||||
for (unsigned short i = 0; i < argc; ++i)
|
||||
{
|
||||
Value v;
|
||||
jsToSeValue(cx, argv[i], &v);
|
||||
outArr->push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
void seToJsArgs(JSContextRef cx, const ValueArray& args, JSValueRef* outArr)
|
||||
{
|
||||
for (size_t i = 0, len = args.size(); i < len; ++i)
|
||||
{
|
||||
seToJsValue(cx, args[i], &outArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void jsToSeValue(JSContextRef cx, JSValueRef jsValue, Value* data)
|
||||
{
|
||||
if (JSValueIsNull(cx, jsValue))
|
||||
{
|
||||
data->setNull();
|
||||
}
|
||||
else if (JSValueIsUndefined(cx, jsValue))
|
||||
{
|
||||
data->setUndefined();
|
||||
}
|
||||
else if (JSValueIsNumber(cx, jsValue))
|
||||
{
|
||||
JSValueRef exception = nullptr;
|
||||
double number = JSValueToNumber(cx, jsValue, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
data->setNumber(number);
|
||||
}
|
||||
}
|
||||
else if (JSValueIsBoolean(cx, jsValue))
|
||||
{
|
||||
data->setBoolean(JSValueToBoolean(cx, jsValue));
|
||||
}
|
||||
else if (JSValueIsString(cx, jsValue))
|
||||
{
|
||||
std::string str;
|
||||
forceConvertJsValueToStdString(cx, jsValue, &str);
|
||||
data->setString(str);
|
||||
}
|
||||
else if (JSValueIsObject(cx, jsValue))
|
||||
{
|
||||
JSValueRef exception = nullptr;
|
||||
JSObjectRef jsobj = JSValueToObject(cx, jsValue, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
void* nativePtr = internal::getPrivate(jsobj);
|
||||
Object* obj = nullptr;
|
||||
if (nativePtr != nullptr)
|
||||
{
|
||||
obj = Object::getObjectWithPtr(nativePtr);
|
||||
}
|
||||
|
||||
if (obj == nullptr)
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, jsobj);
|
||||
}
|
||||
data->setObject(obj, true);
|
||||
obj->decRef();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void seToJsValue(JSContextRef cx, const Value& v, JSValueRef* jsval)
|
||||
{
|
||||
switch (v.getType()) {
|
||||
case Value::Type::Null:
|
||||
*jsval = JSValueMakeNull(cx);
|
||||
break;
|
||||
|
||||
case Value::Type::Number:
|
||||
*jsval = JSValueMakeNumber(cx, v.toNumber());
|
||||
break;
|
||||
|
||||
case Value::Type::String:
|
||||
{
|
||||
JSStringRef str = JSStringCreateWithUTF8CString(v.toString().c_str());
|
||||
*jsval = JSValueMakeString(cx, str);
|
||||
JSStringRelease(str);
|
||||
}
|
||||
break;
|
||||
|
||||
case Value::Type::Boolean:
|
||||
*jsval = JSValueMakeBoolean(cx, v.toBoolean());
|
||||
break;
|
||||
|
||||
case Value::Type::Object:
|
||||
*jsval = v.toObject()->_getJSObject();
|
||||
break;
|
||||
|
||||
default: // Undefined
|
||||
*jsval = JSValueMakeUndefined(cx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void forceConvertJsValueToStdString(JSContextRef cx, JSValueRef jsval, std::string* ret, bool ignoreException/* = false */)
|
||||
{
|
||||
JSValueRef exception = nullptr;
|
||||
JSStringRef jsstr = JSValueToStringCopy(cx, jsval, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
// NOTE: ignoreException is true in ScriptEngine::_formatException because it's already in the _clearException process.
|
||||
// Adds this flag to avoid infinite loop of _clearException -> _formatException -> forceConvertJsValueToStdString -> _clearException -> ...
|
||||
if (!ignoreException)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
ret->clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
jsStringToStdString(cx, jsstr, ret);
|
||||
}
|
||||
|
||||
if (jsstr != nullptr)
|
||||
JSStringRelease(jsstr);
|
||||
}
|
||||
|
||||
void jsStringToStdString(JSContextRef cx, JSStringRef jsStr, std::string* ret)
|
||||
{
|
||||
size_t len = JSStringGetLength(jsStr);
|
||||
const size_t BUF_SIZE = len * 4 + 1;
|
||||
char* buf = (char*)malloc(BUF_SIZE);
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
JSStringGetUTF8CString(jsStr, buf, BUF_SIZE);
|
||||
*ret = buf;
|
||||
free(buf);
|
||||
}
|
||||
|
||||
const char* KEY_PRIVATE_DATA = "__cc_private_data";
|
||||
|
||||
bool hasPrivate(JSObjectRef obj)
|
||||
{
|
||||
void* data = JSObjectGetPrivate(obj);
|
||||
if (data != nullptr)
|
||||
return true;
|
||||
|
||||
JSStringRef key = JSStringCreateWithUTF8CString(KEY_PRIVATE_DATA);
|
||||
bool found = JSObjectHasProperty(__cx, obj, key);
|
||||
JSStringRelease(key);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
void setPrivate(JSObjectRef obj, void* data, JSObjectFinalizeCallback finalizeCb)
|
||||
{
|
||||
bool ok = JSObjectSetPrivate(obj, data);
|
||||
if (ok)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(finalizeCb);
|
||||
Object* privateObj = Object::createObjectWithClass(__jsb_CCPrivateData_class);
|
||||
privateObj->root();
|
||||
|
||||
internal::PrivateData* privateData = (internal::PrivateData*)malloc(sizeof(internal::PrivateData));
|
||||
privateData->data = data;
|
||||
privateData->finalizeCb = finalizeCb;
|
||||
ok = JSObjectSetPrivate(privateObj->_getJSObject(), privateData);
|
||||
assert(ok);
|
||||
|
||||
JSStringRef key = JSStringCreateWithUTF8CString(KEY_PRIVATE_DATA);
|
||||
JSValueRef exception = nullptr;
|
||||
JSObjectSetProperty(__cx, obj, key, privateObj->_getJSObject(), kJSPropertyAttributeDontEnum, &exception);
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
JSStringRelease(key);
|
||||
|
||||
privateObj->unroot();
|
||||
privateObj->decRef();
|
||||
}
|
||||
|
||||
void* getPrivate(JSObjectRef obj)
|
||||
{
|
||||
void* data = JSObjectGetPrivate(obj);
|
||||
if (data != nullptr)
|
||||
return data;
|
||||
|
||||
JSStringRef key = JSStringCreateWithUTF8CString(KEY_PRIVATE_DATA);
|
||||
bool found = JSObjectHasProperty(__cx, obj, key);
|
||||
if (found)
|
||||
{
|
||||
JSValueRef exception = nullptr;
|
||||
JSValueRef privateDataVal = JSObjectGetProperty(__cx, obj, key, &exception);
|
||||
do
|
||||
{
|
||||
if (exception != nullptr)
|
||||
break;
|
||||
|
||||
JSObjectRef jsobj = JSValueToObject(__cx, privateDataVal, &exception);
|
||||
if (exception != nullptr)
|
||||
break;
|
||||
|
||||
internal::PrivateData* privateData = (internal::PrivateData*)JSObjectGetPrivate(jsobj);
|
||||
assert(privateData != nullptr);
|
||||
data = privateData->data;
|
||||
} while(false);
|
||||
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
}
|
||||
JSStringRelease(key);
|
||||
return data;
|
||||
}
|
||||
|
||||
void clearPrivate(JSObjectRef obj)
|
||||
{
|
||||
void* data = JSObjectGetPrivate(obj);
|
||||
if (data != nullptr)
|
||||
{
|
||||
JSObjectSetPrivate(obj, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
JSStringRef key = JSStringCreateWithUTF8CString(KEY_PRIVATE_DATA); //IDEA: cache the key string
|
||||
if (JSObjectHasProperty(__cx, obj, key))
|
||||
{
|
||||
JSValueRef exception = nullptr;
|
||||
do
|
||||
{
|
||||
JSValueRef value = JSObjectGetProperty(__cx, obj, key, &exception);
|
||||
if (exception != nullptr)
|
||||
break;
|
||||
|
||||
JSObjectRef propertyObj = JSValueToObject(__cx, value, &exception);
|
||||
if (exception != nullptr)
|
||||
break;
|
||||
|
||||
internal::PrivateData* privateData = (internal::PrivateData*)JSObjectGetPrivate(propertyObj);
|
||||
free(privateData);
|
||||
JSObjectSetPrivate(propertyObj, nullptr);
|
||||
bool ok = JSObjectDeleteProperty(__cx, obj, key, nullptr);
|
||||
assert(ok);
|
||||
} while (false);
|
||||
|
||||
if (exception != nullptr)
|
||||
{
|
||||
ScriptEngine::getInstance()->_clearException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JSStringRelease(key);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace se { namespace internal {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
#include "../Value.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct PrivateData
|
||||
{
|
||||
void* data;
|
||||
JSObjectFinalizeCallback finalizeCb;
|
||||
};
|
||||
|
||||
void setContext(JSContextRef cx);
|
||||
|
||||
bool defineProperty(Object* obj, const char* name, JSObjectCallAsFunctionCallback jsGetter, JSObjectCallAsFunctionCallback jsSetter);
|
||||
|
||||
void jsToSeArgs(JSContextRef cx, unsigned short argc, const JSValueRef* argv, ValueArray* outArr);
|
||||
void seToJsArgs(JSContextRef cx, const ValueArray& args, JSValueRef* outArr);
|
||||
void jsToSeValue(JSContextRef cx, JSValueRef jsval, Value* v);
|
||||
void seToJsValue(JSContextRef cx, const Value& v, JSValueRef* jsval);
|
||||
|
||||
void forceConvertJsValueToStdString(JSContextRef cx, JSValueRef jsval, std::string* ret, bool ignoreException = false);
|
||||
void jsStringToStdString(JSContextRef cx, JSStringRef jsStr, std::string* ret);
|
||||
|
||||
bool hasPrivate(JSObjectRef obj);
|
||||
void setPrivate(JSObjectRef obj, void* data, JSObjectFinalizeCallback finalizeCb);
|
||||
void* getPrivate(JSObjectRef obj);
|
||||
void clearPrivate(JSObjectRef obj);
|
||||
|
||||
} // namespace internal {
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSC
|
||||
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#ifndef UINT64_C
|
||||
#define UINT64_C(value) __CONCAT(value, ULL)
|
||||
#endif
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "js/Initialization.h"
|
||||
#include "js/Conversions.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <assert.h>
|
||||
|
||||
#include "HelperMacros.h"
|
||||
@@ -0,0 +1,237 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Class.hpp"
|
||||
#include "Object.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
|
||||
namespace se {
|
||||
|
||||
// --- Global Lookup for Constructor Functions
|
||||
|
||||
namespace {
|
||||
// std::unordered_map<std::string, Class *> __clsMap;
|
||||
JSContext* __cx = nullptr;
|
||||
|
||||
bool empty_constructor(JSContext* cx, uint32_t argc, JS::Value* vp)
|
||||
{
|
||||
assert(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Class*> __allClasses;
|
||||
}
|
||||
|
||||
Class::Class()
|
||||
: _parent(nullptr)
|
||||
, _proto(nullptr)
|
||||
, _parentProto(nullptr)
|
||||
, _ctor(nullptr)
|
||||
, _finalizeOp(nullptr)
|
||||
{
|
||||
memset(&_jsCls, 0, sizeof(_jsCls));
|
||||
memset(&_classOps, 0, sizeof(_classOps));
|
||||
|
||||
__allClasses.push_back(this);
|
||||
}
|
||||
|
||||
Class::~Class()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Class* Class::create(const char* className, Object* obj, Object* parentProto, JSNative ctor)
|
||||
{
|
||||
Class* cls = new Class();
|
||||
if (cls != nullptr && !cls->init(className, obj, parentProto, ctor))
|
||||
{
|
||||
delete cls;
|
||||
cls = nullptr;
|
||||
}
|
||||
return cls;
|
||||
}
|
||||
|
||||
bool Class::init(const char* clsName, Object* parent, Object *parentProto, JSNative ctor)
|
||||
{
|
||||
_name = clsName;
|
||||
|
||||
_parent = parent;
|
||||
if (_parent != nullptr)
|
||||
_parent->incRef();
|
||||
|
||||
_parentProto = parentProto;
|
||||
if (_parentProto != nullptr)
|
||||
_parentProto->incRef();
|
||||
|
||||
_ctor = ctor;
|
||||
if (_ctor == nullptr)
|
||||
{
|
||||
_ctor = empty_constructor;
|
||||
}
|
||||
|
||||
// SE_LOGD("Class init ( %s ) ...\n", clsName);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Class::destroy()
|
||||
{
|
||||
SAFE_DEC_REF(_parent);
|
||||
SAFE_DEC_REF(_proto);
|
||||
SAFE_DEC_REF(_parentProto);
|
||||
}
|
||||
|
||||
bool Class::install()
|
||||
{
|
||||
// assert(__clsMap.find(_name) == __clsMap.end());
|
||||
//
|
||||
// __clsMap.emplace(_name, this);
|
||||
|
||||
_jsCls.name = _name;
|
||||
if (_finalizeOp != nullptr)
|
||||
{
|
||||
_jsCls.flags = JSCLASS_HAS_PRIVATE | JSCLASS_FOREGROUND_FINALIZE; //IDEA: Use JSCLASS_BACKGROUND_FINALIZE to improve GC performance
|
||||
_classOps.finalize = _finalizeOp;
|
||||
}
|
||||
else
|
||||
{
|
||||
_jsCls.flags = JSCLASS_HAS_PRIVATE;
|
||||
}
|
||||
|
||||
_jsCls.cOps = &_classOps;
|
||||
|
||||
JSObject* parentObj = _parentProto != nullptr ? _parentProto->_getJSObject() : nullptr;
|
||||
JS::RootedObject parent(__cx, _parent->_getJSObject());
|
||||
JS::RootedObject parentProto(__cx, parentObj);
|
||||
|
||||
_funcs.push_back(JS_FS_END);
|
||||
_properties.push_back(JS_PS_END);
|
||||
_staticFuncs.push_back(JS_FS_END);
|
||||
_staticProperties.push_back(JS_PS_END);
|
||||
|
||||
JSObject* jsobj = JS_InitClass(__cx, parent, parentProto, &_jsCls, _ctor, 0, _properties.data(), _funcs.data(), _staticProperties.data(), _staticFuncs.data());
|
||||
if (jsobj != nullptr)
|
||||
{
|
||||
_proto = Object::_createJSObject(nullptr, jsobj);
|
||||
// SE_LOGD("_proto: %p, name: %s\n", _proto, _name);
|
||||
_proto->root();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Class::defineFunction(const char *name, JSNative func)
|
||||
{
|
||||
JSFunctionSpec cb = JS_FN(name, func, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE);
|
||||
_funcs.push_back(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineProperty(const char *name, JSNative getter, JSNative setter)
|
||||
{
|
||||
JSPropertySpec property = JS_PSGS(name, getter, setter, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
_properties.push_back(property);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineStaticFunction(const char *name, JSNative func)
|
||||
{
|
||||
JSFunctionSpec cb = JS_FN(name, func, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE);
|
||||
_staticFuncs.push_back(cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineStaticProperty(const char *name, JSNative getter, JSNative setter)
|
||||
{
|
||||
JSPropertySpec property = JS_PSGS(name, getter, setter, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
_staticProperties.push_back(property);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Class::defineFinalizeFunction(JSFinalizeOp func)
|
||||
{
|
||||
_finalizeOp = func;
|
||||
return true;
|
||||
}
|
||||
|
||||
// JSObject* Class::_createJSObject(const std::string &clsName, Class** outCls)
|
||||
// {
|
||||
// auto iter = __clsMap.find(clsName);
|
||||
// if (iter == __clsMap.end())
|
||||
// {
|
||||
// *outCls = nullptr;
|
||||
// return nullptr;
|
||||
// }
|
||||
//
|
||||
// Class* thiz = iter->second;
|
||||
// JS::RootedObject obj(__cx, _createJSObjectWithClass(thiz));
|
||||
// *outCls = thiz;
|
||||
// return obj;
|
||||
// }
|
||||
|
||||
JSObject* Class::_createJSObjectWithClass(Class* cls)
|
||||
{
|
||||
JSObject* proto = cls->_proto != nullptr ? cls->_proto->_getJSObject() : nullptr;
|
||||
JS::RootedObject jsProto(__cx, proto);
|
||||
JS::RootedObject obj(__cx, JS_NewObjectWithGivenProto(__cx, &cls->_jsCls, jsProto));
|
||||
return obj;
|
||||
}
|
||||
|
||||
void Class::setContext(JSContext* cx)
|
||||
{
|
||||
__cx = cx;
|
||||
}
|
||||
|
||||
Object *Class::getProto()
|
||||
{
|
||||
return _proto;
|
||||
}
|
||||
|
||||
JSFinalizeOp Class::_getFinalizeCb() const
|
||||
{
|
||||
return _finalizeOp;
|
||||
}
|
||||
|
||||
void Class::cleanup()
|
||||
{
|
||||
for (auto cls : __allClasses)
|
||||
{
|
||||
cls->destroy();
|
||||
}
|
||||
|
||||
se::ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
for (auto cls : __allClasses)
|
||||
{
|
||||
delete cls;
|
||||
}
|
||||
__allClasses.clear();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
@@ -0,0 +1,154 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class Object;
|
||||
|
||||
/**
|
||||
* se::Class represents a definition of how to create a native binding object.
|
||||
*/
|
||||
class Class final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a class used for creating relevant native binding objects.
|
||||
* @param[in] className A null-terminated UTF8 string containing the class's name.
|
||||
* @param[in] obj The object that current class proto object attaches to. Should not be nullptr.
|
||||
* @param[in] parentProto The parent proto object that current class inherits from. Passing nullptr means a new class has no parent.
|
||||
* @param[in] ctor A callback to invoke when your constructor is used in a 'new' expression. Pass nullptr to use the default object constructor.
|
||||
* @return A class instance used for creating relevant native binding objects.
|
||||
* @note Don't need to delete the pointer return by this method, it's managed internally.
|
||||
*/
|
||||
static Class* create(const char* className, Object* obj, Object* parentProto, JSNative ctor);
|
||||
|
||||
/**
|
||||
* @brief Defines a member function with a callback. Each objects created by class will have this function property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the function name.
|
||||
* @param[in] func A callback to invoke when the property is called as a function.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFunction(const char *name, JSNative func);
|
||||
|
||||
/**
|
||||
* @brief Defines a property with accessor callbacks. Each objects created by class will have this property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the property name.
|
||||
* @param[in] getter A callback to invoke when the property is read.
|
||||
* @param[in] setter A callback to invoke when the property is set.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineProperty(const char *name, JSNative getter, JSNative setter);
|
||||
|
||||
/**
|
||||
* @brief Defines a static function with a callback. Only JavaScript constructor object will have this function.
|
||||
* @param[in] name A null-terminated UTF8 string containing the function name.
|
||||
* @param[in] func A callback to invoke when the constructor's property is called as a function.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineStaticFunction(const char *name, JSNative func);
|
||||
|
||||
/**
|
||||
* @brief Defines a static property with accessor callbacks. Only JavaScript constructor object will have this property.
|
||||
* @param[in] name A null-terminated UTF8 string containing the property name.
|
||||
* @param[in] getter A callback to invoke when the constructor's property is read.
|
||||
* @param[in] setter A callback to invoke when the constructor's property is set.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineStaticProperty(const char *name, JSNative getter, JSNative setter);
|
||||
|
||||
/**
|
||||
* @brief Defines the finalize function with a callback.
|
||||
* @param[in] func The callback to invoke when a JavaScript object is garbage collected.
|
||||
* @return true if succeed, otherwise false.
|
||||
*/
|
||||
bool defineFinalizeFunction(JSFinalizeOp func);
|
||||
|
||||
/**
|
||||
* @brief Installs class to JavaScript VM.
|
||||
* @return true if succeed, otherwise false.
|
||||
* @note After this method, an object could be created by `var foo = new Foo();`.
|
||||
*/
|
||||
bool install();
|
||||
|
||||
/**
|
||||
* @brief Gets the proto object of this class.
|
||||
* @return The proto object of this class.
|
||||
* @note Don't need to be released in user code.
|
||||
*/
|
||||
Object* getProto();
|
||||
|
||||
/**
|
||||
* @brief Gets the class name.
|
||||
* @return The class name.
|
||||
*/
|
||||
const char* getName() const { return _name; }
|
||||
|
||||
// Private API used in wrapper
|
||||
JSFinalizeOp _getFinalizeCb() const;
|
||||
//
|
||||
private:
|
||||
Class();
|
||||
~Class();
|
||||
|
||||
bool init(const char* clsName, Object* obj, Object* parentProto, JSNative ctor);
|
||||
void destroy();
|
||||
|
||||
// static JSObject* _createJSObject(const std::string &clsName, Class** outCls);
|
||||
static JSObject* _createJSObjectWithClass(Class* cls);
|
||||
|
||||
static void setContext(JSContext* cx);
|
||||
static void cleanup();
|
||||
|
||||
const char* _name;
|
||||
Object* _parent;
|
||||
Object* _proto;
|
||||
Object* _parentProto;
|
||||
|
||||
JSNative _ctor;
|
||||
|
||||
JSClass _jsCls;
|
||||
JSClassOps _classOps;
|
||||
|
||||
std::vector<JSFunctionSpec> _funcs;
|
||||
std::vector<JSFunctionSpec> _staticFuncs;
|
||||
std::vector<JSPropertySpec> _properties;
|
||||
std::vector<JSPropertySpec> _staticProperties;
|
||||
JSFinalizeOp _finalizeOp;
|
||||
|
||||
friend class ScriptEngine;
|
||||
friend class Object;
|
||||
};
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "../config.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
|
||||
extern uint32_t __jsbInvocationCount;
|
||||
|
||||
#define SAFE_INC_REF(obj) if (obj != nullptr) obj->incRef()
|
||||
#define SAFE_DEC_REF(obj) if ((obj) != nullptr) { (obj)->decRef(); (obj) = nullptr; }
|
||||
|
||||
#define _SE(name) name##Registry
|
||||
|
||||
|
||||
#define SE_DECLARE_FUNC(funcName) \
|
||||
bool funcName##Registry(JSContext* _cx, unsigned argc, JS::Value* _vp)
|
||||
|
||||
#define SE_BIND_FUNC(funcName) \
|
||||
bool funcName##Registry(JSContext* _cx, unsigned argc, JS::Value* _vp) \
|
||||
{ \
|
||||
++__jsbInvocationCount; \
|
||||
bool ret = false; \
|
||||
JS::CallArgs _argv = JS::CallArgsFromVp(argc, _vp); \
|
||||
JS::Value _thiz = _argv.computeThis(_cx); \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(_cx, argc, _argv, &args); \
|
||||
JS::RootedObject _thizObj(_cx, _thiz.toObjectOrNull()); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_cx, _thizObj); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
se::internal::setReturnValue(_cx, state.rval(), _argv); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define SE_DECLARE_FINALIZE_FUNC(funcName) \
|
||||
void funcName##Registry(JSFreeOp* _fop, JSObject* _obj);
|
||||
|
||||
#define SE_BIND_FINALIZE_FUNC(funcName) \
|
||||
void funcName##Registry(JSFreeOp* _fop, JSObject* _obj) \
|
||||
{ \
|
||||
void* nativeThisObject = JS_GetPrivate(_obj); \
|
||||
bool ret = false; \
|
||||
if (nativeThisObject == nullptr) \
|
||||
return;\
|
||||
se::State state(nativeThisObject); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_CTOR(funcName, cls, finalizeCb) \
|
||||
bool funcName##Registry(JSContext* _cx, unsigned argc, JS::Value* _vp) \
|
||||
{ \
|
||||
++__jsbInvocationCount; \
|
||||
bool ret = false; \
|
||||
JS::CallArgs _argv = JS::CallArgsFromVp(argc, _vp); \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(_cx, argc, _argv, &args); \
|
||||
se::Object* thisObject = se::Object::createObjectWithClass(cls); \
|
||||
_argv.rval().setObject(*thisObject->_getJSObject()); \
|
||||
se::State state(thisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (ret) \
|
||||
{ \
|
||||
se::Value _property; \
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_SUB_CLS_CTOR(funcName, cls, finalizeCb) \
|
||||
bool funcName##Registry(JSContext* _cx, unsigned argc, JS::Value* _vp) \
|
||||
{ \
|
||||
++__jsbInvocationCount; \
|
||||
bool ret = false; \
|
||||
JS::CallArgs _argv = JS::CallArgsFromVp(argc, _vp); \
|
||||
JS::Value _thiz = _argv.computeThis(_cx); \
|
||||
se::ValueArray args; \
|
||||
se::internal::jsToSeArgs(_cx, argc, _argv, &args); \
|
||||
se::Object* thisObject = se::Object::_createJSObject(cls, _thiz.toObjectOrNull()); \
|
||||
thisObject->_setFinalizeCallback(finalizeCb##Registry); \
|
||||
se::State state(thisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (ret) \
|
||||
{ \
|
||||
se::Value _property; \
|
||||
bool _found = false; \
|
||||
_found = thisObject->getProperty("_ctor", &_property); \
|
||||
if (_found) _property.toObject()->call(args, thisObject); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_PROP_GET(funcName) \
|
||||
bool funcName##Registry(JSContext *_cx, unsigned argc, JS::Value* _vp) \
|
||||
{ \
|
||||
++__jsbInvocationCount; \
|
||||
bool ret = false; \
|
||||
JS::CallArgs _argv = JS::CallArgsFromVp(argc, _vp); \
|
||||
JS::Value _thiz = _argv.computeThis(_cx); \
|
||||
JS::RootedObject _thizObj(_cx, _thiz.toObjectOrNull()); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_cx, _thizObj); \
|
||||
se::State state(nativeThisObject); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
se::internal::setReturnValue(_cx, state.rval(), _argv); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_BIND_PROP_SET(funcName) \
|
||||
bool funcName##Registry(JSContext *_cx, unsigned _argc, JS::Value *_vp) \
|
||||
{ \
|
||||
++__jsbInvocationCount; \
|
||||
bool ret = false; \
|
||||
JS::CallArgs _argv = JS::CallArgsFromVp(_argc, _vp); \
|
||||
JS::Value _thiz = _argv.computeThis(_cx); \
|
||||
JS::RootedObject _thizObj(_cx, _thiz.toObjectOrNull()); \
|
||||
void* nativeThisObject = se::internal::getPrivate(_cx, _thizObj); \
|
||||
se::Value data; \
|
||||
se::internal::jsToSeValue(_cx, _argv[0], &data); \
|
||||
se::ValueArray args; \
|
||||
args.push_back(std::move(data)); \
|
||||
se::State state(nativeThisObject, args); \
|
||||
ret = funcName(state); \
|
||||
if (!ret) { \
|
||||
SE_LOGE("[ERROR] Failed to invoke %s, location: %s:%d\n", #funcName, __FILE__, __LINE__); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
#define SE_TYPE_NAME(t) typeid(t).name()
|
||||
|
||||
#define SE_QUOTEME_(x) #x
|
||||
#define SE_QUOTEME(x) SE_QUOTEME_(x)
|
||||
|
||||
#define SE_REPORT_ERROR(fmt, ...) \
|
||||
SE_LOGD("ERROR (" __FILE__ ", " SE_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__); \
|
||||
JS_ReportErrorUTF8(se::ScriptEngine::getInstance()->_getContext(), fmt, ##__VA_ARGS__)
|
||||
|
||||
#if COCOS2D_DEBUG > 0
|
||||
|
||||
#define SE_ASSERT(cond, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (!(cond)) \
|
||||
{ \
|
||||
SE_LOGE("ASSERT (" __FILE__ ", " SE_QUOTEME(__LINE__) "): " fmt "\n", ##__VA_ARGS__); \
|
||||
assert(false); \
|
||||
} \
|
||||
} while(false)
|
||||
|
||||
#else
|
||||
|
||||
#define SE_ASSERT(cond, fmt, ...)
|
||||
|
||||
#endif // #if COCOS2D_DEBUG > 0
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
@@ -0,0 +1,722 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "Object.hpp"
|
||||
|
||||
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Class.hpp"
|
||||
#include "ScriptEngine.hpp"
|
||||
#include "../MappingUtils.hpp"
|
||||
|
||||
namespace se {
|
||||
|
||||
std::unordered_map<Object*, void*> __objectMap; // Currently, the value `void*` is always nullptr
|
||||
|
||||
namespace {
|
||||
JSContext *__cx = nullptr;
|
||||
|
||||
void get_or_create_js_obj(JSContext* cx, JS::HandleObject obj, const std::string &name, JS::MutableHandleObject jsObj)
|
||||
{
|
||||
JS::RootedValue nsval(cx);
|
||||
JS_GetProperty(cx, obj, name.c_str(), &nsval);
|
||||
if (nsval.isNullOrUndefined()) {
|
||||
jsObj.set(JS_NewPlainObject(cx));
|
||||
nsval = JS::ObjectValue(*jsObj);
|
||||
JS_SetProperty(cx, obj, name.c_str(), nsval);
|
||||
} else {
|
||||
jsObj.set(nsval.toObjectOrNull());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object::Object()
|
||||
: _root(nullptr)
|
||||
, _privateData(nullptr)
|
||||
, _cls(nullptr)
|
||||
, _finalizeCb(nullptr)
|
||||
, _rootCount(0)
|
||||
{
|
||||
_currentVMId = ScriptEngine::getInstance()->getVMId();
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
{
|
||||
if (_rootCount > 0)
|
||||
{
|
||||
unprotect();
|
||||
}
|
||||
|
||||
auto iter = __objectMap.find(this);
|
||||
if (iter != __objectMap.end())
|
||||
{
|
||||
__objectMap.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
bool Object::init(Class* cls, JSObject* obj)
|
||||
{
|
||||
_cls = cls;
|
||||
_heap = obj;
|
||||
|
||||
assert(__objectMap.find(this) == __objectMap.end());
|
||||
__objectMap.emplace(this, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Object* Object::_createJSObject(Class* cls, JSObject* obj)
|
||||
{
|
||||
Object* ret = new Object();
|
||||
if (!ret->init(cls, obj))
|
||||
{
|
||||
delete ret;
|
||||
ret = nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Object* Object::createPlainObject()
|
||||
{
|
||||
Object* obj = Object::_createJSObject(nullptr, JS_NewPlainObject(__cx));
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createObjectWithClass(Class* cls)
|
||||
{
|
||||
JSObject* jsobj = Class::_createJSObjectWithClass(cls);
|
||||
Object* obj = Object::_createJSObject(cls, jsobj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::getObjectWithPtr(void* ptr)
|
||||
{
|
||||
Object* obj = nullptr;
|
||||
auto iter = NativePtrToObjectMap::find(ptr);
|
||||
if (iter != NativePtrToObjectMap::end())
|
||||
{
|
||||
obj = iter->second;
|
||||
obj->incRef();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createArrayObject(size_t length)
|
||||
{
|
||||
JS::RootedObject jsobj(__cx, JS_NewArrayObject(__cx, length));
|
||||
Object* obj = Object::_createJSObject(nullptr, jsobj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createArrayBufferObject(void* data, size_t byteLength)
|
||||
{
|
||||
JS::RootedObject jsobj(__cx, JS_NewArrayBuffer(__cx, (uint32_t)byteLength));
|
||||
bool isShared = false;
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
uint8_t* tmpData = JS_GetArrayBufferData(jsobj, &isShared, nogc);
|
||||
if (data)
|
||||
{
|
||||
memcpy((void*)tmpData, (const void*)data, byteLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset((void*)tmpData, 0, byteLength);
|
||||
}
|
||||
Object* obj = Object::_createJSObject(nullptr, jsobj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createTypedArray(TypedArrayType type, void* data, size_t byteLength)
|
||||
{
|
||||
if (type == TypedArrayType::NONE)
|
||||
{
|
||||
SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (type == TypedArrayType::UINT8_CLAMPED)
|
||||
{
|
||||
SE_LOGE("Doesn't support to create Uint8ClampedArray with Object::createTypedArray API!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSObject* arr = nullptr;
|
||||
void* tmpData = nullptr;
|
||||
bool isShared = false;
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
|
||||
switch (type) {
|
||||
case TypedArrayType::INT8:
|
||||
arr = JS_NewInt8Array(__cx, (uint32_t)byteLength);
|
||||
tmpData = JS_GetInt8ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::INT16:
|
||||
arr = JS_NewInt16Array(__cx, (uint32_t)byteLength/2);
|
||||
tmpData = JS_GetInt16ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::INT32:
|
||||
arr = JS_NewInt32Array(__cx, (uint32_t)byteLength/4);
|
||||
tmpData = JS_GetInt32ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::UINT8:
|
||||
arr = JS_NewUint8Array(__cx, (uint32_t)byteLength);
|
||||
tmpData = JS_GetUint8ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::UINT16:
|
||||
arr = JS_NewUint16Array(__cx, (uint32_t)byteLength/2);
|
||||
tmpData = JS_GetUint16ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::UINT32:
|
||||
arr = JS_NewUint32Array(__cx, (uint32_t)byteLength/4);
|
||||
tmpData = JS_GetUint32ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::FLOAT32:
|
||||
arr = JS_NewFloat32Array(__cx, (uint32_t)byteLength/4);
|
||||
tmpData = JS_GetFloat32ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
case TypedArrayType::FLOAT64:
|
||||
arr = JS_NewFloat64Array(__cx, (uint32_t)byteLength/8);
|
||||
tmpData = JS_GetFloat64ArrayData(arr, &isShared, nogc);
|
||||
break;
|
||||
default:
|
||||
assert(false); // Should never go here.
|
||||
break;
|
||||
}
|
||||
|
||||
//If data has content,then will copy data into buffer,or will only clear buffer.
|
||||
if (data) {
|
||||
memcpy(tmpData, (const void*)data, byteLength);
|
||||
}else{
|
||||
memset(tmpData, 0, byteLength);
|
||||
}
|
||||
|
||||
Object* obj = Object::_createJSObject(nullptr, arr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object* Object::createUint8TypedArray(uint8_t* data, size_t dataCount)
|
||||
{
|
||||
return createTypedArray(TypedArrayType::UINT8, data, dataCount);
|
||||
}
|
||||
|
||||
Object* Object::createJSONObject(const std::string& jsonStr)
|
||||
{
|
||||
Value strVal(jsonStr);
|
||||
JS::RootedValue jsStr(__cx);
|
||||
internal::seToJsValue(__cx, strVal, &jsStr);
|
||||
JS::RootedValue jsObj(__cx);
|
||||
JS::RootedString rootedStr(__cx, jsStr.toString());
|
||||
Object* obj = nullptr;
|
||||
if (JS_ParseJSON(__cx, rootedStr, &jsObj))
|
||||
{
|
||||
obj = Object::_createJSObject(nullptr, jsObj.toObjectOrNull());
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
void Object::_setFinalizeCallback(JSFinalizeOp finalizeCb)
|
||||
{
|
||||
_finalizeCb = finalizeCb;
|
||||
}
|
||||
|
||||
bool Object::getProperty(const char* name, Value* data)
|
||||
{
|
||||
assert(data != nullptr);
|
||||
data->setUndefined();
|
||||
|
||||
JSObject* jsobj = _getJSObject();
|
||||
if (jsobj == nullptr)
|
||||
return false;
|
||||
|
||||
JS::RootedObject object(__cx, jsobj);
|
||||
|
||||
bool found = false;
|
||||
bool ok = JS_HasProperty(__cx, object, name, &found);
|
||||
|
||||
if (!ok || !found)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::RootedValue rcValue(__cx);
|
||||
ok = JS_GetProperty(__cx, object, name, &rcValue);
|
||||
|
||||
if (ok && data)
|
||||
{
|
||||
internal::jsToSeValue(__cx, rcValue, data);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool Object::setProperty(const char* name, const Value& v)
|
||||
{
|
||||
JS::RootedObject object(__cx, _getJSObject());
|
||||
|
||||
JS::RootedValue value(__cx);
|
||||
internal::seToJsValue(__cx, v, &value);
|
||||
return JS_SetProperty(__cx, object, name, value);
|
||||
}
|
||||
|
||||
bool Object::defineProperty(const char *name, JSNative getter, JSNative setter)
|
||||
{
|
||||
JS::RootedObject jsObj(__cx, _getJSObject());
|
||||
return JS_DefineProperty(__cx, jsObj, name, JS::UndefinedHandleValue, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_SHARED, getter, setter);
|
||||
}
|
||||
|
||||
bool Object::call(const ValueArray& args, Object* thisObject, Value* rval/* = nullptr*/)
|
||||
{
|
||||
assert(isFunction());
|
||||
|
||||
JS::AutoValueVector jsarr(__cx);
|
||||
jsarr.reserve(args.size());
|
||||
internal::seToJsArgs(__cx, args, &jsarr);
|
||||
|
||||
JS::RootedObject contextObject(__cx);
|
||||
if (thisObject != nullptr)
|
||||
{
|
||||
contextObject.set(thisObject->_getJSObject());
|
||||
}
|
||||
|
||||
JSObject* funcObj = _getJSObject();
|
||||
JS::RootedValue func(__cx, JS::ObjectValue(*funcObj));
|
||||
JS::RootedValue rcValue(__cx);
|
||||
|
||||
bool ok = JS_CallFunctionValue(__cx, contextObject, func, jsarr, &rcValue);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
if (rval != nullptr)
|
||||
internal::jsToSeValue(__cx, rcValue, rval);
|
||||
}
|
||||
else
|
||||
{
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool Object::defineFunction(const char *funcName, JSNative func)
|
||||
{
|
||||
JS::RootedObject object(__cx, _getJSObject());
|
||||
bool ok = JS_DefineFunction(__cx, object, funcName, func, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool Object::getArrayLength(uint32_t* length) const
|
||||
{
|
||||
assert(length != nullptr);
|
||||
if (!isArray())
|
||||
return false;
|
||||
|
||||
JS::RootedObject object(__cx, _getJSObject());
|
||||
if (JS_GetArrayLength(__cx, object, length))
|
||||
return true;
|
||||
|
||||
*length = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Object::getArrayElement(uint32_t index, Value* data) const
|
||||
{
|
||||
assert(data != nullptr);
|
||||
if (!isArray())
|
||||
return false;
|
||||
|
||||
JS::RootedObject object(__cx, _getJSObject());
|
||||
JS::RootedValue rcValue(__cx);
|
||||
if (JS_GetElement(__cx, object, index, &rcValue))
|
||||
{
|
||||
internal::jsToSeValue(__cx, rcValue, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
data->setUndefined();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Object::setArrayElement(uint32_t index, const Value& data)
|
||||
{
|
||||
if (!isArray())
|
||||
return false;
|
||||
|
||||
JS::RootedValue jsval(__cx);
|
||||
internal::seToJsValue(__cx, data, &jsval);
|
||||
JS::RootedObject thisObj(__cx, _getJSObject());
|
||||
return JS_SetElement(__cx, thisObj, index, jsval);
|
||||
}
|
||||
|
||||
bool Object::isFunction() const
|
||||
{
|
||||
return JS_ObjectIsFunction(__cx, _getJSObject());
|
||||
}
|
||||
|
||||
bool Object::_isNativeFunction(JSNative func) const
|
||||
{
|
||||
JSObject* obj = _getJSObject();
|
||||
return JS_ObjectIsFunction(__cx, obj) && JS_IsNativeFunction(obj, func);
|
||||
}
|
||||
|
||||
bool Object::isTypedArray() const
|
||||
{
|
||||
return JS_IsTypedArrayObject(_getJSObject());
|
||||
}
|
||||
|
||||
Object::TypedArrayType Object::getTypedArrayType() const
|
||||
{
|
||||
TypedArrayType ret = TypedArrayType::NONE;
|
||||
JSObject* obj = _getJSObject();
|
||||
if (JS_IsInt8Array(obj))
|
||||
ret = TypedArrayType::INT8;
|
||||
else if (JS_IsInt16Array(obj))
|
||||
ret = TypedArrayType::INT16;
|
||||
else if (JS_IsInt32Array(obj))
|
||||
ret = TypedArrayType::INT32;
|
||||
else if (JS_IsUint8Array(obj))
|
||||
ret = TypedArrayType::UINT8;
|
||||
else if (JS_IsUint8ClampedArray(obj))
|
||||
ret = TypedArrayType::UINT8_CLAMPED;
|
||||
else if (JS_IsUint16Array(obj))
|
||||
ret = TypedArrayType::UINT16;
|
||||
else if (JS_IsUint32Array(obj))
|
||||
ret = TypedArrayType::UINT32;
|
||||
else if (JS_IsFloat32Array(obj))
|
||||
ret = TypedArrayType::FLOAT32;
|
||||
else if (JS_IsFloat64Array(obj))
|
||||
ret = TypedArrayType::FLOAT64;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Object::getTypedArrayData(uint8_t** ptr, size_t* length) const
|
||||
{
|
||||
assert(JS_IsArrayBufferViewObject(_getJSObject()));
|
||||
bool isShared = false;
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
*ptr = (uint8_t*)JS_GetArrayBufferViewData(_getJSObject(), &isShared, nogc);
|
||||
*length = JS_GetArrayBufferViewByteLength(_getJSObject());
|
||||
return (*ptr != nullptr);
|
||||
}
|
||||
|
||||
bool Object::isArray() const
|
||||
{
|
||||
JS::RootedValue value(__cx, JS::ObjectValue(*_getJSObject()));
|
||||
bool isArray = false;
|
||||
return JS_IsArrayObject(__cx, value, &isArray) && isArray;
|
||||
}
|
||||
|
||||
bool Object::isArrayBuffer() const
|
||||
{
|
||||
return JS_IsArrayBufferObject(_getJSObject());
|
||||
}
|
||||
|
||||
bool Object::getArrayBufferData(uint8_t** ptr, size_t* length) const
|
||||
{
|
||||
assert(isArrayBuffer());
|
||||
|
||||
bool isShared = false;
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
*ptr = (uint8_t*)JS_GetArrayBufferData(_getJSObject(), &isShared, nogc);
|
||||
*length = JS_GetArrayBufferByteLength(_getJSObject());
|
||||
return (*ptr != nullptr);
|
||||
}
|
||||
|
||||
bool Object::getAllKeys(std::vector<std::string>* allKeys) const
|
||||
{
|
||||
assert(allKeys != nullptr);
|
||||
JS::RootedObject jsobj(__cx, _getJSObject());
|
||||
JS::Rooted<JS::IdVector> props(__cx, JS::IdVector(__cx));
|
||||
if (!JS_Enumerate(__cx, jsobj, &props))
|
||||
return false;
|
||||
|
||||
std::vector<std::string> keys;
|
||||
for (size_t i = 0, length = props.length(); i < length; ++i)
|
||||
{
|
||||
JS::RootedId id(__cx, props[i]);
|
||||
JS::RootedValue keyVal(__cx);
|
||||
JS_IdToValue(__cx, id, &keyVal);
|
||||
|
||||
if (JSID_IS_STRING(id))
|
||||
{
|
||||
JS::RootedString rootedKeyVal(__cx, keyVal.toString());
|
||||
allKeys->push_back(internal::jsToStdString(__cx, rootedKeyVal));
|
||||
}
|
||||
else if (JSID_IS_INT(id))
|
||||
{
|
||||
char buf[50] = {0};
|
||||
snprintf(buf, sizeof(buf), "%d", keyVal.toInt32());
|
||||
allKeys->push_back(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void* Object::getPrivateData() const
|
||||
{
|
||||
if (_privateData == nullptr)
|
||||
{
|
||||
JS::RootedObject obj(__cx, _getJSObject());
|
||||
const_cast<Object*>(this)->_privateData = internal::getPrivate(__cx, obj);
|
||||
}
|
||||
return _privateData;
|
||||
}
|
||||
|
||||
void Object::setPrivateData(void* data)
|
||||
{
|
||||
assert(_privateData == nullptr);
|
||||
assert(NativePtrToObjectMap::find(data) == NativePtrToObjectMap::end());
|
||||
assert(_cls != nullptr);
|
||||
JS::RootedObject obj(__cx, _getJSObject());
|
||||
internal::setPrivate(__cx, obj, data, _finalizeCb);
|
||||
|
||||
NativePtrToObjectMap::emplace(data, this);
|
||||
_privateData = data;
|
||||
}
|
||||
|
||||
void Object::clearPrivateData(bool clearMapping)
|
||||
{
|
||||
if (_privateData != nullptr)
|
||||
{
|
||||
if (clearMapping)
|
||||
NativePtrToObjectMap::erase(_privateData);
|
||||
JS::RootedObject obj(__cx, _getJSObject());
|
||||
internal::clearPrivate(__cx, obj);
|
||||
_privateData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Object::setContext(JSContext *cx)
|
||||
{
|
||||
__cx = cx;
|
||||
}
|
||||
|
||||
// static
|
||||
void Object::cleanup()
|
||||
{
|
||||
for (const auto& e : __objectMap)
|
||||
{
|
||||
e.first->reset();
|
||||
}
|
||||
|
||||
ScriptEngine::getInstance()->addAfterCleanupHook([](){
|
||||
__objectMap.clear();
|
||||
const auto& instance = NativePtrToObjectMap::instance();
|
||||
for (const auto& e : instance)
|
||||
{
|
||||
e.second->decRef();
|
||||
}
|
||||
NativePtrToObjectMap::clear();
|
||||
NonRefNativePtrCreatedByCtorMap::clear();
|
||||
__cx = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
JSObject* Object::_getJSObject() const
|
||||
{
|
||||
return isRooted() ? _root->get() : _heap.get();
|
||||
}
|
||||
|
||||
void Object::root()
|
||||
{
|
||||
if (_rootCount == 0)
|
||||
{
|
||||
protect();
|
||||
}
|
||||
++_rootCount;
|
||||
}
|
||||
|
||||
void Object::unroot()
|
||||
{
|
||||
if (_rootCount > 0)
|
||||
{
|
||||
--_rootCount;
|
||||
if (_rootCount == 0)
|
||||
{
|
||||
unprotect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Object::protect()
|
||||
{
|
||||
assert(_root == nullptr);
|
||||
assert(_heap != JS::GCPolicy<JSObject*>::initial());
|
||||
|
||||
_root = new JS::PersistentRootedObject(__cx, _heap);
|
||||
_heap = JS::GCPolicy<JSObject*>::initial();
|
||||
}
|
||||
|
||||
void Object::unprotect()
|
||||
{
|
||||
if (_root == nullptr)
|
||||
return;
|
||||
|
||||
assert(_currentVMId == ScriptEngine::getInstance()->getVMId());
|
||||
assert(_heap == JS::GCPolicy<JSObject*>::initial());
|
||||
_heap = *_root;
|
||||
delete _root;
|
||||
_root = nullptr;
|
||||
}
|
||||
|
||||
void Object::reset()
|
||||
{
|
||||
if (_root != nullptr)
|
||||
{
|
||||
delete _root;
|
||||
_root = nullptr;
|
||||
}
|
||||
|
||||
_heap = JS::GCPolicy<JSObject*>::initial();
|
||||
}
|
||||
|
||||
/* Tracing makes no sense in the rooted case, because JS::PersistentRooted
|
||||
* already takes care of that. */
|
||||
void Object::trace(JSTracer* tracer, void* data)
|
||||
{
|
||||
assert(!isRooted());
|
||||
JS::TraceEdge(tracer, &_heap, "ccobj tracing");
|
||||
}
|
||||
|
||||
/* If not tracing, then you must call this method during GC in order to
|
||||
* update the object's location if it was moved, or null it out if it was
|
||||
* finalized. If the object was finalized, returns true. */
|
||||
bool Object::updateAfterGC(void* data)
|
||||
{
|
||||
assert(!isRooted());
|
||||
bool isGarbageCollected = false;
|
||||
internal::PrivateData* internalData = nullptr;
|
||||
|
||||
JSObject* oldPtr = _heap.unbarrieredGet();
|
||||
if (_heap.unbarrieredGet() != nullptr)
|
||||
JS_UpdateWeakPointerAfterGC(&_heap);
|
||||
|
||||
JSObject* newPtr = _heap.unbarrieredGet();
|
||||
|
||||
// IDEA: test to see ggc
|
||||
if (oldPtr != nullptr && newPtr != nullptr)
|
||||
{
|
||||
assert(oldPtr == newPtr);
|
||||
}
|
||||
isGarbageCollected = (newPtr == nullptr);
|
||||
if (isGarbageCollected && internalData != nullptr)
|
||||
{
|
||||
free(internalData);
|
||||
}
|
||||
return isGarbageCollected;
|
||||
}
|
||||
|
||||
bool Object::isRooted() const
|
||||
{
|
||||
return _rootCount > 0;
|
||||
}
|
||||
|
||||
bool Object::strictEquals(Object* o) const
|
||||
{
|
||||
JSObject* thisObj = _getJSObject();
|
||||
JSObject* oThisObj = o->_getJSObject();
|
||||
if ((thisObj == nullptr || oThisObj == nullptr) && thisObj != oThisObj)
|
||||
return false;
|
||||
|
||||
assert(thisObj);
|
||||
assert(oThisObj);
|
||||
JS::RootedValue v1(__cx, JS::ObjectValue(*_getJSObject()));
|
||||
JS::RootedValue v2(__cx, JS::ObjectValue(*o->_getJSObject()));
|
||||
bool same = false;
|
||||
bool ok = JS_SameValue(__cx, v1, v2, &same);
|
||||
return ok && same;
|
||||
}
|
||||
|
||||
bool Object::attachObject(Object* obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
||||
Object* global = ScriptEngine::getInstance()->getGlobalObject();
|
||||
Value jsbVal;
|
||||
if (!global->getProperty("jsb", &jsbVal))
|
||||
return false;
|
||||
Object* jsbObj = jsbVal.toObject();
|
||||
|
||||
Value func;
|
||||
|
||||
if (!jsbObj->getProperty("registerNativeRef", &func))
|
||||
return false;
|
||||
|
||||
ValueArray args;
|
||||
args.push_back(Value(this));
|
||||
args.push_back(Value(obj));
|
||||
func.toObject()->call(args, global);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Object::detachObject(Object* obj)
|
||||
{
|
||||
assert(obj);
|
||||
Object* global = ScriptEngine::getInstance()->getGlobalObject();
|
||||
Value jsbVal;
|
||||
if (!global->getProperty("jsb", &jsbVal))
|
||||
return false;
|
||||
Object* jsbObj = jsbVal.toObject();
|
||||
|
||||
Value func;
|
||||
|
||||
if (!jsbObj->getProperty("unregisterNativeRef", &func))
|
||||
return false;
|
||||
|
||||
ValueArray args;
|
||||
args.push_back(Value(this));
|
||||
args.push_back(Value(obj));
|
||||
func.toObject()->call(args, global);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Object::toString() const
|
||||
{
|
||||
std::string ret;
|
||||
if (isFunction() || isArray() || isTypedArray())
|
||||
{
|
||||
JS::RootedValue val(__cx, JS::ObjectOrNullValue(_getJSObject()));
|
||||
internal::forceConvertJsValueToStdString(__cx, val, &ret);
|
||||
}
|
||||
else if (isArrayBuffer())
|
||||
{
|
||||
ret = "[object ArrayBuffer]";
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = "[object Object]";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace se {
|
||||
|
||||
#endif // #if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_SM
|
||||